Skip to content

Commit

Permalink
implemented get settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirari04 committed Jan 15, 2024
1 parent 1dc178c commit f148c3a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions controllers/GetSettingsController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package controllers

import (
"ch/kirari04/videocms/inits"
"ch/kirari04/videocms/models"
"log"

"github.com/gofiber/fiber/v2"
)

func GetSettings(c *fiber.Ctx) error {
_, ok := c.Locals("UserID").(uint)
if !ok {
log.Println("Failed to catch user")
return c.SendStatus(fiber.StatusInternalServerError)
}

var setting models.Setting
if res := inits.DB.FirstOrCreate(&setting); res.Error != nil {
log.Fatalln("Failed to get settings", res.Error)
return c.SendStatus(fiber.StatusInternalServerError)
}
return c.Status(fiber.StatusOK).JSON(&setting)
}
1 change: 1 addition & 0 deletions routes/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func Api() {
protectedApi.Delete("/page", middlewares.IsAdmin, controllers.DeleteWebPage)

protectedApi.Get("/stats", middlewares.IsAdmin, controllers.GetSystemStats)
protectedApi.Get("/settings", middlewares.IsAdmin, controllers.GetSettings)

protectedApi.Post("/webhook", controllers.CreateWebhook)
protectedApi.Put("/webhook", controllers.UpdateWebhook)
Expand Down

0 comments on commit f148c3a

Please sign in to comment.