Remove useless fields from paymentDraft

At first i thought i would need to keep the second query of draftPayment
in newBookingCart, its caller, and i added these fields to pass back
the parsed or retrieved values, but when i could move that query within
draftPayment i forgot to remove them.
This commit is contained in:
jordi fita mas 2024-04-25 13:17:07 +02:00
parent 9eb6483cb9
commit 30e87c309e
1 changed files with 22 additions and 24 deletions

View File

@ -25,15 +25,10 @@ type cartLine struct {
} }
type paymentDraft struct { type paymentDraft struct {
ArrivalDate time.Time
DepartureDate time.Time
NumAdults int NumAdults int
NumTeenagers int NumTeenagers int
NumChildren int NumChildren int
NumDogs int NumDogs int
ZonePreferences string
ACSICard bool
PaymentID int
NumNights int NumNights int
Nights string Nights string
Adults string Adults string
@ -55,24 +50,24 @@ type paymentOption struct {
} }
func draftPayment(ctx context.Context, conn *database.Conn, f *bookingForm, campsiteType string) (*paymentDraft, error) { func draftPayment(ctx context.Context, conn *database.Conn, f *bookingForm, campsiteType string) (*paymentDraft, error) {
var err error
if f.Dates == nil { if f.Dates == nil {
return nil, 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 { if f.Guests == nil {
return nil, 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) draft.NumAdults, err = strconv.Atoi(f.Guests.NumberAdults.Val)
if err != nil { if err != nil {
return nil, 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 { 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 { if f.Guests.ACSICard != nil {
draft.ACSICard = f.Guests.ACSICard.Checked acsiCard = f.Guests.ACSICard.Checked
} }
optionMap := make(map[int]*campsiteTypeOption) 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) join currency using (currency_code)
`, `,
database.ZeroNullUUID(f.PaymentSlug.Val), database.ZeroNullUUID(f.PaymentSlug.Val),
draft.ArrivalDate, arrivalDate,
draft.DepartureDate, departureDate,
campsiteType, campsiteType,
draft.NumAdults, draft.NumAdults,
draft.NumTeenagers, draft.NumTeenagers,
draft.NumChildren, draft.NumChildren,
draft.NumDogs, draft.NumDogs,
draft.ZonePreferences, zonePreferences,
draft.ACSICard, acsiCard,
database.OptionUnitsArray(optionUnits), database.OptionUnitsArray(optionUnits),
) )
var paymentID int
if err = row.Scan( if err = row.Scan(
&f.PaymentSlug.Val, &f.PaymentSlug.Val,
&draft.PaymentID, &paymentID,
&draft.NumNights, &draft.NumNights,
&draft.Nights, &draft.Nights,
&draft.Adults, &draft.Adults,
@ -175,7 +173,7 @@ func draftPayment(ctx context.Context, conn *database.Conn, f *bookingForm, camp
join currency using (currency_code) join currency using (currency_code)
where payment_id = $1 where payment_id = $1
order by campsite_type_option_id order by campsite_type_option_id
`, draft.PaymentID) `, paymentID)
if err != nil { if err != nil {
return nil, err return nil, err
} }