Locations added
This commit is contained in:
38
backend/api/locations/delete.go
Normal file
38
backend/api/locations/delete.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package locations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"fr.latosa-escrima/core"
|
||||
"fr.latosa-escrima/core/models"
|
||||
)
|
||||
|
||||
func HandleDelete(w http.ResponseWriter, r *http.Request) {
|
||||
var location models.Location
|
||||
if err := json.NewDecoder(r.Body).Decode(&location); err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := core.DB.
|
||||
NewDelete().
|
||||
Model(&location).
|
||||
WherePK().
|
||||
Exec(context.Background()); err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "Location deleted.",
|
||||
}.Respond(w, http.StatusOK)
|
||||
}
|
||||
Reference in New Issue
Block a user