From 5927e935ea5e4292a862c61046e47be7ea096523 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Fri, 9 Feb 2024 14:13:27 +0100 Subject: [PATCH] add list bookings page --- internal/server/handlers.go | 9 ++ internal/server/server.go | 1 + internal/views/bookings_list.templ | 40 ++++++ internal/views/bookings_list_templ.go | 172 ++++++++++++++++++++++++++ 4 files changed, 222 insertions(+) create mode 100644 internal/views/bookings_list.templ create mode 100644 internal/views/bookings_list_templ.go diff --git a/internal/server/handlers.go b/internal/server/handlers.go index 6af8624..ba314a4 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -24,6 +24,15 @@ func (s Server) handleHomePage() echo.HandlerFunc { } } +func (s Server) handleListBookingPage() echo.HandlerFunc { + return func(c echo.Context) error { + bookings := make([]*booking.Booking, 0) + _ = s.db.Find(&bookings) + component := views.ListBookings(bookings) + return s.renderTempl(c, http.StatusOK, component) + } +} + func (s Server) handleNewBookingPage() echo.HandlerFunc { return func(c echo.Context) error { component := views.NewBooking(constants.Platforms) diff --git a/internal/server/server.go b/internal/server/server.go index 896fc1b..a63472f 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -50,6 +50,7 @@ func (s Server) MountHandlers() { s.Router.Static("/static", "assets") // landing page s.Router.GET("/", s.handleHomePage()) + s.Router.GET(constants.RouteBooking, s.handleListBookingPage()) s.Router.GET(constants.RouteNewBooking, s.handleNewBookingPage()) s.Router.POST(constants.RouteNewBooking, s.handleCreateBooking()) s.Router.GET(fmt.Sprintf("%s/:id", constants.RouteBooking), s.handleBookingPage()) diff --git a/internal/views/bookings_list.templ b/internal/views/bookings_list.templ new file mode 100644 index 0000000..153ed1d --- /dev/null +++ b/internal/views/bookings_list.templ @@ -0,0 +1,40 @@ +package views + +import "github.com/rjNemo/rentease/internal/domains/booking" +import "strconv" +import "fmt" + +templ ListBookings(bookings []*booking.Booking) { + @BaseLayout() { +
+ + + + + + + + + + + + + for _, b := range bookings { + + + + + + + + + } + +
IDNameTotal (€)FromToPlatform
+ + { strconv.Itoa(b.Id) } + + { b.Name }{ b.From.Format("2006-01-02") }{ b.To.Format("2006-01-02") }{ b.Platform }
+
+ } +} diff --git a/internal/views/bookings_list_templ.go b/internal/views/bookings_list_templ.go new file mode 100644 index 0000000..96a4c63 --- /dev/null +++ b/internal/views/bookings_list_templ.go @@ -0,0 +1,172 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: 0.2.476 +package views + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import "github.com/rjNemo/rentease/internal/domains/booking" +import "strconv" +import "fmt" + +func ListBookings(bookings []*booking.Booking) 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 { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var2 := 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 { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, b := range bookings { + _, 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_Var3 := `ID` + _, 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("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var4 := `Name` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(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 := `Total (€)` + _, 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_Var6 := `From` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6) + 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_Var7 := `To` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7) + 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_Var8 := `Platform` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8) + 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_Var10 string = strconv.Itoa(b.Id) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) + 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_Var11 string = b.Name + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) + 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_Var12 string = b.From.Format("2006-01-02") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) + 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_Var13 string = b.To.Format("2006-01-02") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) + 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_Var14 string = b.Platform + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) + 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 + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = BaseLayout().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +}