2025-06-27 13:01:39 +07:00

155 lines
7.1 KiB
Go

package services
import (
"context"
"enaklo-pos-be/internal/common/mycontext"
"enaklo-pos-be/internal/services/balance"
service "enaklo-pos-be/internal/services/license"
"enaklo-pos-be/internal/services/member"
"enaklo-pos-be/internal/services/oss"
"enaklo-pos-be/internal/services/partner"
"enaklo-pos-be/internal/services/product"
site "enaklo-pos-be/internal/services/sites"
"enaklo-pos-be/internal/services/transaction"
"enaklo-pos-be/internal/services/users"
authSvc "enaklo-pos-be/internal/services/v2/auth"
"enaklo-pos-be/internal/services/v2/cashier_session"
category "enaklo-pos-be/internal/services/v2/categories"
customerSvc "enaklo-pos-be/internal/services/v2/customer"
"enaklo-pos-be/internal/services/v2/inprogress_order"
orderSvc "enaklo-pos-be/internal/services/v2/order"
"enaklo-pos-be/internal/services/v2/undian"
"enaklo-pos-be/internal/services/v2/partner_settings"
productSvc "enaklo-pos-be/internal/services/v2/product"
"gorm.io/gorm"
"enaklo-pos-be/config"
"enaklo-pos-be/internal/entity"
"enaklo-pos-be/internal/repository"
"enaklo-pos-be/internal/services/auth"
)
type ServiceManagerImpl struct {
AuthSvc Auth
UserSvc User
ProductSvc Product
OSSSvc OSSService
PartnerSvc Partner
SiteSvc Site
LicenseSvc License
Transaction Transaction
Balance Balance
OrderV2Svc orderSvc.Service
CustomerV2Svc customerSvc.Service
ProductV2Svc productSvc.Service
MemberRegistrationSvc member.RegistrationService
InProgressSvc inprogress_order.InProgressOrderService
AuthV2Svc authSvc.Service
UndianSvc undian.Service
CashierSvc cashier_session.Service
CategorySvc category.Service
}
func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl) *ServiceManagerImpl {
custSvcV2 := customerSvc.New(repo.CustomerRepo, repo.EmailService)
productSvcV2 := productSvc.New(repo.ProductRepo)
partnerSettings := partner_settings.NewPartnerSettingsService(repo.PartnerSetting)
cashierSvc := cashier_session.New(repo.CashierSeasionRepo)
orderService := orderSvc.New(repo.OrderRepo,
productSvcV2, custSvcV2, repo.TransactionRepo,
repo.Crypto, &cfg.Order, repo.EmailService, partnerSettings,
repo.UndianRepository, cashierSvc)
inprogressOrder := inprogress_order.NewInProgressOrderService(repo.OrderRepo, orderService, productSvcV2, repo.Trx)
categorySvc := category.New(repo.CategoryRepository)
return &ServiceManagerImpl{
AuthSvc: auth.New(repo.Auth, repo.Crypto, repo.User, repo.EmailService, cfg.Email, repo.Trx, repo.License),
UserSvc: users.NewUserService(repo.User),
ProductSvc: product.NewProductService(repo.Product),
OSSSvc: oss.NewOSSService(repo.OSS),
PartnerSvc: partner.NewPartnerService(
repo.Partner, users.NewUserService(repo.User), repo.Trx, repo.Wallet, repo.User),
SiteSvc: site.NewSiteService(repo.Site, repo.User),
LicenseSvc: service.NewLicenseService(repo.License),
Transaction: transaction.New(repo.Transaction, repo.Wallet, repo.Trx),
Balance: balance.NewBalanceService(repo.Wallet, repo.Trx, repo.Crypto, &cfg.Withdraw, repo.Transaction),
OrderV2Svc: orderSvc.New(repo.OrderRepo, productSvcV2, custSvcV2, repo.TransactionRepo, repo.Crypto, &cfg.Order, repo.EmailService, partnerSettings, repo.UndianRepository, cashierSvc),
MemberRegistrationSvc: member.NewMemberRegistrationService(repo.MemberRepository, repo.EmailService, custSvcV2, repo.Crypto),
CustomerV2Svc: custSvcV2,
InProgressSvc: inprogressOrder,
ProductV2Svc: productSvcV2,
AuthV2Svc: authSvc.New(repo.CustomerRepo, repo.Crypto),
UndianSvc: undian.New(repo.UndianRepository),
CashierSvc: cashierSvc,
CategorySvc: categorySvc,
}
}
type Auth interface {
AuthenticateUser(ctx context.Context, email, password string) (*entity.AuthenticateUser, error)
SendPasswordResetLink(ctx context.Context, email string) error
ResetPassword(ctx mycontext.Context, oldPassword, newPassword string) error
}
type User interface {
Create(ctx mycontext.Context, userReq *entity.User) (*entity.User, error)
CreateWithTx(ctx mycontext.Context, tx *gorm.DB, userReq *entity.User) (*entity.User, error)
GetAll(ctx mycontext.Context, search entity.UserSearch) ([]*entity.User, int, error)
GetAllCustomer(ctx mycontext.Context, search entity.CustomerSearch) ([]*entity.Customer, int, error)
Update(ctx mycontext.Context, id int64, userReq *entity.User) (*entity.User, error)
UpdateWithTx(ctx mycontext.Context, tx *gorm.DB, req *entity.User) (*entity.User, error)
GetByID(ctx mycontext.Context, id int64) (*entity.User, error)
Delete(ctx mycontext.Context, id int64) error
}
type Product interface {
Create(ctx mycontext.Context, productReq *entity.Product) (*entity.Product, error)
Update(ctx mycontext.Context, id int64, productReq *entity.Product) (*entity.Product, error)
GetByID(ctx context.Context, id int64) (*entity.Product, error)
GetAll(ctx context.Context, search entity.ProductSearch) ([]*entity.Product, int, error)
GetProductPOS(ctx context.Context, search entity.ProductPOS) ([]*entity.Product, error)
Delete(ctx mycontext.Context, id int64) error
}
type OSSService interface {
UploadFile(ctx context.Context, req *entity.UploadFileRequest) (*entity.UploadFileResponse, error)
}
type Partner interface {
Create(ctx mycontext.Context, branchReq *entity.CreatePartnerRequest) (*entity.Partner, error)
Update(ctx mycontext.Context, branchReq *entity.PartnerUpdate) (*entity.Partner, error)
GetByID(ctx context.Context, id int64) (*entity.Partner, error)
GetAll(ctx context.Context, search entity.PartnerSearch) ([]*entity.Partner, int, error)
Delete(ctx mycontext.Context, id int64) error
}
type Site interface {
Create(ctx mycontext.Context, branchReq *entity.Site) (*entity.Site, error)
Update(ctx mycontext.Context, id int64, branchReq *entity.Site) (*entity.Site, error)
GetByID(ctx context.Context, id int64) (*entity.Site, error)
GetAll(ctx context.Context, search entity.SiteSearch) ([]*entity.Site, int, error)
Delete(ctx mycontext.Context, id int64) error
Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCount, error)
}
type License interface {
Create(ctx mycontext.Context, licenseReq *entity.License) (*entity.License, error)
Update(ctx mycontext.Context, id string, licenseReq *entity.License) (*entity.License, error)
GetByID(ctx context.Context, id string) (*entity.License, error)
GetAll(ctx context.Context, limit, offset int, status string) ([]*entity.LicenseGetAll, int64, error)
}
type Transaction interface {
GetTransactionList(ctx mycontext.Context, req entity.TransactionSearch) ([]*entity.TransactionList, int, error)
Approval(ctx mycontext.Context, req *entity.TransactionApproval) error
}
type Balance interface {
GetByID(ctx context.Context, id int64) (*entity.Balance, error)
WithdrawInquiry(ctx context.Context, req *entity.BalanceWithdrawInquiry) (*entity.BalanceWithdrawInquiryResponse, error)
WithdrawExecute(ctx mycontext.Context, req *entity.WalletWithdrawRequest) (*entity.WalletWithdrawResponse, error)
}