diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index 42bc128..61206f6 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -1620,12 +1620,12 @@ SELECT 1; SELECT * FROM YclientsRules WHERE QuizID = $1 AND Deleted = false; -- name: SetYclientsQuizSettings :one -INSERT INTO YclientsRules (SalonID, QuizID, Services, CustomColor) -SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS CustomColor -FROM YclientsAccounts ya WHERE ya.AccountID = $4 AND ya.Deleted = false +INSERT INTO YclientsRules (SalonID, QuizID, Services,FieldsRule, CustomColor) +SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS FieldsRule, $4 AS CustomColor +FROM YclientsAccounts ya WHERE ya.AccountID = $5 AND ya.Deleted = false RETURNING id; -- name: ChangeYclientsQuizSettings :one -UPDATE YclientsRules SET Services = $1, CustomColor = $2 -WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $3 AND YclientsAccounts.Deleted = false) -AND QuizID = $4 AND Deleted = false RETURNING id; \ No newline at end of file +UPDATE YclientsRules SET Services = $1, CustomColor = $2,FieldsRule = $3 +WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $4 AND YclientsAccounts.Deleted = false) +AND QuizID = $5 AND Deleted = false RETURNING id; \ No newline at end of file diff --git a/dal/schema/000028_init.up.sql b/dal/schema/000028_init.up.sql index a95ff20..d02bc22 100644 --- a/dal/schema/000028_init.up.sql +++ b/dal/schema/000028_init.up.sql @@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS YclientsRules ( SalonID INT NOT NULL, -- ID компании QuizID INT NOT NULL, -- ID квиза на которое вешается правило Services JSONB NOT NULL DEFAULT '{}', + FieldsRule JSONB NOT NULL DEFAULT '{}', CustomColor text NOT NULL Default '', Deleted BOOLEAN NOT NULL DEFAULT FALSE, CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP diff --git a/dal/sqlcgen/models.go b/dal/sqlcgen/models.go index 9f782aa..74a5ab8 100644 --- a/dal/sqlcgen/models.go +++ b/dal/sqlcgen/models.go @@ -431,6 +431,7 @@ type Yclientsrule struct { Salonid int32 `db:"salonid" json:"salonid"` Quizid int32 `db:"quizid" json:"quizid"` Services json.RawMessage `db:"services" json:"services"` + Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"` Customcolor string `db:"customcolor" json:"customcolor"` Deleted bool `db:"deleted" json:"deleted"` Createdat time.Time `db:"createdat" json:"createdat"` diff --git a/dal/sqlcgen/queries.sql.go b/dal/sqlcgen/queries.sql.go index b15903a..6107b4f 100644 --- a/dal/sqlcgen/queries.sql.go +++ b/dal/sqlcgen/queries.sql.go @@ -342,14 +342,15 @@ func (q *Queries) ChangeQuizSettings(ctx context.Context, arg ChangeQuizSettings } const changeYclientsQuizSettings = `-- name: ChangeYclientsQuizSettings :one -UPDATE YclientsRules SET Services = $1, CustomColor = $2 -WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $3 AND YclientsAccounts.Deleted = false) -AND QuizID = $4 AND Deleted = false RETURNING id +UPDATE YclientsRules SET Services = $1, CustomColor = $2,FieldsRule = $3 +WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $4 AND YclientsAccounts.Deleted = false) +AND QuizID = $5 AND Deleted = false RETURNING id ` type ChangeYclientsQuizSettingsParams struct { Services json.RawMessage `db:"services" json:"services"` Customcolor string `db:"customcolor" json:"customcolor"` + Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"` Accountid string `db:"accountid" json:"accountid"` Quizid int32 `db:"quizid" json:"quizid"` } @@ -358,6 +359,7 @@ func (q *Queries) ChangeYclientsQuizSettings(ctx context.Context, arg ChangeYcli row := q.db.QueryRowContext(ctx, changeYclientsQuizSettings, arg.Services, arg.Customcolor, + arg.Fieldsrule, arg.Accountid, arg.Quizid, ) @@ -4791,7 +4793,7 @@ func (q *Queries) GetUsersYclientsWithPagination(ctx context.Context, arg GetUse } const getYclientsQuizRule = `-- name: GetYclientsQuizRule :one -SELECT id, salonid, quizid, services, customcolor, deleted, createdat FROM YclientsRules WHERE QuizID = $1 AND Deleted = false +SELECT id, salonid, quizid, services, fieldsrule, customcolor, deleted, createdat FROM YclientsRules WHERE QuizID = $1 AND Deleted = false ` func (q *Queries) GetYclientsQuizRule(ctx context.Context, quizid int32) (Yclientsrule, error) { @@ -4802,6 +4804,7 @@ func (q *Queries) GetYclientsQuizRule(ctx context.Context, quizid int32) (Yclien &i.Salonid, &i.Quizid, &i.Services, + &i.Fieldsrule, &i.Customcolor, &i.Deleted, &i.Createdat, @@ -5703,15 +5706,16 @@ func (q *Queries) SetQuizSettings(ctx context.Context, arg SetQuizSettingsParams } const setYclientsQuizSettings = `-- name: SetYclientsQuizSettings :one -INSERT INTO YclientsRules (SalonID, QuizID, Services, CustomColor) -SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS CustomColor -FROM YclientsAccounts ya WHERE ya.AccountID = $4 AND ya.Deleted = false +INSERT INTO YclientsRules (SalonID, QuizID, Services,FieldsRule, CustomColor) +SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS FieldsRule, $4 AS CustomColor +FROM YclientsAccounts ya WHERE ya.AccountID = $5 AND ya.Deleted = false RETURNING id ` type SetYclientsQuizSettingsParams struct { Quizid int32 `db:"quizid" json:"quizid"` Services json.RawMessage `db:"services" json:"services"` + Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"` Customcolor string `db:"customcolor" json:"customcolor"` Accountid string `db:"accountid" json:"accountid"` } @@ -5720,6 +5724,7 @@ func (q *Queries) SetYclientsQuizSettings(ctx context.Context, arg SetYclientsQu row := q.db.QueryRowContext(ctx, setYclientsQuizSettings, arg.Quizid, arg.Services, + arg.Fieldsrule, arg.Customcolor, arg.Accountid, ) diff --git a/model/yclients.go b/model/yclients.go index 60cc2e9..f68648f 100644 --- a/model/yclients.go +++ b/model/yclients.go @@ -131,11 +131,16 @@ type YclientsRule struct { SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ" QuizID int32 `json:"quizID"` // ID квиза на которое вешается правило Services ServiceYclientsRule `json:"services"` + FieldsRule YclientsFieldRule `json:"fields_rule"` CustomColor string `json:"custom_color"` Deleted bool `json:"deleted"` CreatedAt time.Time `json:"createdAt"` } +type YclientsFieldRule struct { + QuestionID map[int]string `json:"question_id"` +} + type ServiceYclientsRule struct { ID int `json:"id"` FirstCost int `json:"first_cost"` diff --git a/repository/yclients/yclients.go b/repository/yclients/yclients.go index 715210b..a87bf11 100644 --- a/repository/yclients/yclients.go +++ b/repository/yclients/yclients.go @@ -614,11 +614,18 @@ func (r *YclientsRepository) GettingQuizRules(ctx context.Context, quizID int32) return nil, err } + var fieldsRule model.YclientsFieldRule + err = json.Unmarshal(row.Fieldsrule, &fieldsRule) + if err != nil { + return nil, err + } + return &model.YclientsRule{ ID: row.ID, SalonID: row.Salonid, QuizID: row.Quizid, Services: services, + FieldsRule: fieldsRule, CustomColor: row.Customcolor, Deleted: row.Deleted, CreatedAt: row.Createdat, @@ -630,9 +637,14 @@ func (r *YclientsRepository) SetQuizSettings(ctx context.Context, rule model.Ycl if err != nil { return err } + jsonFieldsRule, err := json.Marshal(rule.FieldsRule) + if err != nil { + return err + } _, err = r.queries.SetYclientsQuizSettings(ctx, sqlcgen.SetYclientsQuizSettingsParams{ Quizid: rule.QuizID, Services: jsonServices, + Fieldsrule: jsonFieldsRule, Customcolor: rule.CustomColor, Accountid: accountID, }) @@ -649,9 +661,14 @@ func (r *YclientsRepository) ChangeQuizSettings(ctx context.Context, rule model. if err != nil { return err } + jsonFieldsRule, err := json.Marshal(rule.FieldsRule) + if err != nil { + return err + } _, err = r.queries.ChangeYclientsQuizSettings(ctx, sqlcgen.ChangeYclientsQuizSettingsParams{ Quizid: rule.QuizID, Services: jsonServices, + Fieldsrule: jsonFieldsRule, Customcolor: rule.CustomColor, Accountid: accountID, })