Reorganization of backend + new routes

This commit is contained in:
cdricms
2025-01-29 18:09:41 +01:00
parent 7c66353e63
commit 8110172a38
67 changed files with 1124 additions and 400 deletions

View File

@@ -1 +1,39 @@
package roles
import (
"context"
"net/http"
"fr.latosa-escrima/core"
"fr.latosa-escrima/core/models"
)
func HandleRoles(w http.ResponseWriter, r *http.Request) {
var roles []models.Role
count, err := core.DB.NewSelect().
Model(&roles).
Relation("Permissions").
ScanAndCount(context.Background())
if count == 0 {
core.JSONError{
Status: core.Error,
Message: "No role found.",
}.Respond(w, http.StatusNotFound)
return
}
if err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusInternalServerError)
return
}
core.JSONSuccess{
Status: core.Success,
Message: "Roles found.",
Data: roles,
}.Respond(w, http.StatusOK)
}