283 lines
6.4 KiB
Go
283 lines
6.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: bookings.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const cancelBooking = `-- name: CancelBooking :one
|
|
UPDATE bookings
|
|
SET status = 'cancelled_by_user', updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ? AND phone = ? AND status IN ('pending', 'confirmed')
|
|
RETURNING id, user_id, project_id, slot_id, phone, status, remark, confirm_token, created_at, updated_at
|
|
`
|
|
|
|
type CancelBookingParams struct {
|
|
ID string `json:"id"`
|
|
Phone string `json:"phone"`
|
|
}
|
|
|
|
func (q *Queries) CancelBooking(ctx context.Context, arg CancelBookingParams) (Booking, error) {
|
|
row := q.db.QueryRowContext(ctx, cancelBooking, arg.ID, arg.Phone)
|
|
var i Booking
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.ProjectID,
|
|
&i.SlotID,
|
|
&i.Phone,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.ConfirmToken,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const countBookingsByProject = `-- name: CountBookingsByProject :one
|
|
SELECT COUNT(*) FROM bookings
|
|
WHERE project_id = ?
|
|
`
|
|
|
|
func (q *Queries) CountBookingsByProject(ctx context.Context, projectID string) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countBookingsByProject, projectID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createBooking = `-- name: CreateBooking :one
|
|
INSERT INTO bookings (id, user_id, project_id, slot_id, phone, status, remark, confirm_token)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
RETURNING id, user_id, project_id, slot_id, phone, status, remark, confirm_token, created_at, updated_at
|
|
`
|
|
|
|
type CreateBookingParams struct {
|
|
ID string `json:"id"`
|
|
UserID sql.NullString `json:"user_id"`
|
|
ProjectID string `json:"project_id"`
|
|
SlotID string `json:"slot_id"`
|
|
Phone string `json:"phone"`
|
|
Status string `json:"status"`
|
|
Remark string `json:"remark"`
|
|
ConfirmToken string `json:"confirm_token"`
|
|
}
|
|
|
|
func (q *Queries) CreateBooking(ctx context.Context, arg CreateBookingParams) (Booking, error) {
|
|
row := q.db.QueryRowContext(ctx, createBooking,
|
|
arg.ID,
|
|
arg.UserID,
|
|
arg.ProjectID,
|
|
arg.SlotID,
|
|
arg.Phone,
|
|
arg.Status,
|
|
arg.Remark,
|
|
arg.ConfirmToken,
|
|
)
|
|
var i Booking
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.ProjectID,
|
|
&i.SlotID,
|
|
&i.Phone,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.ConfirmToken,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getBooking = `-- name: GetBooking :one
|
|
SELECT id, user_id, project_id, slot_id, phone, status, remark, confirm_token, created_at, updated_at FROM bookings
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) GetBooking(ctx context.Context, id string) (Booking, error) {
|
|
row := q.db.QueryRowContext(ctx, getBooking, id)
|
|
var i Booking
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.ProjectID,
|
|
&i.SlotID,
|
|
&i.Phone,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.ConfirmToken,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listBookings = `-- name: ListBookings :many
|
|
SELECT id, user_id, project_id, slot_id, phone, status, remark, confirm_token, created_at, updated_at FROM bookings
|
|
ORDER BY created_at DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListBookingsParams struct {
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListBookings(ctx context.Context, arg ListBookingsParams) ([]Booking, error) {
|
|
rows, err := q.db.QueryContext(ctx, listBookings, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Booking
|
|
for rows.Next() {
|
|
var i Booking
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.ProjectID,
|
|
&i.SlotID,
|
|
&i.Phone,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.ConfirmToken,
|
|
&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 listBookingsByPhone = `-- name: ListBookingsByPhone :many
|
|
SELECT id, user_id, project_id, slot_id, phone, status, remark, confirm_token, created_at, updated_at FROM bookings
|
|
WHERE phone = ?
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListBookingsByPhone(ctx context.Context, phone string) ([]Booking, error) {
|
|
rows, err := q.db.QueryContext(ctx, listBookingsByPhone, phone)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Booking
|
|
for rows.Next() {
|
|
var i Booking
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.ProjectID,
|
|
&i.SlotID,
|
|
&i.Phone,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.ConfirmToken,
|
|
&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 listBookingsByStatus = `-- name: ListBookingsByStatus :many
|
|
SELECT id, user_id, project_id, slot_id, phone, status, remark, confirm_token, created_at, updated_at FROM bookings
|
|
WHERE status = ?
|
|
ORDER BY created_at DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListBookingsByStatusParams struct {
|
|
Status string `json:"status"`
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListBookingsByStatus(ctx context.Context, arg ListBookingsByStatusParams) ([]Booking, error) {
|
|
rows, err := q.db.QueryContext(ctx, listBookingsByStatus, arg.Status, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Booking
|
|
for rows.Next() {
|
|
var i Booking
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.ProjectID,
|
|
&i.SlotID,
|
|
&i.Phone,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.ConfirmToken,
|
|
&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 updateBookingStatus = `-- name: UpdateBookingStatus :one
|
|
UPDATE bookings
|
|
SET status = ?, updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
RETURNING id, user_id, project_id, slot_id, phone, status, remark, confirm_token, created_at, updated_at
|
|
`
|
|
|
|
type UpdateBookingStatusParams struct {
|
|
Status string `json:"status"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBookingStatus(ctx context.Context, arg UpdateBookingStatusParams) (Booking, error) {
|
|
row := q.db.QueryRowContext(ctx, updateBookingStatus, arg.Status, arg.ID)
|
|
var i Booking
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.ProjectID,
|
|
&i.SlotID,
|
|
&i.Phone,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.ConfirmToken,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|