shopitems instead rooms

This commit is contained in:
2025-03-02 18:49:36 +01:00
parent 48491d0786
commit 6398429c92
11 changed files with 409 additions and 438 deletions

View File

@@ -3,6 +3,7 @@ package controllers
import(
"fmt"
"net/http"
"math/rand"
"github.com/gin-gonic/gin"
@@ -139,7 +140,7 @@ func (rc *UserController) LoginHandler(c *gin.Context) {
// send it back
//c.SetSameSite(http.SameSiteLaxMode)
c.SetCookie("Authorization", tokenString, 3600 * 24, "", "", false, true)
c.HTML(http.StatusPermanentRedirect, "index.html", CreateSessionData(c, gin.H{}))
c.HTML(http.StatusOK, "login.html", CreateSessionData(c, gin.H{}))
}
func CreateSessionData(c *gin.Context, extra any) gin.H {
@@ -187,30 +188,34 @@ func (rc *UserController) RegisterView(c *gin.Context) {
}
func (rc *UserController) ResetView(c *gin.Context) {
rooms, _ := repositories.Rooms.GetAll()
shopItems, _ := repositories.ShopItems.GetAll()
data := gin.H{
"title": "Room Page",
"rooms": rooms,
"title": "shopItem Page",
"shopItems": shopItems,
}
c.HTML(http.StatusOK, "passwordreset.html", data)
}
func (rc *UserController) ResetHandler(c *gin.Context) {
rooms, _ := repositories.Rooms.GetAll()
shopItems, _ := repositories.ShopItems.GetAll()
data := gin.H{
"title": "Room Page",
"rooms": rooms,
"title": "shopItem Page",
"shopItems": shopItems,
}
c.HTML(http.StatusOK, "passwordreset.html", data)
}
func (rc *UserController) MainView(c *gin.Context) {
shopItems, _ := repositories.ShopItems.GetAll()
fmt.Println(len(shopItems))
data := CreateSessionData(c, gin.H{
"title": "Room Page",
"title": "shopItem Page",
"shopItems": shopItems,
})
fmt.Println(data)
@@ -218,6 +223,69 @@ func (rc *UserController) MainView(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", data)
}
type booking struct {
Booked bool
}
type calendarbooking struct{
Time string
Bookings []booking
}
func (rc *UserController) CalendarView(c *gin.Context) {
shopItems, _ := repositories.ShopItems.GetAll()
fmt.Println(len(shopItems))
generateBookings := func(amountShopItems int) []calendarbooking {
var result []calendarbooking
time := 6;
for _ = range 18 {
book := calendarbooking{
Time: fmt.Sprintf("%d:00", time),
Bookings: []booking{},
}
for _ = range amountShopItems {
book.Bookings = append(book.Bookings, booking{ Booked: rand.Float32() < 0.5 })
}
time += 1
result = append(result, book)
}
return result
}
bookings := gin.H{
"head": []string{
"malobeo",
"hole of fame",
"BK",
"AZ Conni",
},
"bookings": generateBookings(4),
//"bookings": []calendarbooking{
// {
// Time: "10:00",
// Bookings: []booking{
// { Booked: true },
// { Booked: false },
// },
// },
//},
}
data := CreateSessionData(c, gin.H{
"title": "shopItem Page",
"bookings": bookings,
"shopItemcount": len(bookings["head"].([]string)) + 1,
})
fmt.Println(data)
c.HTML(http.StatusOK, "calendar.html", data)
}
func (rc *UserController) Logout(c *gin.Context) {
c.SetCookie("Authorization", "", -1, "", "", false, true)
c.HTML(http.StatusOK, "index.html", gin.H{})