Skip to content

Commit

Permalink
vingo: settings endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-dev committed Jul 18, 2024
1 parent e403886 commit db59fd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
25 changes: 10 additions & 15 deletions vingo/handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@ import (
"github.com/gofiber/fiber/v2"
)

func SettingsUpdate(c *fiber.Ctx) error {
user := getUserFromStore(c)

scan_in_out := c.FormValue("scan_in_out")
leaderboard := c.FormValue("leaderboard")
public := c.FormValue("public")
type Settings struct{}

if scan_in_out == "" || leaderboard == "" || public == "" {
return c.Status(400).SendString("Missing fields")
}
func (Settings) Update(c *fiber.Ctx) error {
user := getUserFromStore(c)

settings := database.Settings{
ScanInOut: scan_in_out == "on",
Leaderboard: leaderboard == "on",
Public: public == "on",
settings := database.Settings{}
err := c.BodyParser(&settings)
if err != nil {
logger.Println(err)
return c.Status(400).SendString("Invalid payload")
}

sess, _ := store.Get(c)
Expand All @@ -29,10 +24,10 @@ func SettingsUpdate(c *fiber.Ctx) error {
sess.Set(STORE_USER, &user)
sess.Save()

return c.Redirect("/settings")
return c.SendStatus(200)
}

func Settings(c *fiber.Ctx) error {
func (Settings) Get(c *fiber.Ctx) error {
user := getUserFromStore(c)
return c.JSON(user.Settings)
}
5 changes: 4 additions & 1 deletion vingo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ func main() {
api.Get("/user", handlers.User)
api.Get("/leaderboard", handlers.Leaderboard)
api.Get("/scans", handlers.Scans)

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)

api.Get("/settings", handlers.Settings{}.Get)
api.Patch("/settings", handlers.Settings{}.Update)

admin := api.Group("/admin", handlers.IsAdmin)
{
Expand Down

0 comments on commit db59fd5

Please sign in to comment.