289 lines
6.6 KiB
Go
289 lines
6.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: schedules.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createScheduleDay = `-- name: CreateScheduleDay :one
|
|
INSERT INTO schedule_days (id, project_id, date, status, note)
|
|
VALUES (?, ?, ?, ?, ?)
|
|
RETURNING id, project_id, date, status, note, created_at, updated_at
|
|
`
|
|
|
|
type CreateScheduleDayParams struct {
|
|
ID string `json:"id"`
|
|
ProjectID string `json:"project_id"`
|
|
Date string `json:"date"`
|
|
Status string `json:"status"`
|
|
Note string `json:"note"`
|
|
}
|
|
|
|
func (q *Queries) CreateScheduleDay(ctx context.Context, arg CreateScheduleDayParams) (ScheduleDay, error) {
|
|
row := q.db.QueryRowContext(ctx, createScheduleDay,
|
|
arg.ID,
|
|
arg.ProjectID,
|
|
arg.Date,
|
|
arg.Status,
|
|
arg.Note,
|
|
)
|
|
var i ScheduleDay
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Date,
|
|
&i.Status,
|
|
&i.Note,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createTimeSlot = `-- name: CreateTimeSlot :one
|
|
INSERT INTO time_slots (id, schedule_day_id, start_time, end_time, status)
|
|
VALUES (?, ?, ?, ?, ?)
|
|
RETURNING id, schedule_day_id, start_time, end_time, status, created_at, updated_at
|
|
`
|
|
|
|
type CreateTimeSlotParams struct {
|
|
ID string `json:"id"`
|
|
ScheduleDayID string `json:"schedule_day_id"`
|
|
StartTime string `json:"start_time"`
|
|
EndTime string `json:"end_time"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) CreateTimeSlot(ctx context.Context, arg CreateTimeSlotParams) (TimeSlot, error) {
|
|
row := q.db.QueryRowContext(ctx, createTimeSlot,
|
|
arg.ID,
|
|
arg.ScheduleDayID,
|
|
arg.StartTime,
|
|
arg.EndTime,
|
|
arg.Status,
|
|
)
|
|
var i TimeSlot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ScheduleDayID,
|
|
&i.StartTime,
|
|
&i.EndTime,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteScheduleDaysByProject = `-- name: DeleteScheduleDaysByProject :exec
|
|
DELETE FROM schedule_days
|
|
WHERE project_id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteScheduleDaysByProject(ctx context.Context, projectID string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteScheduleDaysByProject, projectID)
|
|
return err
|
|
}
|
|
|
|
const deleteTimeSlotsByProject = `-- name: DeleteTimeSlotsByProject :exec
|
|
DELETE FROM time_slots
|
|
WHERE schedule_day_id IN (
|
|
SELECT id FROM schedule_days
|
|
WHERE project_id = ?
|
|
)
|
|
`
|
|
|
|
func (q *Queries) DeleteTimeSlotsByProject(ctx context.Context, projectID string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteTimeSlotsByProject, projectID)
|
|
return err
|
|
}
|
|
|
|
const getScheduleDay = `-- name: GetScheduleDay :one
|
|
SELECT id, project_id, date, status, note, created_at, updated_at FROM schedule_days
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) GetScheduleDay(ctx context.Context, id string) (ScheduleDay, error) {
|
|
row := q.db.QueryRowContext(ctx, getScheduleDay, id)
|
|
var i ScheduleDay
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Date,
|
|
&i.Status,
|
|
&i.Note,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getTimeSlot = `-- name: GetTimeSlot :one
|
|
SELECT id, schedule_day_id, start_time, end_time, status, created_at, updated_at FROM time_slots
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) GetTimeSlot(ctx context.Context, id string) (TimeSlot, error) {
|
|
row := q.db.QueryRowContext(ctx, getTimeSlot, id)
|
|
var i TimeSlot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ScheduleDayID,
|
|
&i.StartTime,
|
|
&i.EndTime,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listScheduleDaysByProjectMonth = `-- name: ListScheduleDaysByProjectMonth :many
|
|
SELECT id, project_id, date, status, note, created_at, updated_at FROM schedule_days
|
|
WHERE project_id = ?1 AND date LIKE ?2 || '%'
|
|
ORDER BY date ASC
|
|
`
|
|
|
|
type ListScheduleDaysByProjectMonthParams struct {
|
|
ProjectID string `json:"project_id"`
|
|
Month sql.NullString `json:"month"`
|
|
}
|
|
|
|
func (q *Queries) ListScheduleDaysByProjectMonth(ctx context.Context, arg ListScheduleDaysByProjectMonthParams) ([]ScheduleDay, error) {
|
|
rows, err := q.db.QueryContext(ctx, listScheduleDaysByProjectMonth, arg.ProjectID, arg.Month)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ScheduleDay
|
|
for rows.Next() {
|
|
var i ScheduleDay
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Date,
|
|
&i.Status,
|
|
&i.Note,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); 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 listTimeSlotsByDay = `-- name: ListTimeSlotsByDay :many
|
|
SELECT id, schedule_day_id, start_time, end_time, status, created_at, updated_at FROM time_slots
|
|
WHERE schedule_day_id = ?
|
|
ORDER BY start_time ASC
|
|
`
|
|
|
|
func (q *Queries) ListTimeSlotsByDay(ctx context.Context, scheduleDayID string) ([]TimeSlot, error) {
|
|
rows, err := q.db.QueryContext(ctx, listTimeSlotsByDay, scheduleDayID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []TimeSlot
|
|
for rows.Next() {
|
|
var i TimeSlot
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ScheduleDayID,
|
|
&i.StartTime,
|
|
&i.EndTime,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); 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 updateScheduleDay = `-- name: UpdateScheduleDay :one
|
|
UPDATE schedule_days
|
|
SET status = ?, note = ?, updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
RETURNING id, project_id, date, status, note, created_at, updated_at
|
|
`
|
|
|
|
type UpdateScheduleDayParams struct {
|
|
Status string `json:"status"`
|
|
Note string `json:"note"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateScheduleDay(ctx context.Context, arg UpdateScheduleDayParams) (ScheduleDay, error) {
|
|
row := q.db.QueryRowContext(ctx, updateScheduleDay, arg.Status, arg.Note, arg.ID)
|
|
var i ScheduleDay
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Date,
|
|
&i.Status,
|
|
&i.Note,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateTimeSlot = `-- name: UpdateTimeSlot :one
|
|
UPDATE time_slots
|
|
SET start_time = ?,
|
|
end_time = ?,
|
|
status = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
RETURNING id, schedule_day_id, start_time, end_time, status, created_at, updated_at
|
|
`
|
|
|
|
type UpdateTimeSlotParams struct {
|
|
StartTime string `json:"start_time"`
|
|
EndTime string `json:"end_time"`
|
|
Status string `json:"status"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateTimeSlot(ctx context.Context, arg UpdateTimeSlotParams) (TimeSlot, error) {
|
|
row := q.db.QueryRowContext(ctx, updateTimeSlot,
|
|
arg.StartTime,
|
|
arg.EndTime,
|
|
arg.Status,
|
|
arg.ID,
|
|
)
|
|
var i TimeSlot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ScheduleDayID,
|
|
&i.StartTime,
|
|
&i.EndTime,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|