42 lines
804 B
Go
42 lines
804 B
Go
package permissions
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"fr.latosa-escrima/core"
|
|
"fr.latosa-escrima/core/models"
|
|
)
|
|
|
|
func HandlePermission(w http.ResponseWriter, r *http.Request) {
|
|
id := r.PathValue("permission_id")
|
|
var permission models.Permission
|
|
count, err := core.DB.NewSelect().
|
|
Model(&permission).
|
|
Where("id = ?", id).
|
|
Limit(1).
|
|
ScanAndCount(context.Background())
|
|
|
|
if count == 0 {
|
|
core.JSONSuccess{
|
|
Status: core.Success,
|
|
Message: "Permission not 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: "Permission found.",
|
|
Data: permission,
|
|
}.Respond(w, http.StatusOK)
|
|
}
|