the rest
This commit is contained in:
212
internal/db/bookings.sql.go
Normal file
212
internal/db/bookings.sql.go
Normal file
@@ -0,0 +1,212 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: bookings.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
const createBooking = `-- name: CreateBooking :one
|
||||
INSERT INTO bookings (user_id, service_id, event_date, address, notes, status)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, user_id, service_id, event_date, address, notes, created_at, status
|
||||
`
|
||||
|
||||
type CreateBookingParams struct {
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
type CreateBookingRow struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBooking(ctx context.Context, arg CreateBookingParams) (CreateBookingRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, createBooking,
|
||||
arg.UserID,
|
||||
arg.ServiceID,
|
||||
arg.EventDate,
|
||||
arg.Address,
|
||||
arg.Notes,
|
||||
arg.Status,
|
||||
)
|
||||
var i CreateBookingRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ServiceID,
|
||||
&i.EventDate,
|
||||
&i.Address,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBooking = `-- name: GetBooking :one
|
||||
SELECT id, user_id, service_id, event_date, address, notes, created_at, status
|
||||
FROM bookings
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type GetBookingRow struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetBooking(ctx context.Context, id int64) (GetBookingRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, getBooking, id)
|
||||
var i GetBookingRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ServiceID,
|
||||
&i.EventDate,
|
||||
&i.Address,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listBookingsByUser = `-- name: ListBookingsByUser :many
|
||||
SELECT id, user_id, service_id, event_date, address, notes, created_at, status
|
||||
FROM bookings
|
||||
WHERE user_id = $1
|
||||
ORDER BY event_date DESC
|
||||
`
|
||||
|
||||
type ListBookingsByUserRow struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListBookingsByUser(ctx context.Context, userID sql.NullInt64) ([]ListBookingsByUserRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listBookingsByUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListBookingsByUserRow{}
|
||||
for rows.Next() {
|
||||
var i ListBookingsByUserRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ServiceID,
|
||||
&i.EventDate,
|
||||
&i.Address,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
); 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 listBookingsWithServiceByUser = `-- name: ListBookingsWithServiceByUser :many
|
||||
SELECT
|
||||
b.id,
|
||||
b.user_id,
|
||||
b.service_id,
|
||||
b.event_date,
|
||||
b.address,
|
||||
b.notes,
|
||||
b.created_at,
|
||||
b.status,
|
||||
s.name as service_name,
|
||||
s.description as service_description,
|
||||
s.price_cents as service_price_cents
|
||||
FROM bookings b
|
||||
JOIN services s ON b.service_id = s.id
|
||||
WHERE b.user_id = $1
|
||||
ORDER BY b.event_date DESC
|
||||
`
|
||||
|
||||
type ListBookingsWithServiceByUserRow struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Status sql.NullString `json:"status"`
|
||||
ServiceName string `json:"service_name"`
|
||||
ServiceDescription sql.NullString `json:"service_description"`
|
||||
ServicePriceCents int32 `json:"service_price_cents"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListBookingsWithServiceByUser(ctx context.Context, userID sql.NullInt64) ([]ListBookingsWithServiceByUserRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listBookingsWithServiceByUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListBookingsWithServiceByUserRow{}
|
||||
for rows.Next() {
|
||||
var i ListBookingsWithServiceByUserRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ServiceID,
|
||||
&i.EventDate,
|
||||
&i.Address,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
&i.ServiceName,
|
||||
&i.ServiceDescription,
|
||||
&i.ServicePriceCents,
|
||||
); 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
|
||||
}
|
||||
Reference in New Issue
Block a user