Adds a unique name rule

This commit is contained in:
Daniel Svitan 2025-04-13 17:58:05 +02:00
parent 50420bc0a5
commit 3c6d7e027a

View File

@ -237,12 +237,22 @@ func main() {
return c.JSON(http.StatusBadRequest, "missing field 'name'")
}
var target *Client = nil
for _, client := range clients {
if client.ID == id || client.Name == id.String() {
client.Name = name
client.UpdatedAt = time.Now()
return c.JSON(http.StatusOK, echo.Map{"message": "ok"})
target = client
}
if client.Name == name {
return c.JSON(http.StatusBadRequest, echo.Map{"message": "name already used"})
}
}
if target != nil {
target.Name = name
target.UpdatedAt = time.Now()
return c.JSON(http.StatusOK, echo.Map{"message": "ok"})
}
return c.JSON(http.StatusNotFound, echo.Map{"message": "not found"})