refactor: move checking of users name to api layer

This commit is contained in:
Derrick Hammer 2024-02-17 08:45:06 -05:00
parent a546089378
commit c076d219d0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 7 additions and 9 deletions

View File

@ -109,6 +109,11 @@ func (a AccountAPI) register(jc jape.Context) {
return return
} }
if len(request.FirstName) == 0 || len(request.LastName) == 0 {
_ = jc.Error(account.NewAccountError(account.ErrKeyAccountCreationFailed, nil), http.StatusBadRequest)
return
}
user, err := a.accounts.CreateAccount(request.Email, request.Password) user, err := a.accounts.CreateAccount(request.Email, request.Password)
if err != nil { if err != nil {
_ = jc.Error(err, http.StatusUnauthorized) _ = jc.Error(err, http.StatusUnauthorized)

View File

@ -2,9 +2,10 @@ package models
import ( import (
"errors" "errors"
"time"
emailverifier "github.com/AfterShip/email-verifier" emailverifier "github.com/AfterShip/email-verifier"
"gorm.io/gorm" "gorm.io/gorm"
"time"
) )
type User struct { type User struct {
@ -26,14 +27,6 @@ type User struct {
} }
func (u *User) BeforeUpdate(tx *gorm.DB) error { func (u *User) BeforeUpdate(tx *gorm.DB) error {
if len(u.FirstName) == 0 {
return errors.New("first name is empty")
}
if len(u.LastName) == 0 {
return errors.New("last name is empty")
}
verify, err := getEmailVerfier().Verify(u.Email) verify, err := getEmailVerfier().Verify(u.Email)
if err != nil { if err != nil {