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