diff --git a/controllers/GetSettingsController.go b/controllers/GetSettingsController.go new file mode 100755 index 0000000..bf36666 --- /dev/null +++ b/controllers/GetSettingsController.go @@ -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) +} diff --git a/routes/api.go b/routes/api.go index 1e399f9..f2b3994 100755 --- a/routes/api.go +++ b/routes/api.go @@ -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)