Skip to content

Commit

Permalink
vingo: card handlers to receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-dev committed Jul 18, 2024
1 parent db96f94 commit e403886
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions vingo/handlers/cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions vingo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e403886

Please sign in to comment.