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 {
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
}