refactor: bookings and services handlers with shared formatting

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-05-29 16:06:40 +01:00
co-authored by Sisyphus
parent 9deae1b0d7
commit aa75217898
2 changed files with 89 additions and 45 deletions
+12 -3
View File
@@ -36,7 +36,8 @@ type Booking struct {
Notes *string `json:"notes,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy *string `json:"created_by,omitempty"`
CreatedBy *string `json:"created_by,omitempty"`
CreatedByName *string `json:"created_by_name,omitempty"`
// Deposit fields.
// DepositRequired is snapshotted at creation from users.deposits_required > 0
@@ -752,25 +753,33 @@ func GetAdminBookingHandler(w http.ResponseWriter, r *http.Request) {
var booking Booking
booking.User = &UserSummary{}
var depositRequired bool
var dateOfBirth sql.NullTime
err := db.DB.QueryRow(r.Context(), `
SELECT
b.id, b.user_id, b.start_time, b.status, b.notes,
b.created_at, b.updated_at, b.created_by,
u.fn, u.email, u.phone, u.profile_pic_url, u.loyalty_stamps,
u.fn, u.email, u.phone, u.profile_pic_url, u.date_of_birth, u.loyalty_stamps,
u.referral_code, u.notes,
creator.fn,
b.deposit_required
FROM bookings b
LEFT JOIN users u ON b.user_id = u.id
LEFT JOIN users creator ON b.created_by = creator.id
WHERE b.id = $1
`, bookingID).Scan(
&booking.ID, &booking.User.ID, &booking.StartTime, &booking.Status, &booking.Notes,
&booking.CreatedAt, &booking.UpdatedAt, &booking.CreatedBy,
&booking.User.FullName, &booking.User.Email, &booking.User.Phone,
&booking.User.ProfilePicURL, &booking.User.LoyaltyStamps,
&booking.User.ProfilePicURL, &dateOfBirth, &booking.User.LoyaltyStamps,
&booking.User.ReferralCode, &booking.User.Notes,
&booking.CreatedByName,
&depositRequired,
)
if dateOfBirth.Valid {
s := dateOfBirth.Time.Format("2006-01-02")
booking.User.DateOfBirth = &s
}
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
http.Error(w, "Booking not found", http.StatusNotFound)