diff --git a/vingo/handlers/cards.go b/vingo/handlers/cards.go index a1dc0e9..accd969 100644 --- a/vingo/handlers/cards.go +++ b/vingo/handlers/cards.go @@ -10,7 +10,9 @@ import ( var register_timeout = time.Minute -func StartCardRegister(c *fiber.Ctx) error { +type Cards struct{} + +func (Cards) StartRegister(c *fiber.Ctx) error { user := getUserFromStore(c) if time.Now().Before(registering_end) { @@ -27,7 +29,7 @@ func StartCardRegister(c *fiber.Ctx) error { return c.Status(200).JSON(map[string]bool{}) } -func Cards(c *fiber.Ctx) error { +func (Cards) Get(c *fiber.Ctx) error { user := getUserFromStore(c) cards, err := database.GetCardsAndStatsForUser(user.Id) if err != nil { @@ -38,7 +40,7 @@ func Cards(c *fiber.Ctx) error { return c.JSON(cards) } -func CardRegisterStatus(c *fiber.Ctx) error { +func (Cards) RegisterStatus(c *fiber.Ctx) error { user := getUserFromStore(c) register_ongoing := time.Now().Before(registering_end) is_current_user := registering_user == user.Id @@ -47,7 +49,7 @@ func CardRegisterStatus(c *fiber.Ctx) error { return c.JSON(map[string]interface{}{"registering": register_ongoing, "isCurrentUser": is_current_user, "success": registering_success, "timeRemaining": time_remaining, "timePercentage": time_percentage}) } -func CardNameUpdate(c *fiber.Ctx) error { +func (Cards) Update(c *fiber.Ctx) error { user := getUserFromStore(c) card_id, err := strconv.Atoi(c.Params("id")) if err != nil { diff --git a/vingo/main.go b/vingo/main.go index 73e5d8d..6e881f6 100644 --- a/vingo/main.go +++ b/vingo/main.go @@ -45,10 +45,10 @@ func main() { api.Get("/user", handlers.User) api.Get("/leaderboard", handlers.Leaderboard) api.Get("/scans", handlers.Scans) - api.Get("/cards", handlers.Cards) - api.Patch("/cards/:id", handlers.CardNameUpdate) - api.Get("/cards/register", handlers.CardRegisterStatus) - api.Post("/cards/register", handlers.StartCardRegister) + api.Get("/cards", handlers.Cards{}.Get) + api.Patch("/cards/:id", handlers.Cards{}.Update) + api.Get("/cards/register", handlers.Cards{}.RegisterStatus) + api.Post("/cards/register", handlers.Cards{}.StartRegister) api.Get("/settings", handlers.Settings) admin := api.Group("/admin", handlers.IsAdmin)