fix: handle duplicate input
This commit is contained in:
parent
bd305f0edf
commit
3b2321d5db
@ -7,8 +7,8 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (sr *StaffRepository) GetStaffByEmail(email string) (*authdomain.LoginRepoResponse, error) {
|
||||
var staff authdomain.LoginRepoResponse
|
||||
func (sr *StaffRepository) GetStaffByEmail(email string) (*authdomain.Staff, error) {
|
||||
var staff authdomain.Staff
|
||||
|
||||
if email == "" {
|
||||
return nil, errors.New("email is empty")
|
||||
|
||||
@ -10,7 +10,7 @@ type StaffRepository struct {
|
||||
}
|
||||
|
||||
type StaffIntf interface {
|
||||
GetStaffByEmail(string) (*authdomain.LoginRepoResponse, error)
|
||||
GetStaffByEmail(string) (*authdomain.Staff, error)
|
||||
Create(*authdomain.Staff) (*authdomain.Staff, error)
|
||||
}
|
||||
|
||||
|
||||
@ -3,12 +3,12 @@ package userrepository
|
||||
import (
|
||||
"errors"
|
||||
|
||||
usermodel "github.com/ardeman/project-legalgo-go/database/user"
|
||||
authdomain "github.com/ardeman/project-legalgo-go/internal/domain/auth"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (ur *UserRepository) GetUserByEmail(email string) (*usermodel.User, error) {
|
||||
var user usermodel.User
|
||||
func (ur *UserRepository) GetUserByEmail(email string) (*authdomain.User, error) {
|
||||
var user authdomain.User
|
||||
|
||||
if email == "" {
|
||||
return nil, errors.New("email is empty")
|
||||
|
||||
@ -2,7 +2,6 @@ package userrepository
|
||||
|
||||
import (
|
||||
"github.com/ardeman/project-legalgo-go/database"
|
||||
usermodel "github.com/ardeman/project-legalgo-go/database/user"
|
||||
authdomain "github.com/ardeman/project-legalgo-go/internal/domain/auth"
|
||||
)
|
||||
|
||||
@ -11,7 +10,7 @@ type UserRepository struct {
|
||||
}
|
||||
|
||||
type UserIntf interface {
|
||||
GetUserByEmail(string) (*usermodel.User, error)
|
||||
GetUserByEmail(string) (*authdomain.User, error)
|
||||
CreateUser(*authdomain.User) (*authdomain.User, error)
|
||||
}
|
||||
|
||||
|
||||
@ -7,8 +7,8 @@ import (
|
||||
"github.com/ardeman/project-legalgo-go/internal/utilities/utils"
|
||||
)
|
||||
|
||||
func (sv *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
|
||||
user, err := sv.userRepo.GetUserByEmail(spec.Email)
|
||||
func (a *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
|
||||
user, err := a.userRepo.GetUserByEmail(spec.Email)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
|
||||
@ -9,6 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error) {
|
||||
_, err := a.staffRepo.GetStaffByEmail(spec.Email)
|
||||
if err == nil {
|
||||
return "", errors.New("this email address is already in use")
|
||||
}
|
||||
hashedPwd, err := HashPassword(spec.Password)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@ -9,6 +9,12 @@ import (
|
||||
)
|
||||
|
||||
func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error) {
|
||||
_, err := a.userRepo.GetUserByEmail(spec.Email)
|
||||
|
||||
if err == nil {
|
||||
return "", errors.New("this email address is already in use")
|
||||
}
|
||||
|
||||
subsId, err := a.subsRepo.Create(spec.SubscribePlanID)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user