refactor: project name and set default plan for new user
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
func (s *SubsAccs) Create(subsPlanId string) (string, error) {
|
||||
spec := &subscribedomain.Subscribe{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
SubscribePlanID: subsPlanId,
|
||||
}
|
||||
|
||||
@@ -15,5 +15,5 @@ func (s *SubsAccs) Create(subsPlanId string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return spec.ID.String(), nil
|
||||
return spec.ID, nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
func (s *SubsPlan) Create(spec subscribeplandomain.SubscribePlanReq) error {
|
||||
data := &subscribeplandomain.SubscribePlan{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Code: spec.Code,
|
||||
Name: spec.Name,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package subscribeplanrepository
|
||||
|
||||
import (
|
||||
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *SubsPlan) GetDefault() (subscribeplandomain.SubscribePlan, error) {
|
||||
var subscribePlan subscribeplandomain.SubscribePlan
|
||||
|
||||
if err := s.DB.Where("code = ?", "basic").First(&subscribePlan).Error; err != nil {
|
||||
s.DB.Create(&subscribeplandomain.SubscribePlan{
|
||||
ID: uuid.NewString(),
|
||||
Code: "basic",
|
||||
Name: "Basic",
|
||||
})
|
||||
}
|
||||
|
||||
return subscribePlan, nil
|
||||
}
|
||||
@@ -12,6 +12,7 @@ type SubsPlan struct {
|
||||
type SubsPlanIntf interface {
|
||||
Create(subscribeplandomain.SubscribePlanReq) error
|
||||
GetAll() ([]subscribeplandomain.SubscribePlan, error)
|
||||
GetDefault() (subscribeplandomain.SubscribePlan, error)
|
||||
}
|
||||
|
||||
func New(
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package authdomain
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type LoginReq struct {
|
||||
Email string `json:"email" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
@@ -12,7 +10,7 @@ type AuthResponse struct {
|
||||
}
|
||||
|
||||
type LoginRepoResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
ID string `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package authdomain
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type RegisterUserReq struct {
|
||||
Email string `json:"email" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
@@ -10,11 +8,11 @@ type RegisterUserReq struct {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Phone string `json:"phone"`
|
||||
SubscribeID string `json:"subscribe_id"`
|
||||
ID string `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Phone string `json:"phone"`
|
||||
SubscribeID string `json:"subscribe_id"`
|
||||
}
|
||||
|
||||
type RegisterStaffReq struct {
|
||||
@@ -23,7 +21,7 @@ type RegisterStaffReq struct {
|
||||
}
|
||||
|
||||
type Staff struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
ID string `json:"id"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package subscribedomain
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type Subscribe struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
SubscribePlanID string `json:"subscribe_plan_id"`
|
||||
ID string `json:"id"`
|
||||
SubscribePlanID string `json:"subscribe_plan_id"`
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package subscribeplandomain
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type SubscribePlanReq struct {
|
||||
Code string `json:"code" validate:"required"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
}
|
||||
|
||||
type SubscribePlan struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
@@ -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