diff --git a/pkg/booking/cart.go b/pkg/booking/cart.go index d8920bd..1f9f6a8 100644 --- a/pkg/booking/cart.go +++ b/pkg/booking/cart.go @@ -25,15 +25,10 @@ type cartLine struct { } type paymentDraft struct { - ArrivalDate time.Time - DepartureDate time.Time NumAdults int NumTeenagers int NumChildren int NumDogs int - ZonePreferences string - ACSICard bool - PaymentID int NumNights int Nights string Adults string @@ -55,24 +50,24 @@ type paymentOption struct { } func draftPayment(ctx context.Context, conn *database.Conn, f *bookingForm, campsiteType string) (*paymentDraft, error) { - var err error if f.Dates == nil { return nil, nil } - draft := &paymentDraft{} - draft.ArrivalDate, err = time.Parse(database.ISODateFormat, f.Dates.ArrivalDate.Val) - if err != nil { - return nil, nil - } - draft.DepartureDate, err = time.Parse(database.ISODateFormat, f.Dates.DepartureDate.Val) - if err != nil { - return nil, nil - } - if f.Guests == nil { return nil, nil } + + arrivalDate, err := time.Parse(database.ISODateFormat, f.Dates.ArrivalDate.Val) + if err != nil { + return nil, nil + } + departureDate, err := time.Parse(database.ISODateFormat, f.Dates.DepartureDate.Val) + if err != nil { + return nil, nil + } + + draft := &paymentDraft{} draft.NumAdults, err = strconv.Atoi(f.Guests.NumberAdults.Val) if err != nil { return nil, nil @@ -92,12 +87,14 @@ func draftPayment(ctx context.Context, conn *database.Conn, f *bookingForm, camp } } + var zonePreferences string if f.Options != nil && f.Options.ZonePreferences != nil { - draft.ZonePreferences = f.Options.ZonePreferences.Val + zonePreferences = f.Options.ZonePreferences.Val } + var acsiCard bool if f.Guests.ACSICard != nil { - draft.ACSICard = f.Guests.ACSICard.Checked + acsiCard = f.Guests.ACSICard.Checked } optionMap := make(map[int]*campsiteTypeOption) @@ -135,20 +132,21 @@ func draftPayment(ctx context.Context, conn *database.Conn, f *bookingForm, camp join currency using (currency_code) `, database.ZeroNullUUID(f.PaymentSlug.Val), - draft.ArrivalDate, - draft.DepartureDate, + arrivalDate, + departureDate, campsiteType, draft.NumAdults, draft.NumTeenagers, draft.NumChildren, draft.NumDogs, - draft.ZonePreferences, - draft.ACSICard, + zonePreferences, + acsiCard, database.OptionUnitsArray(optionUnits), ) + var paymentID int if err = row.Scan( &f.PaymentSlug.Val, - &draft.PaymentID, + &paymentID, &draft.NumNights, &draft.Nights, &draft.Adults, @@ -175,7 +173,7 @@ func draftPayment(ctx context.Context, conn *database.Conn, f *bookingForm, camp join currency using (currency_code) where payment_id = $1 order by campsite_type_option_id -`, draft.PaymentID) +`, paymentID) if err != nil { return nil, err }