refactor: project name and set default plan for new user

This commit is contained in:
ericprd
2025-02-27 01:15:47 +08:00
parent 46472d01fe
commit 775a9def75
21 changed files with 123 additions and 66 deletions
+10 -6
View File
@@ -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,
}
}
+1 -1
View File
@@ -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,
}
+11 -6
View File
@@ -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,