mirror of
https://github.com/hazemKrimi/crimson-vault.git
synced 2026-05-01 18:20:27 +00:00
chore: add request validations
This commit is contained in:
+10
-2
@@ -11,13 +11,17 @@ import (
|
||||
)
|
||||
|
||||
func (api *API) CreateClientHandler(context echo.Context) error {
|
||||
var body models.CreateClientBody
|
||||
var body models.CreateClientRequestBody
|
||||
|
||||
if err := context.Bind(&body); err != nil {
|
||||
log.Println(fmt.Sprintf("Error creating Client: %v.", err))
|
||||
return context.String(http.StatusBadRequest, "Invalid JSON!")
|
||||
}
|
||||
|
||||
if err := context.Validate(body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := api.db.CreateClient(body)
|
||||
|
||||
log.Println(fmt.Sprintf("Client created with ID %d.", client.ID))
|
||||
@@ -71,13 +75,17 @@ func (api *API) UpdateClientHandler(context echo.Context) error {
|
||||
return context.String(http.StatusInternalServerError, "Unexpected error updating Client!")
|
||||
}
|
||||
|
||||
var body models.UpdateClientBody
|
||||
var body models.UpdateClientRequestBody
|
||||
|
||||
if err := context.Bind(&body); err != nil {
|
||||
log.Println(fmt.Sprintf("Error updating Client: %v.", err))
|
||||
return context.String(http.StatusBadRequest, "Invalid JSON!")
|
||||
}
|
||||
|
||||
if err := context.Validate(body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var client models.Client
|
||||
|
||||
if err := api.db.UpdateClient(id, body, &client); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user