Reorganization of backend + new routes
This commit is contained in:
32
backend/api/users/remove_role.go
Normal file
32
backend/api/users/remove_role.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"fr.latosa-escrima/core"
|
||||
"fr.latosa-escrima/core/models"
|
||||
)
|
||||
|
||||
func HandleRemoveRole(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.Background()
|
||||
user_id := r.PathValue("user_uuid")
|
||||
role_id := r.PathValue("role_id")
|
||||
|
||||
_, err := core.DB.NewDelete().Model((*models.UserToRole)(nil)).
|
||||
Where("user_id = ? AND role_id = ?", user_id, role_id).
|
||||
Exec(ctx)
|
||||
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "Role removed.",
|
||||
}.Respond(w, http.StatusOK)
|
||||
}
|
||||
Reference in New Issue
Block a user