diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index 702a72c..0c206ae 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -1570,4 +1570,7 @@ INSERT INTO YclientsAccountUsers (SalonID, YclientsID, Name, Specialization, IDP VALUES ($1, $2, $3, $4, $5, $6,$7,$8,$9,$10); -- name: DeleteYclientsUsers :exec -UPDATE YclientsAccountUsers SET Deleted = true WHERE ID = ANY($1::bigint[]); \ No newline at end of file +UPDATE YclientsAccountUsers SET Deleted = true WHERE ID = ANY($1::bigint[]); + +-- name: GetServicesByIDYclients :many +SELECT * FROM YclientsServices WHERE SalonID = $1 AND Deleted = false; \ No newline at end of file diff --git a/dal/schema/000028_init.up.sql b/dal/schema/000028_init.up.sql index 37ebdd7..3ab374e 100644 --- a/dal/schema/000028_init.up.sql +++ b/dal/schema/000028_init.up.sql @@ -52,6 +52,7 @@ CREATE TABLE IF NOT EXISTS YclientsServices ( ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY, SalonID INT NOT NULL, -- ID компании ServiceID INT NOT NULL, + SalonServiceID INT NOT NULL, Title text NOT NULL, CategoryID INT NOT NULL, PriceMin text NOT NULL, @@ -60,6 +61,7 @@ CREATE TABLE IF NOT EXISTS YclientsServices ( Comment text NOT NULL, Active text NOT NULL, ApiID text NOT NULL, + Staff JSONB 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 ab0cf5c..fc11a27 100644 --- a/dal/sqlcgen/models.go +++ b/dal/sqlcgen/models.go @@ -427,19 +427,21 @@ type Yclientsaccountuser struct { } type Yclientsservice struct { - ID int64 `db:"id" json:"id"` - Salonid int32 `db:"salonid" json:"salonid"` - Serviceid int32 `db:"serviceid" json:"serviceid"` - Title string `db:"title" json:"title"` - Categoryid int32 `db:"categoryid" json:"categoryid"` - Pricemin string `db:"pricemin" json:"pricemin"` - Pricemax string `db:"pricemax" json:"pricemax"` - Discount string `db:"discount" json:"discount"` - Comment string `db:"comment" json:"comment"` - Active string `db:"active" json:"active"` - Apiid string `db:"apiid" json:"apiid"` - Deleted bool `db:"deleted" json:"deleted"` - Createdat time.Time `db:"createdat" json:"createdat"` + ID int64 `db:"id" json:"id"` + Salonid int32 `db:"salonid" json:"salonid"` + Serviceid int32 `db:"serviceid" json:"serviceid"` + Salonserviceid int32 `db:"salonserviceid" json:"salonserviceid"` + Title string `db:"title" json:"title"` + Categoryid int32 `db:"categoryid" json:"categoryid"` + Pricemin string `db:"pricemin" json:"pricemin"` + Pricemax string `db:"pricemax" json:"pricemax"` + Discount string `db:"discount" json:"discount"` + Comment string `db:"comment" json:"comment"` + Active string `db:"active" json:"active"` + Apiid string `db:"apiid" json:"apiid"` + Staff json.RawMessage `db:"staff" json:"staff"` + Deleted bool `db:"deleted" json:"deleted"` + Createdat time.Time `db:"createdat" json:"createdat"` } type Yclientstimeslot struct { diff --git a/dal/sqlcgen/queries.sql.go b/dal/sqlcgen/queries.sql.go index 629ef11..8949bdd 100644 --- a/dal/sqlcgen/queries.sql.go +++ b/dal/sqlcgen/queries.sql.go @@ -3699,12 +3699,55 @@ func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAn return items, nil } +const getServicesByIDYclients = `-- name: GetServicesByIDYclients :many +SELECT id, salonid, serviceid, salonserviceid, title, categoryid, pricemin, pricemax, discount, comment, active, apiid, staff, deleted, createdat FROM YclientsServices WHERE SalonID = $1 AND Deleted = false +` + +func (q *Queries) GetServicesByIDYclients(ctx context.Context, salonid int32) ([]Yclientsservice, error) { + rows, err := q.db.QueryContext(ctx, getServicesByIDYclients, salonid) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Yclientsservice + for rows.Next() { + var i Yclientsservice + if err := rows.Scan( + &i.ID, + &i.Salonid, + &i.Serviceid, + &i.Salonserviceid, + &i.Title, + &i.Categoryid, + &i.Pricemin, + &i.Pricemax, + &i.Discount, + &i.Comment, + &i.Active, + &i.Apiid, + &i.Staff, + &i.Deleted, + &i.Createdat, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const getServicesYclientsWithPagination = `-- name: GetServicesYclientsWithPagination :many WITH user_data AS ( SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false ) -SELECT u.id, u.salonid, u.serviceid, u.title, u.categoryid, u.pricemin, u.pricemax, u.discount, u.comment, u.active, u.apiid, u.deleted, u.createdat, COUNT(*) OVER() as total_count +SELECT u.id, u.salonid, u.serviceid, u.salonserviceid, u.title, u.categoryid, u.pricemin, u.pricemax, u.discount, u.comment, u.active, u.apiid, u.staff, u.deleted, u.createdat, COUNT(*) OVER() as total_count FROM YclientsServices u JOIN user_data a ON u.SalonID = a.SalonID WHERE u.Deleted = false @@ -3718,20 +3761,22 @@ type GetServicesYclientsWithPaginationParams struct { } type GetServicesYclientsWithPaginationRow struct { - ID int64 `db:"id" json:"id"` - Salonid int32 `db:"salonid" json:"salonid"` - Serviceid int32 `db:"serviceid" json:"serviceid"` - Title string `db:"title" json:"title"` - Categoryid int32 `db:"categoryid" json:"categoryid"` - Pricemin string `db:"pricemin" json:"pricemin"` - Pricemax string `db:"pricemax" json:"pricemax"` - Discount string `db:"discount" json:"discount"` - Comment string `db:"comment" json:"comment"` - Active string `db:"active" json:"active"` - Apiid string `db:"apiid" json:"apiid"` - Deleted bool `db:"deleted" json:"deleted"` - Createdat time.Time `db:"createdat" json:"createdat"` - TotalCount int64 `db:"total_count" json:"total_count"` + ID int64 `db:"id" json:"id"` + Salonid int32 `db:"salonid" json:"salonid"` + Serviceid int32 `db:"serviceid" json:"serviceid"` + Salonserviceid int32 `db:"salonserviceid" json:"salonserviceid"` + Title string `db:"title" json:"title"` + Categoryid int32 `db:"categoryid" json:"categoryid"` + Pricemin string `db:"pricemin" json:"pricemin"` + Pricemax string `db:"pricemax" json:"pricemax"` + Discount string `db:"discount" json:"discount"` + Comment string `db:"comment" json:"comment"` + Active string `db:"active" json:"active"` + Apiid string `db:"apiid" json:"apiid"` + Staff json.RawMessage `db:"staff" json:"staff"` + Deleted bool `db:"deleted" json:"deleted"` + Createdat time.Time `db:"createdat" json:"createdat"` + TotalCount int64 `db:"total_count" json:"total_count"` } // -- name: GetCompanyYclientsWithPagination :many @@ -3756,6 +3801,7 @@ func (q *Queries) GetServicesYclientsWithPagination(ctx context.Context, arg Get &i.ID, &i.Salonid, &i.Serviceid, + &i.Salonserviceid, &i.Title, &i.Categoryid, &i.Pricemin, @@ -3764,6 +3810,7 @@ func (q *Queries) GetServicesYclientsWithPagination(ctx context.Context, arg Get &i.Comment, &i.Active, &i.Apiid, + &i.Staff, &i.Deleted, &i.Createdat, &i.TotalCount, diff --git a/model/yclients.go b/model/yclients.go index 3fff0d2..1bd1e71 100644 --- a/model/yclients.go +++ b/model/yclients.go @@ -62,21 +62,27 @@ type UserListYclientsResp struct { //} type YclientsServices struct { - ID int64 `json:"id"` - SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ" - ServiceID int32 `json:"serviceID"` - Title string `json:"title"` - CategoryID int32 `json:"categoryID"` - PriceMin string `json:"priceMin"` - PriceMax string `json:"priceMax"` - Discount string `json:"discount"` - Comment string `json:"comment"` - Active string `json:"active"` - ApiID string `json:"apiID"` - Deleted bool `json:"deleted"` - CreatedAt time.Time `json:"createdAt"` + ID int64 `json:"id"` + SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ" + ServiceID int32 `json:"serviceID"` + SalonServiceID int32 `json:"salon_service_id"` + Title string `json:"title"` + CategoryID int32 `json:"categoryID"` + PriceMin string `json:"priceMin"` + PriceMax string `json:"priceMax"` + Discount string `json:"discount"` + Comment string `json:"comment"` + Active string `json:"active"` + ApiID string `json:"apiID"` + Staff []YclientsServiceStaff `json:"staff"` + Deleted bool `json:"deleted"` + CreatedAt time.Time `json:"createdAt"` } +type YclientsServiceStaff struct { + ID string `json:"id"` + SeanceLength string `json:"seance_length"` +} type ServicesListYclientsResp struct { Count int64 `json:"count"` Items []YclientsServices `json:"items"` diff --git a/repository/yclients/yclients.go b/repository/yclients/yclients.go index f38ac93..e957b01 100644 --- a/repository/yclients/yclients.go +++ b/repository/yclients/yclients.go @@ -335,35 +335,77 @@ func (r *YclientsRepository) GettingServicesWithPagination(ctx context.Context, if err != nil { return nil, err } - var users []model.YclientsServices + var services []model.YclientsServices var count int64 for _, row := range rows { - users = append(users, model.YclientsServices{ - ID: row.ID, - SalonID: row.Salonid, - ServiceID: row.Serviceid, - Title: row.Title, - CategoryID: row.Categoryid, - PriceMin: row.Pricemin, - PriceMax: row.Pricemax, - Discount: row.Discount, - Comment: row.Comment, - Active: row.Active, - ApiID: row.Apiid, - Deleted: row.Deleted, - CreatedAt: row.Createdat, + var staff []model.YclientsServiceStaff + err = json.Unmarshal(row.Staff, &staff) + if err != nil { + return nil, err + } + + services = append(services, model.YclientsServices{ + ID: row.ID, + SalonID: row.Salonid, + ServiceID: row.Serviceid, + SalonServiceID: row.Salonserviceid, + Title: row.Title, + CategoryID: row.Categoryid, + PriceMin: row.Pricemin, + PriceMax: row.Pricemax, + Discount: row.Discount, + Comment: row.Comment, + Active: row.Active, + ApiID: row.Apiid, + Staff: staff, + Deleted: row.Deleted, + CreatedAt: row.Createdat, }) count = row.TotalCount } resp := model.ServicesListYclientsResp{ Count: count, - Items: users, + Items: services, } return &resp, nil } +func (r *YclientsRepository) GetAccountServicesByID(ctx context.Context, salonID int32) ([]model.YclientsServices, error) { + rows, err := r.queries.GetServicesByIDYclients(ctx, salonID) + if err != nil { + return nil, err + } + var services []model.YclientsServices + for _, row := range rows { + var staff []model.YclientsServiceStaff + err = json.Unmarshal(row.Staff, &staff) + if err != nil { + return nil, err + } + + services = append(services, model.YclientsServices{ + ID: row.ID, + SalonID: row.Salonid, + ServiceID: row.Serviceid, + SalonServiceID: row.Salonserviceid, + Title: row.Title, + CategoryID: row.Categoryid, + PriceMin: row.Pricemin, + PriceMax: row.Pricemax, + Discount: row.Discount, + Comment: row.Comment, + Active: row.Active, + ApiID: row.Apiid, + Staff: staff, + Deleted: row.Deleted, + CreatedAt: row.Createdat, + }) + } + return services, nil +} + // todo func (r *YclientsRepository) UpdateServices() { @@ -380,7 +422,7 @@ func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context, if err != nil { return nil, err } - var users []model.Timeslots + var timeslots []model.Timeslots var count int64 for _, row := range rows { var weekdaysSettings []model.WeekdaySetting @@ -395,7 +437,7 @@ func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context, return nil, err } - users = append(users, model.Timeslots{ + timeslots = append(timeslots, model.Timeslots{ ID: row.ID, SalonID: row.Salonid, IsEnabled: row.Isenabled, @@ -409,7 +451,7 @@ func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context, resp := model.TimeslotsListYclientsResp{ Count: count, - Items: users, + Items: timeslots, } return &resp, nil