From 869642fa4d59a6700e3adaa0aed3417447d5eca5 Mon Sep 17 00:00:00 2001 From: kalipso Date: Tue, 25 Mar 2025 20:47:05 +0100 Subject: [PATCH] format --- controllers/userController.go | 52 ++++++++++++++++------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/controllers/userController.go b/controllers/userController.go index 6ed3f58..05217bb 100644 --- a/controllers/userController.go +++ b/controllers/userController.go @@ -1,30 +1,28 @@ package controllers -import( +import ( "fmt" - "net/http" "math/rand" + "net/http" "github.com/gin-gonic/gin" "example.com/gin/test/models" "example.com/gin/test/repositories" "example.com/gin/test/services" -) +) - -type UserController struct {} +type UserController struct{} func NewUserController() UserController { return UserController{} } - func (uc *UserController) Register(c *gin.Context) { //Get the email/passwd off req body var body struct { - Name string - Email string + Name string + Email string Password string } @@ -53,11 +51,10 @@ func (uc *UserController) Register(c *gin.Context) { c.JSON(http.StatusOK, gin.H{}) } - func (uc *UserController) Login(c *gin.Context) { //Get the email/passwd off req body var body struct { - Email string + Email string Password string } @@ -83,7 +80,7 @@ func (uc *UserController) Login(c *gin.Context) { // send it back c.SetSameSite(http.SameSiteLaxMode) - c.SetCookie("Authorization", tokenString, 3600 * 24, "", "", false, true) + c.SetCookie("Authorization", tokenString, 3600*24, "", "", false, true) c.JSON(http.StatusOK, gin.H{}) } @@ -116,7 +113,6 @@ func (rc *UserController) LoginView(c *gin.Context) { c.HTML(http.StatusOK, "login.html", CreateSessionData(c, data)) } - func (rc *UserController) LoginHandler(c *gin.Context) { email := c.PostForm("email") password := c.PostForm("password") @@ -139,7 +135,7 @@ func (rc *UserController) LoginHandler(c *gin.Context) { // send it back //c.SetSameSite(http.SameSiteLaxMode) - c.SetCookie("Authorization", tokenString, 3600 * 24, "", "", false, true) + c.SetCookie("Authorization", tokenString, 3600*24, "", "", false, true) c.HTML(http.StatusOK, "login.html", CreateSessionData(c, gin.H{})) } @@ -147,9 +143,8 @@ func CreateSessionData(c *gin.Context, extra any) gin.H { _, exists := c.Get("user") return gin.H{ - "test": "HEllo World", "loggedIn": exists, - "data": extra, + "data": extra, } } @@ -162,7 +157,7 @@ func (rc *UserController) RegisterHandler(c *gin.Context) { if err != nil { data := gin.H{ - "error": "Registering Failed.", + "error": "Registering Failed.", "success": "", } @@ -171,7 +166,7 @@ func (rc *UserController) RegisterHandler(c *gin.Context) { } data := gin.H{ - "error": "", + "error": "", "success": "You successfully registered. Try logging in.", } @@ -180,7 +175,7 @@ func (rc *UserController) RegisterHandler(c *gin.Context) { func (rc *UserController) RegisterView(c *gin.Context) { data := gin.H{ - "error": "", + "error": "", "success": "", } @@ -191,7 +186,7 @@ func (rc *UserController) ResetView(c *gin.Context) { shopItems, _ := repositories.ShopItems.GetAll() data := gin.H{ - "title": "shopItem Page", + "title": "shopItem Page", "shopItems": shopItems, } @@ -202,7 +197,7 @@ func (rc *UserController) ResetHandler(c *gin.Context) { shopItems, _ := repositories.ShopItems.GetAll() data := gin.H{ - "title": "shopItem Page", + "title": "shopItem Page", "shopItems": shopItems, } @@ -214,7 +209,7 @@ func (rc *UserController) MainView(c *gin.Context) { fmt.Println(len(shopItems)) data := CreateSessionData(c, gin.H{ - "title": "shopItem Page", + "title": "shopItem Page", "shopItems": shopItems, }) @@ -227,8 +222,8 @@ type booking struct { Booked bool } -type calendarbooking struct{ - Time string +type calendarbooking struct { + Time string Bookings []booking } @@ -236,17 +231,16 @@ 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; + time := 6 for _ = range 18 { book := calendarbooking{ - Time: fmt.Sprintf("%d:00", time), + Time: fmt.Sprintf("%d:00", time), Bookings: []booking{}, } for _ = range amountShopItems { - book.Bookings = append(book.Bookings, booking{ Booked: rand.Float32() < 0.5 }) + book.Bookings = append(book.Bookings, booking{Booked: rand.Float32() < 0.5}) } time += 1 @@ -276,8 +270,8 @@ func (rc *UserController) CalendarView(c *gin.Context) { } data := CreateSessionData(c, gin.H{ - "title": "shopItem Page", - "bookings": bookings, + "title": "shopItem Page", + "bookings": bookings, "shopItemcount": len(bookings["head"].([]string)) + 1, })