added method GetTimeslotsByIDYclients
This commit is contained in:
parent
b5e8ef404c
commit
6a6ab469b0
@ -1595,4 +1595,7 @@ INSERT INTO YclientsTimeSlots (SalonID, IsEnabled, WeekdaysSettings, DatesSettin
|
|||||||
VALUES ($1, $2, $3, $4);
|
VALUES ($1, $2, $3, $4);
|
||||||
|
|
||||||
-- name: DeleteYclientsTimeslots :exec
|
-- name: DeleteYclientsTimeslots :exec
|
||||||
UPDATE YclientsTimeSlots SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
UPDATE YclientsTimeSlots SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
||||||
|
|
||||||
|
-- name: GetTimeslotsByIDYclients :many
|
||||||
|
SELECT * FROM YclientsTimeSlots WHERE SalonID = $1 AND Deleted = false;
|
||||||
@ -4041,6 +4041,41 @@ func (q *Queries) GetTagsWithPagination(ctx context.Context, arg GetTagsWithPagi
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getTimeslotsByIDYclients = `-- name: GetTimeslotsByIDYclients :many
|
||||||
|
SELECT id, salonid, isenabled, weekdayssettings, datessettings, deleted, createdat FROM YclientsTimeSlots WHERE SalonID = $1 AND Deleted = false
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetTimeslotsByIDYclients(ctx context.Context, salonid int32) ([]Yclientstimeslot, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getTimeslotsByIDYclients, salonid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Yclientstimeslot
|
||||||
|
for rows.Next() {
|
||||||
|
var i Yclientstimeslot
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Salonid,
|
||||||
|
&i.Isenabled,
|
||||||
|
&i.Weekdayssettings,
|
||||||
|
&i.Datessettings,
|
||||||
|
&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 getTimeslotsYclientsWithPagination = `-- name: GetTimeslotsYclientsWithPagination :many
|
const getTimeslotsYclientsWithPagination = `-- name: GetTimeslotsYclientsWithPagination :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
|
||||||
|
|||||||
@ -564,3 +564,36 @@ func (r *YclientsRepository) DeleteTimeslots(ctx context.Context, ids []int64) e
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *YclientsRepository) GetAccountTimeslotsByID(ctx context.Context, salonID int32) ([]model.Timeslots, error) {
|
||||||
|
rows, err := r.queries.GetTimeslotsByIDYclients(ctx, salonID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var timeslots []model.Timeslots
|
||||||
|
for _, row := range rows {
|
||||||
|
var weekdaysSettings []model.WeekdaySetting
|
||||||
|
err = json.Unmarshal(row.Weekdayssettings, &weekdaysSettings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var datesSettings model.DateSetting
|
||||||
|
err = json.Unmarshal(row.Datessettings, &datesSettings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
timeslots = append(timeslots, model.Timeslots{
|
||||||
|
ID: row.ID,
|
||||||
|
SalonID: row.Salonid,
|
||||||
|
IsEnabled: row.Isenabled,
|
||||||
|
WeekdaysSettings: weekdaysSettings,
|
||||||
|
DatesSettings: datesSettings,
|
||||||
|
Deleted: row.Deleted,
|
||||||
|
CreatedAt: row.Createdat,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return timeslots, nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user