mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
add request booking feature
This commit is contained in:
parent
3078bac637
commit
1daa3eb7b8
6 changed files with 104 additions and 10 deletions
|
|
@ -23,6 +23,24 @@ type Booking struct {
|
||||||
PlatformFees float64 `gorm:"type:decimal(10,2)"`
|
PlatformFees float64 `gorm:"type:decimal(10,2)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b Booking) InvoiceNumber(hc *config.Host) string {
|
||||||
|
return fmt.Sprintf("%s%04s", hc.InvoicePrefix, strconv.Itoa(b.Id+hc.CustomerSeed))
|
||||||
|
}
|
||||||
|
|
||||||
|
type BookingRequest struct {
|
||||||
|
From time.Time
|
||||||
|
To time.Time
|
||||||
|
gorm.Model
|
||||||
|
CustomerName string
|
||||||
|
PhoneNumber *string // ensure at least one out of these is not null
|
||||||
|
Email *string
|
||||||
|
ItemType string
|
||||||
|
Message string
|
||||||
|
Status string
|
||||||
|
CustomerNumber int
|
||||||
|
BookingId int
|
||||||
|
}
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Item string
|
Item string
|
||||||
|
|
@ -33,7 +51,3 @@ type Item struct {
|
||||||
Quantity int
|
Quantity int
|
||||||
Price float64 `gorm:"type:decimal(10,2)"`
|
Price float64 `gorm:"type:decimal(10,2)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Booking) InvoiceNumber(hc *config.Host) string {
|
|
||||||
return fmt.Sprintf("%s%04s", hc.InvoicePrefix, strconv.Itoa(b.Id+hc.CustomerSeed))
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
u "github.com/rjNemo/underscore"
|
u "github.com/rjNemo/underscore"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"github.com/rjNemo/rentease/config"
|
"github.com/rjNemo/rentease/config"
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,14 @@ import (
|
||||||
|
|
||||||
func handleHomePage(hc *config.Host) echo.HandlerFunc {
|
func handleHomePage(hc *config.Host) echo.HandlerFunc {
|
||||||
return func(ctx echo.Context) error {
|
return func(ctx echo.Context) error {
|
||||||
return renderTempl(ctx, http.StatusOK, view.Index(&view.HostViewModel{
|
return renderTempl(ctx, http.StatusOK, view.Index(&view.HomePageViewModel{
|
||||||
Name: hc.Name,
|
Name: hc.Name,
|
||||||
Address: hc.Address,
|
Address: hc.Address,
|
||||||
ZipCode: hc.ZipCode,
|
ZipCode: hc.ZipCode,
|
||||||
City: hc.City,
|
City: hc.City,
|
||||||
PhoneNumber: hc.PhoneNumber,
|
PhoneNumber: hc.PhoneNumber,
|
||||||
Email: hc.Email,
|
Email: hc.Email,
|
||||||
|
Items: hc.Items,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,21 @@
|
||||||
package view
|
package view
|
||||||
|
|
||||||
type HostViewModel struct {
|
import (
|
||||||
|
"github.com/rjNemo/rentease/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HomePageViewModel struct {
|
||||||
Name string
|
Name string
|
||||||
Address string
|
Address string
|
||||||
ZipCode string
|
ZipCode string
|
||||||
City string
|
City string
|
||||||
PhoneNumber string
|
PhoneNumber string
|
||||||
Email string
|
Email string
|
||||||
|
Items []config.HostItem
|
||||||
}
|
}
|
||||||
|
|
||||||
templ Index(host *HostViewModel) {
|
templ Index(host *HomePageViewModel) {
|
||||||
@BaseLayout() {
|
@PublicLayout() {
|
||||||
<article>
|
<article>
|
||||||
<header>{ host.Name }</header>
|
<header>{ host.Name }</header>
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
|
|
@ -23,5 +28,48 @@ templ Index(host *HostViewModel) {
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
<section>
|
||||||
|
<article>
|
||||||
|
<form>
|
||||||
|
<fieldset class="grid">
|
||||||
|
<label for="item">
|
||||||
|
Logement
|
||||||
|
<select name="item" id="item" required>
|
||||||
|
for _,i := range host.Items {
|
||||||
|
<option value={ i.Name }>{ i.Name }</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label for="from">
|
||||||
|
Du
|
||||||
|
<input type="date" id="from" name="from" required/>
|
||||||
|
</label>
|
||||||
|
<label for="to">
|
||||||
|
Au
|
||||||
|
<input type="date" id="to" name="to" required/>
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset class="grid">
|
||||||
|
<label for="name">
|
||||||
|
Nom *
|
||||||
|
<input type="text" id="name" name="name" required/>
|
||||||
|
</label>
|
||||||
|
<label for="phone">
|
||||||
|
Telephone
|
||||||
|
<input type="tel" id="phone" name="phone"/>
|
||||||
|
</label>
|
||||||
|
<label for="email">
|
||||||
|
Email
|
||||||
|
<input type="email" id="email" name="email"/>
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
<label for="message">
|
||||||
|
Message
|
||||||
|
<textarea name="message" id="message"></textarea>
|
||||||
|
</label>
|
||||||
|
<button type="submit">Book</button>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
internal/view/public.templ
Normal file
32
internal/view/public.templ
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package view
|
||||||
|
|
||||||
|
templ PublicLayout() {
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" data-theme="light">
|
||||||
|
<head>
|
||||||
|
<title>RentEase | Your Property Management System</title>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<meta name="description" content="AI assistant to help you improve your management"/>
|
||||||
|
<link rel="icon" href="/static/img/favicon.svg"/>
|
||||||
|
<link rel="stylesheet" href="/static/css/pico.min.css"/>
|
||||||
|
<script src="/static/js/htmx.js" defer></script>
|
||||||
|
</head>
|
||||||
|
<body hx-boost="true">
|
||||||
|
<nav class="container-fluid">
|
||||||
|
<ul>
|
||||||
|
<li><a href="/"><b>🏨 RentEase </b> </a></li>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="/rooms">Rooms</a></li>
|
||||||
|
<li><a href="/services">Services</a></li>
|
||||||
|
<li><a href="/book" role="button">Book Now</a></li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<main class="container">
|
||||||
|
{ children... }
|
||||||
|
</main>
|
||||||
|
<footer class="container-fluid">🏨 RentEase © 2024</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
}
|
||||||
2
main.go
2
main.go
|
|
@ -34,7 +34,7 @@ func main() {
|
||||||
log.Fatalf("error connecting to the database %s\n", err)
|
log.Fatalf("error connecting to the database %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.AutoMigrate(&booking.Booking{}, &booking.Item{})
|
err = db.AutoMigrate(&booking.Booking{}, &booking.BookingRequest{}, &booking.Item{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error migrating the database %s\n", err)
|
log.Fatalf("error migrating the database %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue