mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
add line items
This commit is contained in:
parent
fbce6b6026
commit
80d7ff5d84
8 changed files with 211 additions and 10 deletions
6
Makefile
6
Makefile
|
|
@ -3,18 +3,18 @@ PORT=8000
|
||||||
DB_USER=ruidy
|
DB_USER=ruidy
|
||||||
DB_NAME=villafleurie
|
DB_NAME=villafleurie
|
||||||
|
|
||||||
build: templ
|
build: format lint templ
|
||||||
@docker build -t ${NAME}:latest .
|
@docker build -t ${NAME}:latest .
|
||||||
run: build
|
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}
|
@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
|
dev: templ
|
||||||
@air cmd/main.go
|
@air cmd/main.go
|
||||||
templ: lint
|
templ:
|
||||||
@templ generate
|
@templ generate
|
||||||
format:
|
format:
|
||||||
@templ fmt .
|
@templ fmt .
|
||||||
@go fmt ./...
|
@go fmt ./...
|
||||||
lint: format
|
lint:
|
||||||
@golangci-lint run ./...
|
@golangci-lint run ./...
|
||||||
|
|
||||||
.PHONY: build run dev templ format lint
|
.PHONY: build run dev templ format lint
|
||||||
|
|
|
||||||
3
constants/items.go
Normal file
3
constants/items.go
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
package constants
|
||||||
|
|
||||||
|
var Items = []string{"T2", "T3", "Airport", "Port"}
|
||||||
3
constants/payment_methods.go
Normal file
3
constants/payment_methods.go
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
package constants
|
||||||
|
|
||||||
|
var PaymentMethods = []string{"Card", "Cash", "Cheque", "Transfer"}
|
||||||
|
|
@ -28,5 +28,5 @@ type Item struct {
|
||||||
Quantity int
|
Quantity int
|
||||||
Price string
|
Price string
|
||||||
PaymentMethod string
|
PaymentMethod string
|
||||||
PaymentStatus string
|
PaymentStatus string `gorm:"default:Pending"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,44 @@ func (s Server) handleBookingPage() echo.HandlerFunc {
|
||||||
b := &booking.Booking{Id: id}
|
b := &booking.Booking{Id: id}
|
||||||
s.db.Preload("Items").First(b)
|
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)
|
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) {
|
func parseTime(src string) (time.Time, error) {
|
||||||
ts, err := time.Parse("2006-01-02", src)
|
ts, err := time.Parse("2006-01-02", src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ func (s Server) MountHandlers() {
|
||||||
s.Router.GET(constants.RouteNewBooking, s.handleNewBookingPage())
|
s.Router.GET(constants.RouteNewBooking, s.handleNewBookingPage())
|
||||||
s.Router.POST(constants.RouteNewBooking, s.handleCreateBooking())
|
s.Router.POST(constants.RouteNewBooking, s.handleCreateBooking())
|
||||||
s.Router.GET(fmt.Sprintf("%s/:id", constants.RouteBooking), s.handleBookingPage())
|
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() {
|
func (s Server) Start() {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ import (
|
||||||
"github.com/rjNemo/rentease/internal/domains/booking"
|
"github.com/rjNemo/rentease/internal/domains/booking"
|
||||||
)
|
)
|
||||||
|
|
||||||
templ BookingById(booking *booking.Booking, platforms []string) {
|
templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []string) {
|
||||||
@BaseLayout() {
|
@BaseLayout() {
|
||||||
<hgroup>
|
<hgroup>
|
||||||
<h1>Booking ID: VFNI#{ fmt.Sprintf("%04s", strconv.Itoa(booking.Id)) } </h1>
|
<h1>Booking ID VFNI#{ fmt.Sprintf("%04s", strconv.Itoa(booking.Id)) } </h1>
|
||||||
<h2>Manage a booking </h2>
|
<h2>Manage a booking </h2>
|
||||||
</hgroup>
|
</hgroup>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
|
|
@ -88,5 +88,41 @@ templ BookingById(booking *booking.Booking, platforms []string) {
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</figure>
|
</figure>
|
||||||
|
<button class="secondary" onclick="new_line_modal.showModal()">Add line </button>
|
||||||
|
<dialog id="new_line_modal">
|
||||||
|
<form method="post" action={ templ.SafeURL(fmt.Sprintf("/bookings/%d/items", booking.Id)) }>
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<a onclick="new_line_modal.close()" aria-label="Close" class="close"></a>
|
||||||
|
New line item
|
||||||
|
</header>
|
||||||
|
<label for="new-line-item">
|
||||||
|
Item
|
||||||
|
<select name="item" id="new-line-item">
|
||||||
|
for _, item := range items {
|
||||||
|
<option value={ item }>{ item } </option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label for="new-line-quantity">
|
||||||
|
Quantity
|
||||||
|
<input type="number" name="quantity" id="new-line-quantity"/>
|
||||||
|
</label>
|
||||||
|
<label for="new-line-price">
|
||||||
|
Price
|
||||||
|
<input type="number" name="price" id="new-line-price"/>
|
||||||
|
</label>
|
||||||
|
<label for="new-line-method">
|
||||||
|
Payment Method
|
||||||
|
<select name="method" id="new-line-method">
|
||||||
|
for _, paymentMethod := range paymentMethods {
|
||||||
|
<option value={ paymentMethod }>{ paymentMethod } </option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<button type="submit">Add</button>
|
||||||
|
</article>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/rjNemo/rentease/internal/domains/booking"
|
"github.com/rjNemo/rentease/internal/domains/booking"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BookingById(booking *booking.Booking, platforms []string) templ.Component {
|
func BookingById(booking *booking.Booking, items, platforms, paymentMethods []string) templ.Component {
|
||||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
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)
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||||
if !templ_7745c5c3_IsBuffer {
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
|
@ -40,7 +40,7 @@ func BookingById(booking *booking.Booking, platforms []string) templ.Component {
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Var3 := `Booking ID: VFNI#`
|
templ_7745c5c3_Var3 := `Booking ID VFNI#`
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
|
|
@ -367,7 +367,133 @@ func BookingById(booking *booking.Booking, platforms []string) templ.Component {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table></figure>")
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table></figure><button class=\"secondary\" onclick=\"new_line_modal.showModal()\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Var30 := `Add line `
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var30)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button> <dialog id=\"new_line_modal\"><form method=\"post\" action=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var31 templ.SafeURL = templ.SafeURL(fmt.Sprintf("/bookings/%d/items", booking.Id))
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var31)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><article><header><a onclick=\"new_line_modal.close()\" aria-label=\"Close\" class=\"close\"></a> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Var32 := `New line item`
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var32)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</header><label for=\"new-line-item\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Var33 := `Item`
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var33)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <select name=\"item\" id=\"new-line-item\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, item := range items {
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(item))
|
||||||
|
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_Var34 string = item
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <label for=\"new-line-quantity\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Var35 := `Quantity`
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var35)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <input type=\"number\" name=\"quantity\" id=\"new-line-quantity\"></label> <label for=\"new-line-price\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Var36 := `Price`
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var36)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <input type=\"number\" name=\"price\" id=\"new-line-price\"></label> <label for=\"new-line-method\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Var37 := `Payment Method`
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var37)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <select name=\"method\" id=\"new-line-method\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, paymentMethod := range paymentMethods {
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(paymentMethod))
|
||||||
|
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_Var38 string = paymentMethod
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <button type=\"submit\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Var39 := `Add`
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var39)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button></article></form></dialog>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue