mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
create item in service
This commit is contained in:
parent
92f8085537
commit
3dd36da114
3 changed files with 16 additions and 15 deletions
|
|
@ -43,6 +43,18 @@ func (bs Service) One(id int) *Booking {
|
|||
return b
|
||||
}
|
||||
|
||||
func (bs Service) CreateItem(bid int, item string, qty int, price float64, method string) *Item {
|
||||
i := &Item{
|
||||
BookingId: bid,
|
||||
Item: item,
|
||||
Quantity: qty,
|
||||
Price: price,
|
||||
PaymentMethod: method,
|
||||
}
|
||||
_ = bs.db.Create(i)
|
||||
return i
|
||||
}
|
||||
|
||||
type Line struct {
|
||||
From time.Time
|
||||
To time.Time
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ func handleBookingPage(bs *booking.Service) echo.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func (s Server) handleCreateItem() echo.HandlerFunc {
|
||||
func handleCreateItem(bs *booking.Service) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
bookingIdStr := c.Param("id")
|
||||
bid, err := strconv.Atoi(bookingIdStr)
|
||||
|
|
@ -134,15 +134,7 @@ func (s Server) handleCreateItem() echo.HandlerFunc {
|
|||
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 s.renderTempl(c, http.StatusCreated, views.LineItem(i))
|
||||
i := bs.CreateItem(bid, ni.Item, ni.Quantity, ni.Price, ni.PaymentMethod)
|
||||
return renderTempl(c, http.StatusCreated, views.LineItem(i))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
|
||||
"github.com/rjNemo/rentease/constants"
|
||||
)
|
||||
|
||||
func (s Server) MountHandlers() {
|
||||
|
|
@ -29,7 +26,7 @@ func (s Server) MountHandlers() {
|
|||
s.Router.GET("/bookings/new", handleNewBookingPage())
|
||||
s.Router.POST("/bookings/new", handleCreateBooking(s.bs))
|
||||
s.Router.GET("/bookings/:id", handleBookingPage(s.bs))
|
||||
s.Router.POST(fmt.Sprintf("%s/:id/items", constants.RouteBooking), s.handleCreateItem())
|
||||
s.Router.POST("bookings/:id/items", handleCreateItem(s.bs))
|
||||
s.Router.GET("/reports", handleReportsPage())
|
||||
s.Router.GET("/reports/do", handleComputeReport(s.bs))
|
||||
s.Router.GET("/pdf", handleCreateInvoicePdf(s.ps))
|
||||
|
|
|
|||
Loading…
Reference in a new issue