refactor: project name and set default plan for new user
This commit is contained in:
@@ -3,14 +3,16 @@ package authsvc
|
||||
import (
|
||||
staffrepository "github.com/ardeman/project-legalgo-go/internal/accessor/staff"
|
||||
subscriberepository "github.com/ardeman/project-legalgo-go/internal/accessor/subscribe"
|
||||
subscribeplanrepository "github.com/ardeman/project-legalgo-go/internal/accessor/subscribeplan"
|
||||
userrepository "github.com/ardeman/project-legalgo-go/internal/accessor/user_repository"
|
||||
authdomain "github.com/ardeman/project-legalgo-go/internal/domain/auth"
|
||||
)
|
||||
|
||||
type AuthSvc struct {
|
||||
staffRepo staffrepository.StaffIntf
|
||||
userRepo userrepository.UserIntf
|
||||
subsRepo subscriberepository.SubsIntf
|
||||
staffRepo staffrepository.StaffIntf
|
||||
userRepo userrepository.UserIntf
|
||||
subsRepo subscriberepository.SubsIntf
|
||||
subsPlanRepo subscribeplanrepository.SubsPlanIntf
|
||||
}
|
||||
|
||||
type AuthIntf interface {
|
||||
@@ -24,10 +26,12 @@ func New(
|
||||
staffRepo staffrepository.StaffIntf,
|
||||
userRepo userrepository.UserIntf,
|
||||
subsRepo subscriberepository.SubsIntf,
|
||||
subsPlanRepo subscribeplanrepository.SubsPlanIntf,
|
||||
) AuthIntf {
|
||||
return &AuthSvc{
|
||||
staffRepo: staffRepo,
|
||||
userRepo: userRepo,
|
||||
subsRepo: subsRepo,
|
||||
staffRepo: staffRepo,
|
||||
userRepo: userRepo,
|
||||
subsRepo: subsRepo,
|
||||
subsPlanRepo: subsPlanRepo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error
|
||||
}
|
||||
|
||||
user := authdomain.Staff{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Email: spec.Email,
|
||||
Password: hashedPwd,
|
||||
}
|
||||
|
||||
@@ -15,13 +15,18 @@ func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error)
|
||||
return "", errors.New("this email address is already in use")
|
||||
}
|
||||
|
||||
var subsId string
|
||||
|
||||
if spec.SubscribePlanID != "" {
|
||||
subsId, err = a.subsRepo.Create(spec.SubscribePlanID)
|
||||
if spec.SubscribePlanID == "" {
|
||||
subsPlan, err := a.subsPlanRepo.GetDefault()
|
||||
if err != nil {
|
||||
return "", nil
|
||||
return "", err
|
||||
}
|
||||
|
||||
spec.SubscribePlanID = subsPlan.ID
|
||||
}
|
||||
|
||||
subsId, err := a.subsRepo.Create(spec.SubscribePlanID)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
hashedPwd, err := HashPassword(spec.Password)
|
||||
@@ -30,7 +35,7 @@ func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error)
|
||||
}
|
||||
|
||||
user := authdomain.User{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Email: spec.Email,
|
||||
SubscribeID: subsId,
|
||||
Password: hashedPwd,
|
||||
|
||||
Reference in New Issue
Block a user