diff --git a/internal/domains/booking/models.go b/internal/domains/booking/models.go index 43ff94a..dfc7b72 100644 --- a/internal/domains/booking/models.go +++ b/internal/domains/booking/models.go @@ -17,4 +17,16 @@ type Booking struct { To time.Time Platform string PlatformFees string + Items []Item +} + +type Item struct { + gorm.Model + Id int + BookingId int + Item string + Quantity int + Price string + PaymentMethod string + PaymentStatus string } diff --git a/internal/server/handlers.go b/internal/server/handlers.go index 42a7d5b..ccea768 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -3,6 +3,7 @@ package server import ( "fmt" "net/http" + "strconv" "time" "github.com/labstack/echo/v4" @@ -68,7 +69,15 @@ func (s Server) handleCreateBooking() echo.HandlerFunc { func (s Server) handleBookingPage() echo.HandlerFunc { return func(c echo.Context) error { - component := views.BookingById() + idStr := c.Param("id") + id, err := strconv.Atoi(idStr) + if err != nil { + return err + } + b := &booking.Booking{Id: id} + s.db.Preload("Items").First(b) + + component := views.BookingById(b, constants.Platforms) return s.renderTempl(c, http.StatusOK, component) } diff --git a/internal/views/booking_by_id.templ b/internal/views/booking_by_id.templ index 400e8d0..864ddfe 100644 --- a/internal/views/booking_by_id.templ +++ b/internal/views/booking_by_id.templ @@ -1,7 +1,92 @@ package views -templ BookingById() { - @BaseLayout() { -

ok

- } -} \ No newline at end of file +import ( + "fmt" + "strconv" + + "github.com/rjNemo/rentease/internal/domains/booking" +) + +templ BookingById(booking *booking.Booking, platforms []string) { + @BaseLayout() { +
+

Booking ID: VFNI#{ fmt.Sprintf("%04s", strconv.Itoa(booking.Id)) }

+

Manage a booking

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+

Line Items

+
+ + + + + + + + + + + + + for i, item := range booking.Items { + + + + + + + + + } + +
#ItemQuantityPricePayment MethodPayment Status
{ strconv.Itoa(i+1) }{ item.Item }{ strconv.Itoa(item.Quantity) }{ item.Price }{ item.PaymentMethod }{ item.PaymentStatus }
+
+ } +} diff --git a/internal/views/booking_by_id_templ.go b/internal/views/booking_by_id_templ.go index 41a9a90..92a549f 100644 --- a/internal/views/booking_by_id_templ.go +++ b/internal/views/booking_by_id_templ.go @@ -10,7 +10,14 @@ import "context" import "io" import "bytes" -func BookingById() templ.Component { +import ( + "fmt" + "strconv" + + "github.com/rjNemo/rentease/internal/domains/booking" +) + +func BookingById(booking *booking.Booking, platforms []string) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -29,16 +36,338 @@ func BookingById() templ.Component { templ_7745c5c3_Buffer = templ.GetBuffer() defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Var3 := `ok ` + templ_7745c5c3_Var3 := `Booking ID: VFNI#` _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + var templ_7745c5c3_Var4 string = fmt.Sprintf("%04s", strconv.Itoa(booking.Id)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var5 := `Manage a booking ` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var17 := `Line Items ` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for i, item := range booking.Items { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var18 := `#` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var18) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var19 := `Item` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var19) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var20 := `Quantity` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var20) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var21 := `Price` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var21) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var22 := `Payment Method` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var22) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var23 := `Payment Status` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var23) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var24 string = strconv.Itoa(i + 1) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var25 string = item.Item + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var26 string = strconv.Itoa(item.Quantity) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var27 string = item.Price + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var28 string = item.PaymentMethod + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var29 string = item.PaymentStatus + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/main.go b/main.go index 8aa4972..6c75154 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ func main() { log.Fatalf("error connecting to the database %s\n", err) } - err = db.AutoMigrate(&booking.Booking{}) + err = db.AutoMigrate(&booking.Booking{}, &booking.Item{}) if err != nil { log.Fatalf("error migrating the database %s\n", err) }