added methods UpdateYclientsAccountTimeslots, AddYclientsAccountTimeslots, DeleteYclientsTimeslots
This commit is contained in:
parent
19196aa451
commit
b5e8ef404c
@ -1586,5 +1586,13 @@ VALUES ($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12);
|
||||
-- name: DeleteYclientsServices :exec
|
||||
UPDATE YclientsServices SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
||||
|
||||
-- name: GetTimeslotsByIDYclients :many
|
||||
SELECT * FROM YclientsTimeSlots WHERE SalonID = $1 AND Deleted = false;
|
||||
-- name: UpdateYclientsAccountTimeslots :exec
|
||||
UPDATE YclientsTimeSlots SET IsEnabled = $2,WeekdaysSettings = $3, DatesSettings = $4
|
||||
WHERE SalonID = $1 AND deleted = false;
|
||||
|
||||
-- name: AddYclientsAccountTimeslots :exec
|
||||
INSERT INTO YclientsTimeSlots (SalonID, IsEnabled, WeekdaysSettings, DatesSettings)
|
||||
VALUES ($1, $2, $3, $4);
|
||||
|
||||
-- name: DeleteYclientsTimeslots :exec
|
||||
UPDATE YclientsTimeSlots SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
||||
@ -149,6 +149,28 @@ func (q *Queries) AddYclientsAccountService(ctx context.Context, arg AddYclients
|
||||
return err
|
||||
}
|
||||
|
||||
const addYclientsAccountTimeslots = `-- name: AddYclientsAccountTimeslots :exec
|
||||
INSERT INTO YclientsTimeSlots (SalonID, IsEnabled, WeekdaysSettings, DatesSettings)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
`
|
||||
|
||||
type AddYclientsAccountTimeslotsParams struct {
|
||||
Salonid int32 `db:"salonid" json:"salonid"`
|
||||
Isenabled bool `db:"isenabled" json:"isenabled"`
|
||||
Weekdayssettings json.RawMessage `db:"weekdayssettings" json:"weekdayssettings"`
|
||||
Datessettings json.RawMessage `db:"datessettings" json:"datessettings"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddYclientsAccountTimeslots(ctx context.Context, arg AddYclientsAccountTimeslotsParams) error {
|
||||
_, err := q.db.ExecContext(ctx, addYclientsAccountTimeslots,
|
||||
arg.Salonid,
|
||||
arg.Isenabled,
|
||||
arg.Weekdayssettings,
|
||||
arg.Datessettings,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const addYclientsAccountUser = `-- name: AddYclientsAccountUser :exec
|
||||
INSERT INTO YclientsAccountUsers (SalonID, YclientsID, Name, Specialization, IDPosition, TitlePosition,Fired,Status,Hidden,YclientsUserID)
|
||||
VALUES ($1, $2, $3, $4, $5, $6,$7,$8,$9,$10)
|
||||
@ -1609,6 +1631,15 @@ func (q *Queries) DeleteYclientsServices(ctx context.Context, dollar_1 []int64)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteYclientsTimeslots = `-- name: DeleteYclientsTimeslots :exec
|
||||
UPDATE YclientsTimeSlots SET Deleted = true WHERE ID = ANY($1::bigint[])
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteYclientsTimeslots(ctx context.Context, dollar_1 []int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteYclientsTimeslots, pq.Array(dollar_1))
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteYclientsUsers = `-- name: DeleteYclientsUsers :exec
|
||||
UPDATE YclientsAccountUsers SET Deleted = true WHERE ID = ANY($1::bigint[])
|
||||
`
|
||||
@ -4010,41 +4041,6 @@ func (q *Queries) GetTagsWithPagination(ctx context.Context, arg GetTagsWithPagi
|
||||
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
|
||||
WITH user_data AS (
|
||||
SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false
|
||||
@ -6162,6 +6158,28 @@ func (q *Queries) UpdateYclientsAccountServices(ctx context.Context, arg UpdateY
|
||||
return err
|
||||
}
|
||||
|
||||
const updateYclientsAccountTimeslots = `-- name: UpdateYclientsAccountTimeslots :exec
|
||||
UPDATE YclientsTimeSlots SET IsEnabled = $2,WeekdaysSettings = $3, DatesSettings = $4
|
||||
WHERE SalonID = $1 AND deleted = false
|
||||
`
|
||||
|
||||
type UpdateYclientsAccountTimeslotsParams struct {
|
||||
Salonid int32 `db:"salonid" json:"salonid"`
|
||||
Isenabled bool `db:"isenabled" json:"isenabled"`
|
||||
Weekdayssettings json.RawMessage `db:"weekdayssettings" json:"weekdayssettings"`
|
||||
Datessettings json.RawMessage `db:"datessettings" json:"datessettings"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateYclientsAccountTimeslots(ctx context.Context, arg UpdateYclientsAccountTimeslotsParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateYclientsAccountTimeslots,
|
||||
arg.Salonid,
|
||||
arg.Isenabled,
|
||||
arg.Weekdayssettings,
|
||||
arg.Datessettings,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateYclientsAccountUser = `-- name: UpdateYclientsAccountUser :exec
|
||||
UPDATE YclientsAccountUsers SET Name = $3, Specialization = $4, IDPosition = $5, TitlePosition= $6, Fired = $7,Status = $8,Hidden=$9
|
||||
WHERE SalonID = $1 AND YclientsID = $2 AND deleted = false
|
||||
|
||||
@ -511,40 +511,56 @@ func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context,
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (r *YclientsRepository) GetAccountTimeslotsByID(ctx context.Context, salonID int32) ([]model.Timeslots, error) {
|
||||
rows, err := r.queries.GetTimeslotsByIDYclients(ctx, salonID)
|
||||
func (r *YclientsRepository) UpdateAccountTimeslots(ctx context.Context, salonID int32, timeslots model.Timeslots) error {
|
||||
weekdaysSettings, err := json.Marshal(timeslots.WeekdaysSettings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return 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,
|
||||
})
|
||||
datesSettings, err := json.Marshal(timeslots.DatesSettings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return timeslots, nil
|
||||
|
||||
err = r.queries.UpdateYclientsAccountTimeslots(ctx, sqlcgen.UpdateYclientsAccountTimeslotsParams{
|
||||
Salonid: salonID,
|
||||
Isenabled: timeslots.IsEnabled,
|
||||
Weekdayssettings: weekdaysSettings,
|
||||
Datessettings: datesSettings,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// todo
|
||||
func (r *YclientsRepository) UpdateTimeslots() {
|
||||
func (r *YclientsRepository) AddAccountTimeslots(ctx context.Context, salonID int32, timeslots model.Timeslots) error {
|
||||
weekdaysSettings, err := json.Marshal(timeslots.WeekdaysSettings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
datesSettings, err := json.Marshal(timeslots.DatesSettings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = r.queries.AddYclientsAccountTimeslots(ctx, sqlcgen.AddYclientsAccountTimeslotsParams{
|
||||
Salonid: salonID,
|
||||
Isenabled: timeslots.IsEnabled,
|
||||
Weekdayssettings: weekdaysSettings,
|
||||
Datessettings: datesSettings,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *YclientsRepository) DeleteTimeslots(ctx context.Context, ids []int64) error {
|
||||
err := r.queries.DeleteYclientsTimeslots(ctx, ids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user