add request booking feature

This commit is contained in:
Ruidy 2024-03-10 10:45:30 +01:00
parent 3078bac637
commit 1daa3eb7b8
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
6 changed files with 104 additions and 10 deletions

View file

@ -23,6 +23,24 @@ type Booking struct {
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 {
gorm.Model
Item string
@ -33,7 +51,3 @@ type Item struct {
Quantity int
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))
}

View file

@ -6,7 +6,6 @@ import (
"time"
u "github.com/rjNemo/underscore"
"gorm.io/gorm"
"github.com/rjNemo/rentease/config"

View file

@ -11,13 +11,14 @@ import (
func handleHomePage(hc *config.Host) echo.HandlerFunc {
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,
Address: hc.Address,
ZipCode: hc.ZipCode,
City: hc.City,
PhoneNumber: hc.PhoneNumber,
Email: hc.Email,
Items: hc.Items,
}))
}
}

View file

@ -1,16 +1,21 @@
package view
type HostViewModel struct {
import (
"github.com/rjNemo/rentease/config"
)
type HomePageViewModel struct {
Name string
Address string
ZipCode string
City string
PhoneNumber string
Email string
Items []config.HostItem
}
templ Index(host *HostViewModel) {
@BaseLayout() {
templ Index(host *HomePageViewModel) {
@PublicLayout() {
<article>
<header>{ host.Name }</header>
<div class="grid">
@ -23,5 +28,48 @@ templ Index(host *HostViewModel) {
</ul>
</div>
</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>
}
}

View 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 &copy 2024</footer>
</body>
</html>
}

View file

@ -34,7 +34,7 @@ func main() {
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 {
log.Fatalf("error migrating the database %s\n", err)
}