fix: return error when there is no subscribe plan found
This commit is contained in:
parent
55460653e3
commit
c02d8cda69
21
internal/accessor/subscribeplan/get_by_id.go
Normal file
21
internal/accessor/subscribeplan/get_by_id.go
Normal file
@ -0,0 +1,21 @@
|
||||
package subscribeplanrepository
|
||||
|
||||
import (
|
||||
"errors"
|
||||
subscribeplandomain "legalgo-BE-go/internal/domain/subscribe_plan"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (s *SubsPlan) GetByID(id string) (subscribeplandomain.SubscribePlan, error) {
|
||||
var subscribePlan subscribeplandomain.SubscribePlan
|
||||
|
||||
if err := s.DB.First(&subscribePlan, "id = ? ", id).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return subscribePlan, errors.New("subscribe plan not found")
|
||||
}
|
||||
return subscribePlan, err
|
||||
}
|
||||
|
||||
return subscribePlan, nil
|
||||
}
|
||||
@ -12,6 +12,7 @@ type SubsPlan struct {
|
||||
type SubsPlanIntf interface {
|
||||
Create(subscribeplandomain.SubscribePlanReq) error
|
||||
GetAll() ([]subscribeplandomain.SubscribePlan, error)
|
||||
GetByID(string) (subscribeplandomain.SubscribePlan, error)
|
||||
GetDefault() (subscribeplandomain.SubscribePlan, error)
|
||||
}
|
||||
|
||||
|
||||
@ -25,9 +25,14 @@ func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error)
|
||||
spec.SubscribePlanID = subsPlan.ID
|
||||
}
|
||||
|
||||
_, err = a.subsPlanRepo.GetByID(spec.SubscribePlanID)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
|
||||
subsId, err := a.subsRepo.Create(spec.SubscribePlanID)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
return "", err
|
||||
}
|
||||
|
||||
hashedPwd, err := HashPassword(spec.Password)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user