diff --git a/server/main.go b/server/main.go index df9120b..8c47ba9 100644 --- a/server/main.go +++ b/server/main.go @@ -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"})