upd table YclientsServices and added method GetAccountServicesByID

This commit is contained in:
pasha1coil 2025-10-07 15:17:55 +03:00
parent e557d9e68d
commit 7d1e1c9ba5
6 changed files with 163 additions and 61 deletions

@ -1570,4 +1570,7 @@ INSERT INTO YclientsAccountUsers (SalonID, YclientsID, Name, Specialization, IDP
VALUES ($1, $2, $3, $4, $5, $6,$7,$8,$9,$10); VALUES ($1, $2, $3, $4, $5, $6,$7,$8,$9,$10);
-- name: DeleteYclientsUsers :exec -- name: DeleteYclientsUsers :exec
UPDATE YclientsAccountUsers SET Deleted = true WHERE ID = ANY($1::bigint[]); UPDATE YclientsAccountUsers SET Deleted = true WHERE ID = ANY($1::bigint[]);
-- name: GetServicesByIDYclients :many
SELECT * FROM YclientsServices WHERE SalonID = $1 AND Deleted = false;

@ -52,6 +52,7 @@ CREATE TABLE IF NOT EXISTS YclientsServices (
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY, ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
SalonID INT NOT NULL, -- ID компании SalonID INT NOT NULL, -- ID компании
ServiceID INT NOT NULL, ServiceID INT NOT NULL,
SalonServiceID INT NOT NULL,
Title text NOT NULL, Title text NOT NULL,
CategoryID INT NOT NULL, CategoryID INT NOT NULL,
PriceMin text NOT NULL, PriceMin text NOT NULL,
@ -60,6 +61,7 @@ CREATE TABLE IF NOT EXISTS YclientsServices (
Comment text NOT NULL, Comment text NOT NULL,
Active text NOT NULL, Active text NOT NULL,
ApiID text NOT NULL, ApiID text NOT NULL,
Staff JSONB NOT NULL DEFAULT '{}',
Deleted BOOLEAN NOT NULL DEFAULT FALSE, Deleted BOOLEAN NOT NULL DEFAULT FALSE,
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
); );

@ -427,19 +427,21 @@ type Yclientsaccountuser struct {
} }
type Yclientsservice struct { type Yclientsservice struct {
ID int64 `db:"id" json:"id"` ID int64 `db:"id" json:"id"`
Salonid int32 `db:"salonid" json:"salonid"` Salonid int32 `db:"salonid" json:"salonid"`
Serviceid int32 `db:"serviceid" json:"serviceid"` Serviceid int32 `db:"serviceid" json:"serviceid"`
Title string `db:"title" json:"title"` Salonserviceid int32 `db:"salonserviceid" json:"salonserviceid"`
Categoryid int32 `db:"categoryid" json:"categoryid"` Title string `db:"title" json:"title"`
Pricemin string `db:"pricemin" json:"pricemin"` Categoryid int32 `db:"categoryid" json:"categoryid"`
Pricemax string `db:"pricemax" json:"pricemax"` Pricemin string `db:"pricemin" json:"pricemin"`
Discount string `db:"discount" json:"discount"` Pricemax string `db:"pricemax" json:"pricemax"`
Comment string `db:"comment" json:"comment"` Discount string `db:"discount" json:"discount"`
Active string `db:"active" json:"active"` Comment string `db:"comment" json:"comment"`
Apiid string `db:"apiid" json:"apiid"` Active string `db:"active" json:"active"`
Deleted bool `db:"deleted" json:"deleted"` Apiid string `db:"apiid" json:"apiid"`
Createdat time.Time `db:"createdat" json:"createdat"` Staff json.RawMessage `db:"staff" json:"staff"`
Deleted bool `db:"deleted" json:"deleted"`
Createdat time.Time `db:"createdat" json:"createdat"`
} }
type Yclientstimeslot struct { type Yclientstimeslot struct {

@ -3699,12 +3699,55 @@ func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAn
return items, nil 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 const getServicesYclientsWithPagination = `-- name: GetServicesYclientsWithPagination :many
WITH user_data AS ( WITH user_data AS (
SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false 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 FROM YclientsServices u
JOIN user_data a ON u.SalonID = a.SalonID JOIN user_data a ON u.SalonID = a.SalonID
WHERE u.Deleted = false WHERE u.Deleted = false
@ -3718,20 +3761,22 @@ type GetServicesYclientsWithPaginationParams struct {
} }
type GetServicesYclientsWithPaginationRow struct { type GetServicesYclientsWithPaginationRow struct {
ID int64 `db:"id" json:"id"` ID int64 `db:"id" json:"id"`
Salonid int32 `db:"salonid" json:"salonid"` Salonid int32 `db:"salonid" json:"salonid"`
Serviceid int32 `db:"serviceid" json:"serviceid"` Serviceid int32 `db:"serviceid" json:"serviceid"`
Title string `db:"title" json:"title"` Salonserviceid int32 `db:"salonserviceid" json:"salonserviceid"`
Categoryid int32 `db:"categoryid" json:"categoryid"` Title string `db:"title" json:"title"`
Pricemin string `db:"pricemin" json:"pricemin"` Categoryid int32 `db:"categoryid" json:"categoryid"`
Pricemax string `db:"pricemax" json:"pricemax"` Pricemin string `db:"pricemin" json:"pricemin"`
Discount string `db:"discount" json:"discount"` Pricemax string `db:"pricemax" json:"pricemax"`
Comment string `db:"comment" json:"comment"` Discount string `db:"discount" json:"discount"`
Active string `db:"active" json:"active"` Comment string `db:"comment" json:"comment"`
Apiid string `db:"apiid" json:"apiid"` Active string `db:"active" json:"active"`
Deleted bool `db:"deleted" json:"deleted"` Apiid string `db:"apiid" json:"apiid"`
Createdat time.Time `db:"createdat" json:"createdat"` Staff json.RawMessage `db:"staff" json:"staff"`
TotalCount int64 `db:"total_count" json:"total_count"` Deleted bool `db:"deleted" json:"deleted"`
Createdat time.Time `db:"createdat" json:"createdat"`
TotalCount int64 `db:"total_count" json:"total_count"`
} }
// -- name: GetCompanyYclientsWithPagination :many // -- name: GetCompanyYclientsWithPagination :many
@ -3756,6 +3801,7 @@ func (q *Queries) GetServicesYclientsWithPagination(ctx context.Context, arg Get
&i.ID, &i.ID,
&i.Salonid, &i.Salonid,
&i.Serviceid, &i.Serviceid,
&i.Salonserviceid,
&i.Title, &i.Title,
&i.Categoryid, &i.Categoryid,
&i.Pricemin, &i.Pricemin,
@ -3764,6 +3810,7 @@ func (q *Queries) GetServicesYclientsWithPagination(ctx context.Context, arg Get
&i.Comment, &i.Comment,
&i.Active, &i.Active,
&i.Apiid, &i.Apiid,
&i.Staff,
&i.Deleted, &i.Deleted,
&i.Createdat, &i.Createdat,
&i.TotalCount, &i.TotalCount,

@ -62,21 +62,27 @@ type UserListYclientsResp struct {
//} //}
type YclientsServices struct { type YclientsServices struct {
ID int64 `json:"id"` ID int64 `json:"id"`
SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ" SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
ServiceID int32 `json:"serviceID"` ServiceID int32 `json:"serviceID"`
Title string `json:"title"` SalonServiceID int32 `json:"salon_service_id"`
CategoryID int32 `json:"categoryID"` Title string `json:"title"`
PriceMin string `json:"priceMin"` CategoryID int32 `json:"categoryID"`
PriceMax string `json:"priceMax"` PriceMin string `json:"priceMin"`
Discount string `json:"discount"` PriceMax string `json:"priceMax"`
Comment string `json:"comment"` Discount string `json:"discount"`
Active string `json:"active"` Comment string `json:"comment"`
ApiID string `json:"apiID"` Active string `json:"active"`
Deleted bool `json:"deleted"` ApiID string `json:"apiID"`
CreatedAt time.Time `json:"createdAt"` 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 { type ServicesListYclientsResp struct {
Count int64 `json:"count"` Count int64 `json:"count"`
Items []YclientsServices `json:"items"` Items []YclientsServices `json:"items"`

@ -335,35 +335,77 @@ func (r *YclientsRepository) GettingServicesWithPagination(ctx context.Context,
if err != nil { if err != nil {
return nil, err return nil, err
} }
var users []model.YclientsServices var services []model.YclientsServices
var count int64 var count int64
for _, row := range rows { for _, row := range rows {
users = append(users, model.YclientsServices{ var staff []model.YclientsServiceStaff
ID: row.ID, err = json.Unmarshal(row.Staff, &staff)
SalonID: row.Salonid, if err != nil {
ServiceID: row.Serviceid, return nil, err
Title: row.Title, }
CategoryID: row.Categoryid,
PriceMin: row.Pricemin, services = append(services, model.YclientsServices{
PriceMax: row.Pricemax, ID: row.ID,
Discount: row.Discount, SalonID: row.Salonid,
Comment: row.Comment, ServiceID: row.Serviceid,
Active: row.Active, SalonServiceID: row.Salonserviceid,
ApiID: row.Apiid, Title: row.Title,
Deleted: row.Deleted, CategoryID: row.Categoryid,
CreatedAt: row.Createdat, 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 count = row.TotalCount
} }
resp := model.ServicesListYclientsResp{ resp := model.ServicesListYclientsResp{
Count: count, Count: count,
Items: users, Items: services,
} }
return &resp, nil 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 // todo
func (r *YclientsRepository) UpdateServices() { func (r *YclientsRepository) UpdateServices() {
@ -380,7 +422,7 @@ func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context,
if err != nil { if err != nil {
return nil, err return nil, err
} }
var users []model.Timeslots var timeslots []model.Timeslots
var count int64 var count int64
for _, row := range rows { for _, row := range rows {
var weekdaysSettings []model.WeekdaySetting var weekdaysSettings []model.WeekdaySetting
@ -395,7 +437,7 @@ func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context,
return nil, err return nil, err
} }
users = append(users, model.Timeslots{ timeslots = append(timeslots, model.Timeslots{
ID: row.ID, ID: row.ID,
SalonID: row.Salonid, SalonID: row.Salonid,
IsEnabled: row.Isenabled, IsEnabled: row.Isenabled,
@ -409,7 +451,7 @@ func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context,
resp := model.TimeslotsListYclientsResp{ resp := model.TimeslotsListYclientsResp{
Count: count, Count: count,
Items: users, Items: timeslots,
} }
return &resp, nil return &resp, nil