Files
orbits/internal/server/api/routes/ctrlroute.go

33 lines
741 B
Go

package routes
import (
"log/slog"
"orbits-server/internal/server/api/assets"
"orbits-server/internal/server/service"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func RegisterCtrlRoutes(api *gin.RouterGroup, db *gorm.DB) {
ctrlService := service.NewControlService(db)
// define the control route on the api
// /api/control
ctrl := api.Group("/control")
// Display the information on what is going on at the moment
ctrl.GET("/command", func(c *gin.Context) {
command, err := ctrlService.ListLatestCommand()
if err != nil {
slog.Error("unable to determine state", "error", err)
assets.InternalErrorResponse(c)
return
}
assets.BasicResponse(c, command)
})
ctrl.PATCH("/command", func(c *gin.Context) {
})
}