Implements API validator and uses it in user endpoint

This commit is contained in:
Dennis Schoepf 2024-04-30 20:03:37 +02:00
parent 932edb8da7
commit cfe335ea39
3 changed files with 45 additions and 3 deletions

View file

@ -27,6 +27,12 @@ func (h *Handler) createUser(c *fiber.Ctx) error {
return defaultUserError
}
validationErr := ValidateModel(user)
if validationErr != nil {
return validationErr
}
_, insertErr := h.db.Exec("INSERT INTO user (id, first_name, email) VALUES (?, ?, ?)", user.ID, user.FirstName, user.Email)
if insertErr != nil {