diff --git a/internal/booking/models.go b/internal/booking/models.go index 3d03a06..bce7855 100644 --- a/internal/booking/models.go +++ b/internal/booking/models.go @@ -18,7 +18,7 @@ type Booking struct { PhoneNumber string Email string Platform string - ExternalId string `gorm:"uniqueIndex:booking_external_id"` + ExternalId *string `gorm:"uniqueIndex:booking_external_id"` Items []Item Id int CustomerNumber int `gorm:"column:customers"` diff --git a/internal/booking/service.go b/internal/booking/service.go index 0dd7ed1..cda8b4c 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -38,7 +38,7 @@ func (bs Service) All() []*Line { } func (bs Service) Create(From time.Time, To time.Time, Name string, PhoneNumber string, Email string, Platform string, - CustomerNumber int, PlatformFees float64, externalId string, + CustomerNumber int, PlatformFees float64, externalId *string, ) *Booking { b := &Booking{ Name: Name, @@ -253,7 +253,7 @@ func (bs Service) ParseFromApi(rawContent string) (*Booking, error) { standardRate := extractFloat(`Standard Rate\n\s+€ (\d+)`, content) taxQty := (totalAmount - standardRate*float64(stayLength)) / 1.5 - b := bs.Create(*formatDate(arrivalDate), *formatDate(departureDate), customerName, "", customerEmail, "Booking", customerNumber, commissionAmount, externalId) + b := bs.Create(*formatDate(arrivalDate), *formatDate(departureDate), customerName, "", customerEmail, "Booking", customerNumber, commissionAmount, &externalId) bs.CreateItem(b.Id, item, stayLength, standardRate, "Card") bs.CreateItem(b.Id, "Taxes", int(taxQty), 1.5, "Cash") diff --git a/internal/server/handle_bookings.go b/internal/server/handle_bookings.go index 2383688..1c6db05 100644 --- a/internal/server/handle_bookings.go +++ b/internal/server/handle_bookings.go @@ -72,7 +72,7 @@ func handleCreateBooking(bs *booking.Service) echo.HandlerFunc { ts, _ = myTime.ParseFromForm(c.FormValue("to")) nb.To = ts - b := bs.Create(nb.From, nb.To, nb.Name, nb.PhoneNumber, nb.Email, nb.Platform, nb.CustomerNumber, nb.PlatformFees, "") // TODO: add field in the form + b := bs.Create(nb.From, nb.To, nb.Name, nb.PhoneNumber, nb.Email, nb.Platform, nb.CustomerNumber, nb.PlatformFees, nil) // TODO: add field in the form return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s/%d", constant.RouteBooking, b.Id)) } }