chore: remove common error package

This commit is contained in:
Steven
2023-06-20 16:01:13 +08:00
parent df4c09c15b
commit 20884e9370
11 changed files with 68 additions and 140 deletions

View File

@ -2,8 +2,7 @@ package api
import (
"fmt"
"github.com/boojack/shortify/common"
"net/mail"
)
type User struct {
@ -15,12 +14,11 @@ type User struct {
RowStatus RowStatus `json:"rowStatus"`
// Domain specific fields
Email string `json:"email"`
DisplayName string `json:"displayName"`
PasswordHash string `json:"-"`
OpenID string `json:"openId"`
Role Role `json:"role"`
UserSettingList []*UserSetting `json:"userSettingList"`
Email string `json:"email"`
DisplayName string `json:"displayName"`
PasswordHash string `json:"-"`
OpenID string `json:"openId"`
Role Role `json:"role"`
}
type UserCreate struct {
@ -36,7 +34,7 @@ func (create UserCreate) Validate() error {
if len(create.Email) < 3 {
return fmt.Errorf("email is too short, minimum length is 6")
}
if !common.ValidateEmail(create.Email) {
if !validateEmail(create.Email) {
return fmt.Errorf("invalid email format")
}
if len(create.Password) < 3 {
@ -77,3 +75,11 @@ type UserFind struct {
type UserDelete struct {
ID int
}
// validateEmail validates the email.
func validateEmail(email string) bool {
if _, err := mail.ParseAddress(email); err != nil {
return false
}
return true
}

View File

@ -2,8 +2,8 @@ package v1
import (
"fmt"
"net/mail"
"github.com/boojack/shortify/common"
"github.com/labstack/echo/v4"
)
@ -57,7 +57,7 @@ func (create UserCreate) Validate() error {
if len(create.Email) < 3 {
return fmt.Errorf("email is too short, minimum length is 6")
}
if !common.ValidateEmail(create.Email) {
if !validateEmail(create.Email) {
return fmt.Errorf("invalid email format")
}
if len(create.Password) < 3 {
@ -104,3 +104,11 @@ func (*APIV1Service) RegisterUserRoutes(g *echo.Group) {
return c.String(200, "GET /user")
})
}
// validateEmail validates the email.
func validateEmail(email string) bool {
if _, err := mail.ParseAddress(email); err != nil {
return false
}
return true
}