feat(backend): update scheduling handlers

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-18 16:26:39 +01:00
co-authored by Sisyphus
parent 6ff35a5cc7
commit 6c89fea118
6 changed files with 367 additions and 111 deletions
+15 -3
View File
@@ -9,15 +9,16 @@ import (
"time"
"crussell/db"
"crussell/internal/validators"
"crussell/mw"
"log"
)
// --- Types ---
type DefaultHours struct {
Weekday int `json:"weekday"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
Weekday int `json:"weekday" validate:"gte=0,lte=6"`
StartTime string `json:"startTime" validate:"required"`
EndTime string `json:"endTime" validate:"required"`
IsOpen bool `json:"isOpen"`
}
@@ -63,6 +64,16 @@ func UpdateDefaultHours(w http.ResponseWriter, r *http.Request) {
return
}
for _, h := range hours {
if err := validators.Validate.Struct(&h); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
// M8
// L5
for _, h := range hours {
if !isValidTime15Min(h.StartTime) {
http.Error(w, "start_time must be in 15-minute intervals (00, 15, 30, 45)", http.StatusBadRequest)
@@ -425,6 +436,7 @@ func GetAvailableHours(w http.ResponseWriter, r *http.Request) {
) sub), 0) AS total_duration
FROM bookings b
WHERE b.start_time >= $1 AND b.start_time <= $2
AND b.status NOT IN ('client_cancelled', 'we_cancelled', 'no_show', 'pending_release', 'deposit_lapsed')
ORDER BY b.start_time
`, start, end)