Reorganization of backend + new routes
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user