From e88d62513082100de94cf4bb0178f760d151ce3f Mon Sep 17 00:00:00 2001 From: tumillanino Date: Tue, 28 Oct 2025 13:44:34 +1100 Subject: [PATCH] linked service id directly to service offered --- internal/handlers/booking.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/handlers/booking.go b/internal/handlers/booking.go index b43259a..9648cff 100644 --- a/internal/handlers/booking.go +++ b/internal/handlers/booking.go @@ -14,6 +14,19 @@ import ( "decor-by-hannahs/internal/db" ) +func getServiceIDFromOption(option string) int64 { + serviceMap := map[string]int64{ + "Small Bundle": 1, + "Medium Bundle": 2, + "Large Bundle": 3, + "Balloons Only": 4, + } + if id, ok := serviceMap[option]; ok { + return id + } + return 1 +} + func validateAustralianAddress(address string) (bool, string) { if len(strings.TrimSpace(address)) < 10 { return false, "Address is too short. Please provide a complete address." @@ -125,10 +138,11 @@ func BookingAPIHandler(q *db.Queries, tmpl *template.Template, oryClient *ory.AP } userID := sql.NullInt64{Int64: user.ID, Valid: true} + serviceID := getServiceIDFromOption(in.ServiceOption) booking, err := q.CreateBooking(r.Context(), db.CreateBookingParams{ UserID: userID, - ServiceID: sql.NullInt64{}, + ServiceID: sql.NullInt64{Int64: serviceID, Valid: true}, EventDate: eventTime, Address: sqlNullString(in.Address), Notes: sqlNullString(in.Notes),