diff --git a/Makefile b/Makefile
index d60cf78..4122f7a 100644
--- a/Makefile
+++ b/Makefile
@@ -3,18 +3,18 @@ PORT=8000
DB_USER=ruidy
DB_NAME=villafleurie
-build: templ
+build: format lint templ
@docker build -t ${NAME}:latest .
run: build
@docker run -p ${PORT}:${PORT} -e DATABASE_URL="host=docker.for.mac.host.internal user=${DB_USER} database=${DB_NAME}" -e PORT=${PORT} ${NAME}
dev: templ
@air cmd/main.go
-templ: lint
+templ:
@templ generate
format:
@templ fmt .
@go fmt ./...
-lint: format
+lint:
@golangci-lint run ./...
.PHONY: build run dev templ format lint
diff --git a/constants/items.go b/constants/items.go
new file mode 100644
index 0000000..28f0c57
--- /dev/null
+++ b/constants/items.go
@@ -0,0 +1,3 @@
+package constants
+
+var Items = []string{"T2", "T3", "Airport", "Port"}
diff --git a/constants/payment_methods.go b/constants/payment_methods.go
new file mode 100644
index 0000000..93fa8a7
--- /dev/null
+++ b/constants/payment_methods.go
@@ -0,0 +1,3 @@
+package constants
+
+var PaymentMethods = []string{"Card", "Cash", "Cheque", "Transfer"}
diff --git a/internal/domains/booking/models.go b/internal/domains/booking/models.go
index dfc7b72..7ce3c17 100644
--- a/internal/domains/booking/models.go
+++ b/internal/domains/booking/models.go
@@ -28,5 +28,5 @@ type Item struct {
Quantity int
Price string
PaymentMethod string
- PaymentStatus string
+ PaymentStatus string `gorm:"default:Pending"`
}
diff --git a/internal/server/handlers.go b/internal/server/handlers.go
index ccea768..2b6af85 100644
--- a/internal/server/handlers.go
+++ b/internal/server/handlers.go
@@ -77,12 +77,44 @@ func (s Server) handleBookingPage() echo.HandlerFunc {
b := &booking.Booking{Id: id}
s.db.Preload("Items").First(b)
- component := views.BookingById(b, constants.Platforms)
+ component := views.BookingById(b, constants.Items, constants.Platforms, constants.PaymentMethods)
return s.renderTempl(c, http.StatusOK, component)
}
}
+func (s Server) handleCreateItem() echo.HandlerFunc {
+ return func(c echo.Context) error {
+ bookingIdStr := c.Param("id")
+ bid, err := strconv.Atoi(bookingIdStr)
+ if err != nil {
+ return err
+ }
+
+ type NewItem struct {
+ Item string `form:"item"`
+ Quantity int `form:"quantity"`
+ Price string `form:"price"`
+ PaymentMethod string `form:"method"`
+ }
+ ni := new(NewItem)
+ if err := c.Bind(ni); err != nil {
+ log.Warn(err)
+ return err
+ }
+
+ i := &booking.Item{
+ BookingId: bid,
+ Item: ni.Item,
+ Quantity: ni.Quantity,
+ Price: ni.Price,
+ PaymentMethod: ni.PaymentMethod,
+ }
+ _ = s.db.Create(i)
+ return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s/%d", constants.RouteBooking, bid))
+ }
+}
+
func parseTime(src string) (time.Time, error) {
ts, err := time.Parse("2006-01-02", src)
if err != nil {
diff --git a/internal/server/server.go b/internal/server/server.go
index 2635204..896fc1b 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -53,6 +53,7 @@ func (s Server) MountHandlers() {
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())
+ s.Router.POST(fmt.Sprintf("%s/:id/items", constants.RouteBooking), s.handleCreateItem())
}
func (s Server) Start() {
diff --git a/internal/views/booking_by_id.templ b/internal/views/booking_by_id.templ
index 864ddfe..3f1418e 100644
--- a/internal/views/booking_by_id.templ
+++ b/internal/views/booking_by_id.templ
@@ -7,10 +7,10 @@ import (
"github.com/rjNemo/rentease/internal/domains/booking"
)
-templ BookingById(booking *booking.Booking, platforms []string) {
+templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []string) {
@BaseLayout() {
- Booking ID: VFNI#{ fmt.Sprintf("%04s", strconv.Itoa(booking.Id)) }
+ Booking ID VFNI#{ fmt.Sprintf("%04s", strconv.Itoa(booking.Id)) }
Manage a booking