70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package log
|
|
|
|
import (
|
|
"fmt"
|
|
"jannex/log-manager/modules/loghandler"
|
|
"jannex/log-manager/modules/structs"
|
|
"jannex/log-manager/modules/utils"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func AddLog(c *fiber.Ctx) error {
|
|
var body structs.LogBody
|
|
|
|
if err := utils.BodyParserHelper(c, &body); err != nil {
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
loghandler.AddLog(body)
|
|
|
|
return c.SendStatus(fiber.StatusOK)
|
|
}
|
|
|
|
func GetLog(c *fiber.Ctx) error {
|
|
var params structs.GetLogParams
|
|
|
|
if err := utils.ParamsParserHelper(c, ¶ms); err != nil {
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
var query structs.GetLogQuery
|
|
|
|
if err := utils.QueryParserHelper(c, &query); err != nil {
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
fmt.Println("params", params, "query", query)
|
|
|
|
// no type specified
|
|
if params.Type == "" {
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
// no date specified -> return all available files
|
|
if query.D == "" {
|
|
availableLogs, err := loghandler.GetAvailableLogFiles(params.Type)
|
|
|
|
if err != nil {
|
|
return c.SendStatus(fiber.StatusUnprocessableEntity)
|
|
}
|
|
|
|
return c.JSON(availableLogs)
|
|
}
|
|
|
|
logs, err := loghandler.GetLogByDate(params.Type, query.D)
|
|
|
|
if err != nil {
|
|
return c.SendStatus(fiber.StatusUnprocessableEntity)
|
|
}
|
|
|
|
return c.JSON(logs)
|
|
|
|
}
|
|
|
|
func GetAvailableLogTypes(c *fiber.Ctx) error {
|
|
logTypes := loghandler.GetAvailableLogTypes()
|
|
|
|
return c.JSON(logTypes)
|
|
}
|