Files
Crussell/backend/handlers/bookings/repo.go
T
popertotsandSisyphus 0ea1bb64b4 feat(bookings): add closing_time validation and repo layer
Extract closing hours check into reusable checkClosingHours helper. Add repo.go for shared DB query helpers. Update admin_reserve to use closing_time and move overlap check inside transaction with FOR UPDATE.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-24 23:43:23 +01:00

47 lines
1.6 KiB
Go

package bookings
import (
"context"
"time"
"crussell/db"
)
// GetBookingStatus returns the status of a booking by ID.
// Uses db.Conn directly — not for use inside transactions.
func GetBookingStatus(ctx context.Context, bookingID string) (string, error) {
var status string
err := db.Conn.QueryRow(ctx, `SELECT status FROM bookings WHERE id = $1`, bookingID).Scan(&status)
if err != nil {
return "", err
}
return status, nil
}
// GetBookingStartTime returns the start_time of a booking by ID.
// Uses db.Conn directly — not for use inside transactions.
func GetBookingStartTime(ctx context.Context, bookingID string) (time.Time, error) {
var startTime time.Time
err := db.Conn.QueryRow(ctx, `SELECT start_time FROM bookings WHERE id = $1`, bookingID).Scan(&startTime)
if err != nil {
return time.Time{}, err
}
return startTime, nil
}
// BookingExists checks if a booking with the given ID exists.
// Uses db.Conn directly — not for use inside transactions.
func BookingExists(ctx context.Context, bookingID string) (bool, error) {
var exists bool
err := db.Conn.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM bookings WHERE id = $1)`, bookingID).Scan(&exists)
return exists, err
}
// CountUserBookingsInStatus counts the number of bookings for a user with a specific status.
// Uses db.Conn directly — not for use inside transactions.
func CountUserBookingsInStatus(ctx context.Context, userID, status string) (int, error) {
var count int
err := db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = $2`, userID, status).Scan(&count)
return count, err
}