chores: refactor struct and structure project
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
package authsvc
|
||||
|
||||
import authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
import (
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
)
|
||||
|
||||
func (as *AuthSvc) GetStaffProfile(email string) (*authdomain.StaffProfile, error) {
|
||||
func (as *impl) GetStaffProfile(email string) (*staffdomain.StaffProfile, error) {
|
||||
staff, err := as.staffRepo.GetStaffByEmail(email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
profile := &authdomain.StaffProfile{
|
||||
profile := &staffdomain.StaffProfile{
|
||||
ID: staff.ID,
|
||||
Name: staff.Name,
|
||||
Email: staff.Email,
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package authsvc
|
||||
|
||||
import authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
import (
|
||||
userdomain "legalgo-BE-go/internal/domain/user"
|
||||
)
|
||||
|
||||
func (as *AuthSvc) GetUserProfile(email string) (*authdomain.UserProfile, error) {
|
||||
func (as *impl) GetUserProfile(email string) (*userdomain.UserProfile, error) {
|
||||
user, err := as.userRepo.GetUserProfile(email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -5,34 +5,35 @@ import (
|
||||
subscriberepository "legalgo-BE-go/internal/accessor/subscribe"
|
||||
subscribeplanrepository "legalgo-BE-go/internal/accessor/subscribeplan"
|
||||
userrepository "legalgo-BE-go/internal/accessor/user_repository"
|
||||
authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
userdomain "legalgo-BE-go/internal/domain/user"
|
||||
)
|
||||
|
||||
type AuthSvc struct {
|
||||
staffRepo staffrepository.StaffIntf
|
||||
type impl struct {
|
||||
staffRepo staffrepository.Staff
|
||||
userRepo userrepository.UserIntf
|
||||
subsRepo subscriberepository.SubsIntf
|
||||
subsPlanRepo subscribeplanrepository.SubsPlanIntf
|
||||
}
|
||||
|
||||
type AuthIntf interface {
|
||||
LoginAsStaff(authdomain.LoginReq) (string, error)
|
||||
RegisterUser(authdomain.RegisterUserReq) (string, error)
|
||||
GetUserProfile(string) (*authdomain.UserProfile, error)
|
||||
type Auth interface {
|
||||
LoginAsStaff(staffdomain.StaffLogin) (string, error)
|
||||
RegisterStaff(staffdomain.StaffRegister) (string, error)
|
||||
GetStaffProfile(string) (*staffdomain.StaffProfile, error)
|
||||
UpdateStaff(staffdomain.Staff) error
|
||||
|
||||
LoginAsUser(authdomain.LoginReq) (string, error)
|
||||
RegisterStaff(authdomain.RegisterStaffReq) (string, error)
|
||||
UpdateStaff(authdomain.Staff) error
|
||||
GetStaffProfile(string) (*authdomain.StaffProfile, error)
|
||||
LoginAsUser(userdomain.UserLogin) (string, error)
|
||||
RegisterUser(userdomain.UserRegister) (string, error)
|
||||
GetUserProfile(string) (*userdomain.UserProfile, error)
|
||||
}
|
||||
|
||||
func New(
|
||||
staffRepo staffrepository.StaffIntf,
|
||||
staffRepo staffrepository.Staff,
|
||||
userRepo userrepository.UserIntf,
|
||||
subsRepo subscriberepository.SubsIntf,
|
||||
subsPlanRepo subscribeplanrepository.SubsPlanIntf,
|
||||
) AuthIntf {
|
||||
return &AuthSvc{
|
||||
) Auth {
|
||||
return &impl{
|
||||
staffRepo: staffRepo,
|
||||
userRepo: userRepo,
|
||||
subsRepo: subsRepo,
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"errors"
|
||||
|
||||
authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (sv *AuthSvc) LoginAsStaff(spec authdomain.LoginReq) (string, error) {
|
||||
func (sv *impl) LoginAsStaff(spec staffdomain.StaffLogin) (string, error) {
|
||||
staff, err := sv.staffRepo.GetStaffByEmail(spec.Email)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
@@ -23,6 +24,7 @@ func (sv *AuthSvc) LoginAsStaff(spec authdomain.LoginReq) (string, error) {
|
||||
authToken := authdomain.AuthToken{
|
||||
Email: staff.Email,
|
||||
SessionID: uuid.NewString(),
|
||||
Role: "staff",
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(authToken)
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"errors"
|
||||
|
||||
authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
userdomain "legalgo-BE-go/internal/domain/user"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (a *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
|
||||
func (a *impl) LoginAsUser(spec userdomain.UserLogin) (string, error) {
|
||||
user, err := a.userRepo.GetUserByEmail(spec.Email)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
@@ -23,6 +24,7 @@ func (a *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
|
||||
authToken := authdomain.AuthToken{
|
||||
Email: user.Email,
|
||||
SessionID: uuid.NewString(),
|
||||
Role: "user",
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(authToken)
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"errors"
|
||||
|
||||
authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error) {
|
||||
func (a *impl) RegisterStaff(spec staffdomain.StaffRegister) (string, error) {
|
||||
_, err := a.staffRepo.GetStaffByEmail(spec.Email)
|
||||
if err == nil {
|
||||
return "", errors.New("this email address is already in use")
|
||||
@@ -19,7 +20,7 @@ func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error
|
||||
return "", err
|
||||
}
|
||||
|
||||
staff := authdomain.Staff{
|
||||
staff := staffdomain.Staff{
|
||||
ID: uuid.NewString(),
|
||||
Email: spec.Email,
|
||||
Password: hashedPwd,
|
||||
@@ -27,7 +28,7 @@ func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error
|
||||
ProfilePicture: spec.ProfilePicture,
|
||||
}
|
||||
|
||||
_, err = a.staffRepo.Create(&staff)
|
||||
err = a.staffRepo.Create(staff)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
@@ -35,6 +36,7 @@ func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error
|
||||
authToken := authdomain.AuthToken{
|
||||
Email: staff.Email,
|
||||
SessionID: uuid.NewString(),
|
||||
Role: "staff",
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(authToken)
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"errors"
|
||||
|
||||
authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
userdomain "legalgo-BE-go/internal/domain/user"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error) {
|
||||
func (a *impl) RegisterUser(spec userdomain.UserRegister) (string, error) {
|
||||
_, err := a.userRepo.GetUserByEmail(spec.Email)
|
||||
|
||||
if err == nil {
|
||||
@@ -40,7 +41,7 @@ func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error)
|
||||
return "", err
|
||||
}
|
||||
|
||||
user := authdomain.User{
|
||||
user := userdomain.User{
|
||||
ID: uuid.NewString(),
|
||||
Email: spec.Email,
|
||||
SubscribeID: subsId,
|
||||
@@ -48,7 +49,7 @@ func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error)
|
||||
Phone: spec.Phone,
|
||||
}
|
||||
|
||||
_, err = a.userRepo.CreateUser(&user)
|
||||
err = a.userRepo.CreateUser(user)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
@@ -56,6 +57,7 @@ func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error)
|
||||
authToken := authdomain.AuthToken{
|
||||
Email: user.Email,
|
||||
SessionID: uuid.NewString(),
|
||||
Role: "user",
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(authToken)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package authsvc
|
||||
|
||||
import authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
import (
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
)
|
||||
|
||||
func (as *AuthSvc) UpdateStaff(spec authdomain.Staff) error {
|
||||
func (as *impl) UpdateStaff(spec staffdomain.Staff) error {
|
||||
if _, err := as.staffRepo.GetStaffByID(spec.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package categorysvc
|
||||
|
||||
import categorydomain "legalgo-BE-go/internal/domain/category"
|
||||
import (
|
||||
categorydomain "legalgo-BE-go/internal/domain/category"
|
||||
)
|
||||
|
||||
func (i *impl) GetAll() ([]categorydomain.Category, error) {
|
||||
return i.categoryRepo.GetAll()
|
||||
return i.categoryRepo.GetAllModel()
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package categorysvc
|
||||
|
||||
import (
|
||||
"legalgo-BE-go/database"
|
||||
)
|
||||
|
||||
func (i *impl) GetAllModel() ([]database.CategoryModel, error) {
|
||||
return i.categoryRepo.GetAllModel()
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package categorysvc
|
||||
|
||||
import (
|
||||
"legalgo-BE-go/database"
|
||||
categoryrepository "legalgo-BE-go/internal/accessor/category"
|
||||
categorydomain "legalgo-BE-go/internal/domain/category"
|
||||
)
|
||||
@@ -13,7 +12,7 @@ type impl struct {
|
||||
type Category interface {
|
||||
Create(categorydomain.CategoryReq) error
|
||||
GetAll() ([]categorydomain.Category, error)
|
||||
GetAllModel() ([]database.CategoryModel, error)
|
||||
Update(string, categorydomain.CategoryReq) error
|
||||
}
|
||||
|
||||
func New(
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package categorysvc
|
||||
|
||||
import (
|
||||
categorydomain "legalgo-BE-go/internal/domain/category"
|
||||
timeutils "legalgo-BE-go/internal/utilities/time_utils"
|
||||
)
|
||||
|
||||
func (i *impl) Update(categoryID string, spec categorydomain.CategoryReq) error {
|
||||
updateData := categorydomain.Category{
|
||||
ID: categoryID,
|
||||
Name: spec.Name,
|
||||
Code: spec.Code,
|
||||
UpdatedAt: timeutils.Now(),
|
||||
}
|
||||
|
||||
if err := i.categoryRepo.Update(updateData); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -17,7 +17,7 @@ func (i *impl) CreateModel(spec newsdomain.NewsReq, staffId string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
categories, err := i.categoryRepo.GetBulks(spec.Categories)
|
||||
categories, err := i.categoryRepo.GetByIDs(spec.Categories)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func (i *impl) CreateModel(spec newsdomain.NewsReq, staffId string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
newSpec := database.NewsModel{
|
||||
newSpec := database.News{
|
||||
ID: uuid.NewString(),
|
||||
Title: spec.Title,
|
||||
Content: spec.Content,
|
||||
|
||||
@@ -4,6 +4,6 @@ import (
|
||||
"legalgo-BE-go/database"
|
||||
)
|
||||
|
||||
func (i *impl) GetAllModel() ([]database.NewsModel, error) {
|
||||
func (i *impl) GetAllModel() ([]database.News, error) {
|
||||
return i.newsRepo.GetAllModel()
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type impl struct {
|
||||
|
||||
type News interface {
|
||||
GetAll() ([]newsdomain.News, error)
|
||||
GetAllModel() ([]database.NewsModel, error)
|
||||
GetAllModel() ([]database.News, error)
|
||||
Create(newsdomain.NewsReq, string) error
|
||||
CreateModel(newsdomain.NewsReq, string) error
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package subscribesvc
|
||||
|
||||
func (s *SubsSvc) Create(subsPlanId string) (string, error) {
|
||||
func (s *impl) Create(subsPlanId string) (string, error) {
|
||||
subsId, err := s.subsRepo.Create(subsPlanId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package subscribesvc
|
||||
|
||||
import subscriberepository "legalgo-BE-go/internal/accessor/subscribe"
|
||||
import (
|
||||
subscriberepository "legalgo-BE-go/internal/accessor/subscribe"
|
||||
userdomain "legalgo-BE-go/internal/domain/user"
|
||||
)
|
||||
|
||||
type SubsSvc struct {
|
||||
type impl struct {
|
||||
subsRepo subscriberepository.SubsIntf
|
||||
}
|
||||
|
||||
type SubsIntf interface {
|
||||
type Subscribe interface {
|
||||
Create(string) (string, error)
|
||||
Update(string, userdomain.UserSubsUpdate) error
|
||||
}
|
||||
|
||||
func New(subsRepo subscriberepository.SubsIntf) SubsIntf {
|
||||
return &SubsSvc{subsRepo}
|
||||
func New(subsRepo subscriberepository.SubsIntf) Subscribe {
|
||||
return &impl{subsRepo}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package subscribesvc
|
||||
|
||||
import (
|
||||
userdomain "legalgo-BE-go/internal/domain/user"
|
||||
)
|
||||
|
||||
func (i *impl) Update(id string, spec userdomain.UserSubsUpdate) error {
|
||||
return nil
|
||||
}
|
||||
@@ -2,6 +2,6 @@ package subscribeplansvc
|
||||
|
||||
import subscribeplandomain "legalgo-BE-go/internal/domain/subscribe_plan"
|
||||
|
||||
func (sb *SubsPlanSvc) CreatePlan(spec subscribeplandomain.SubscribePlanReq) error {
|
||||
func (sb *impl) CreatePlan(spec subscribeplandomain.SubscribePlanReq) error {
|
||||
return sb.subsAccs.Create(spec)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import (
|
||||
subscribeplandomain "legalgo-BE-go/internal/domain/subscribe_plan"
|
||||
)
|
||||
|
||||
func (s *SubsPlanSvc) GetAllPlan() ([]subscribeplandomain.SubscribePlan, error) {
|
||||
func (s *impl) GetAllPlan() ([]subscribeplandomain.SubscribePlan, error) {
|
||||
return s.subsAccs.GetAll()
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ import (
|
||||
subscribeplandomain "legalgo-BE-go/internal/domain/subscribe_plan"
|
||||
)
|
||||
|
||||
type SubsPlanSvc struct {
|
||||
type impl struct {
|
||||
subsAccs subscribeplanrepository.SubsPlanIntf
|
||||
}
|
||||
|
||||
type SubsPlanIntf interface {
|
||||
type SubscribePlan interface {
|
||||
CreatePlan(subscribeplandomain.SubscribePlanReq) error
|
||||
GetAllPlan() ([]subscribeplandomain.SubscribePlan, error)
|
||||
}
|
||||
|
||||
func New(
|
||||
subsAccs subscribeplanrepository.SubsPlanIntf,
|
||||
) SubsPlanIntf {
|
||||
return &SubsPlanSvc{subsAccs}
|
||||
) SubscribePlan {
|
||||
return &impl{subsAccs}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import (
|
||||
"legalgo-BE-go/database"
|
||||
)
|
||||
|
||||
func (i *impl) GetAllModel() ([]database.TagModel, error) {
|
||||
func (i *impl) GetAllModel() ([]database.Tag, error) {
|
||||
return i.tagRepo.GetAllModel()
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ type impl struct {
|
||||
tagRepo tagrepository.TagAccessor
|
||||
}
|
||||
|
||||
type TagIntf interface {
|
||||
type Tag interface {
|
||||
Create(tagdomain.TagReq) error
|
||||
GetAll() ([]tagdomain.Tag, error)
|
||||
GetAllModel() ([]database.TagModel, error)
|
||||
GetAllModel() ([]database.Tag, error)
|
||||
}
|
||||
|
||||
func New(
|
||||
tagRepo tagrepository.TagAccessor,
|
||||
) TagIntf {
|
||||
) Tag {
|
||||
return &impl{tagRepo}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user