Files
orbits/internal/api/routes_api.go
T
2026-04-22 15:26:59 +02:00

48 lines
990 B
Go

package api
import (
"eden-server/internal/database"
"log/slog"
"net/http"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func spawnApiRoutes(api *gin.RouterGroup /* env runtime.Environment,*/, db *gorm.DB) {
// prefix: api
// Display the information on what is going on at the moment
api.GET("/status", func(c *gin.Context) {
state, err := database.GetState(db)
if err != nil {
slog.Error("unable to determine state", "error", err)
c.JSON(http.StatusInternalServerError, RespObj{
Msg: ieMes,
})
return
}
c.JSON(http.StatusOK, RespObj{
Msg: okMes,
Data: state,
})
})
// define a route to check what is registered
api.GET("/available", func(c *gin.Context) {
files, err := database.GetFiles(db)
if err != nil {
slog.Error("failed to retrieve available files", "error", err)
c.JSON(http.StatusInternalServerError, RespObj{
Msg: ieMes,
})
return
}
c.JSON(http.StatusOK, RespObj{
Msg: okMes,
Data: files,
})
})
}