190 lines
9.2 KiB
Go
Raw Normal View History

2023-10-08 15:59:42 +07:00
package services
import (
"context"
2025-03-04 20:36:17 +07:00
"enaklo-pos-be/internal/common/mycontext"
"enaklo-pos-be/internal/services/balance"
"enaklo-pos-be/internal/services/discovery"
service "enaklo-pos-be/internal/services/license"
2025-03-15 15:51:18 +08:00
"enaklo-pos-be/internal/services/member"
2025-03-04 20:36:17 +07:00
"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/studio"
"enaklo-pos-be/internal/services/transaction"
"enaklo-pos-be/internal/services/users"
2025-04-26 12:23:12 +07:00
authSvc "enaklo-pos-be/internal/services/v2/auth"
2025-03-08 00:35:23 +07:00
customerSvc "enaklo-pos-be/internal/services/v2/customer"
2025-04-05 11:28:06 +08:00
"enaklo-pos-be/internal/services/v2/inprogress_order"
2025-03-08 00:35:23 +07:00
orderSvc "enaklo-pos-be/internal/services/v2/order"
2025-04-26 12:23:12 +07:00
2025-04-10 11:21:08 +07:00
"enaklo-pos-be/internal/services/v2/partner_settings"
2025-03-08 00:35:23 +07:00
productSvc "enaklo-pos-be/internal/services/v2/product"
2024-07-26 11:37:22 +07:00
2024-06-03 14:40:50 +07:00
"gorm.io/gorm"
2023-10-08 15:59:42 +07:00
2025-03-04 20:36:17 +07:00
"enaklo-pos-be/config"
"enaklo-pos-be/internal/entity"
"enaklo-pos-be/internal/repository"
"enaklo-pos-be/internal/services/auth"
"enaklo-pos-be/internal/services/event"
2023-10-08 15:59:42 +07:00
)
type ServiceManagerImpl struct {
2024-08-03 20:01:25 +07:00
AuthSvc Auth
EventSvc Event
UserSvc User
StudioSvc Studio
ProductSvc Product
OSSSvc OSSService
PartnerSvc Partner
SiteSvc Site
LicenseSvc License
Transaction Transaction
Balance Balance
DiscoverService DiscoverService
2025-03-08 00:35:23 +07:00
2025-03-15 15:51:18 +08:00
OrderV2Svc orderSvc.Service
CustomerV2Svc customerSvc.Service
ProductV2Svc productSvc.Service
MemberRegistrationSvc member.RegistrationService
2025-04-05 11:28:06 +08:00
InProgressSvc inprogress_order.InProgressOrderService
2025-04-26 12:23:12 +07:00
AuthV2Svc authSvc.Service
2023-10-08 15:59:42 +07:00
}
func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl) *ServiceManagerImpl {
2025-03-08 00:35:23 +07:00
2025-04-05 11:28:06 +08:00
custSvcV2 := customerSvc.New(repo.CustomerRepo, repo.EmailService)
2025-03-08 00:35:23 +07:00
productSvcV2 := productSvc.New(repo.ProductRepo)
2025-04-10 11:21:08 +07:00
partnerSettings := partner_settings.NewPartnerSettingsService(repo.PartnerSetting)
2025-03-08 00:35:23 +07:00
2025-04-10 11:21:08 +07:00
orderService := orderSvc.New(repo.OrderRepo, productSvcV2, custSvcV2, repo.TransactionRepo, repo.Crypto, &cfg.Order, repo.EmailService, partnerSettings)
inprogressOrder := inprogress_order.NewInProgressOrderService(repo.OrderRepo, orderService, productSvcV2)
2023-10-08 15:59:42 +07:00
return &ServiceManagerImpl{
2024-08-02 00:51:54 +07:00
AuthSvc: auth.New(repo.Auth, repo.Crypto, repo.User, repo.EmailService, cfg.Email, repo.Trx, repo.License),
2023-10-08 15:59:42 +07:00
EventSvc: event.NewEventService(repo.Event),
2024-08-28 00:36:26 +07:00
UserSvc: users.NewUserService(repo.User),
2023-10-08 15:59:42 +07:00
StudioSvc: studio.NewStudioService(repo.Studio),
ProductSvc: product.NewProductService(repo.Product),
2024-07-26 22:32:24 +07:00
OSSSvc: oss.NewOSSService(repo.OSS),
2024-06-03 14:40:50 +07:00
PartnerSvc: partner.NewPartnerService(
2024-08-28 00:36:26 +07:00
repo.Partner, users.NewUserService(repo.User), repo.Trx, repo.Wallet, repo.User),
2025-03-15 15:51:18 +08:00
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),
DiscoverService: discovery.NewDiscoveryService(repo.Site, cfg.Discovery, repo.Product),
2025-04-10 11:21:08 +07:00
OrderV2Svc: orderSvc.New(repo.OrderRepo, productSvcV2, custSvcV2, repo.TransactionRepo, repo.Crypto, &cfg.Order, repo.EmailService, partnerSettings),
2025-05-03 10:50:41 +07:00
MemberRegistrationSvc: member.NewMemberRegistrationService(repo.MemberRepository, repo.EmailService, custSvcV2, repo.Crypto),
2025-03-15 15:51:18 +08:00
CustomerV2Svc: custSvcV2,
2025-04-05 11:28:06 +08:00
InProgressSvc: inprogressOrder,
2025-04-26 12:23:12 +07:00
ProductV2Svc: productSvcV2,
AuthV2Svc: authSvc.New(repo.CustomerRepo, repo.Crypto),
2023-10-08 15:59:42 +07:00
}
}
type Auth interface {
AuthenticateUser(ctx context.Context, email, password string) (*entity.AuthenticateUser, error)
2024-07-23 01:36:25 +07:00
SendPasswordResetLink(ctx context.Context, email string) error
ResetPassword(ctx mycontext.Context, oldPassword, newPassword string) error
2023-10-08 15:59:42 +07:00
}
type Event interface {
Create(ctx context.Context, eventReq *entity.Event) (*entity.Event, error)
Update(ctx context.Context, id int64, eventReq *entity.Event) (*entity.Event, error)
GetByID(ctx context.Context, id int64) (*entity.Event, error)
GetAll(ctx context.Context, search entity.EventSearch) ([]*entity.Event, int, error)
Delete(ctx context.Context, id int64) error
}
type User interface {
Create(ctx mycontext.Context, userReq *entity.User) (*entity.User, error)
2024-06-03 14:40:50 +07:00
CreateWithTx(ctx mycontext.Context, tx *gorm.DB, userReq *entity.User) (*entity.User, error)
2023-10-08 15:59:42 +07:00
GetAll(ctx mycontext.Context, search entity.UserSearch) ([]*entity.User, int, error)
2024-08-15 11:01:55 +07:00
GetAllCustomer(ctx mycontext.Context, search entity.CustomerSearch) ([]*entity.Customer, int, error)
2023-10-08 15:59:42 +07:00
Update(ctx mycontext.Context, id int64, userReq *entity.User) (*entity.User, error)
2024-07-30 14:18:18 +07:00
UpdateWithTx(ctx mycontext.Context, tx *gorm.DB, req *entity.User) (*entity.User, error)
2023-10-08 15:59:42 +07:00
GetByID(ctx mycontext.Context, id int64) (*entity.User, error)
Delete(ctx mycontext.Context, id int64) error
}
type Studio interface {
Create(ctx mycontext.Context, studioReq *entity.Studio) (*entity.Studio, error)
Update(ctx mycontext.Context, id int64, studioReq *entity.Studio) (*entity.Studio, error)
GetByID(ctx context.Context, id int64) (*entity.Studio, error)
Search(ctx context.Context, search entity.StudioSearch) ([]*entity.Studio, int, 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)
2024-06-05 00:24:53 +07:00
GetProductPOS(ctx context.Context, search entity.ProductPOS) ([]*entity.Product, error)
2023-10-08 15:59:42 +07:00
Delete(ctx mycontext.Context, id int64) error
}
type Order interface {
2024-07-30 22:02:36 +07:00
CreateOrder(ctx mycontext.Context, req *entity.OrderRequest) (*entity.OrderResponse, error)
2024-08-13 23:09:05 +07:00
CheckInInquiry(ctx mycontext.Context, qrCode string, partnerID *int64) (*entity.CheckinResponse, error)
CheckInExecute(ctx mycontext.Context,
token string, partnerID *int64) (*entity.CheckinExecute, error)
2024-10-15 11:52:34 +07:00
Execute(ctx mycontext.Context, req *entity.OrderExecuteRequest) (*entity.ExecuteOrderResponse, error)
2024-06-05 00:24:53 +07:00
ProcessCallback(ctx context.Context, req *entity.CallbackRequest) error
GetAllHistoryOrders(ctx mycontext.Context, req entity.OrderSearch) ([]*entity.HistoryOrder, int, error)
CountSoldOfTicket(ctx mycontext.Context, req entity.OrderSearch) (*entity.TicketSold, error)
SumAmount(ctx mycontext.Context, req entity.OrderSearch) (*entity.Order, error)
2024-08-02 02:27:57 +07:00
GetDailySales(ctx mycontext.Context, req entity.OrderSearch) ([]entity.ProductDailySales, error)
GetPaymentDistribution(ctx mycontext.Context, req entity.OrderSearch) ([]entity.PaymentTypeDistribution, error)
2024-08-06 16:21:55 +07:00
GetByID(ctx mycontext.Context, id int64, referenceID string) (*entity.Order, error)
2024-08-21 15:48:50 +07:00
GetPrintDetail(ctx mycontext.Context, id int64) (*entity.OrderPrintDetail, error)
2024-10-27 19:48:10 +07:00
ProcessLinkQuCallback(ctx context.Context, req *entity.LinkQuCallback) error
2023-10-08 15:59:42 +07:00
}
type OSSService interface {
UploadFile(ctx context.Context, req *entity.UploadFileRequest) (*entity.UploadFileResponse, error)
}
type Partner interface {
2024-06-03 14:40:50 +07:00
Create(ctx mycontext.Context, branchReq *entity.CreatePartnerRequest) (*entity.Partner, error)
2024-07-30 14:18:18 +07:00
Update(ctx mycontext.Context, branchReq *entity.PartnerUpdate) (*entity.Partner, error)
2023-10-08 15:59:42 +07:00
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
}
2024-06-03 14:40:50 +07:00
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
2024-07-27 15:26:00 +07:00
Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCount, error)
2024-06-03 14:40:50 +07:00
}
2024-07-28 13:00:01 +07:00
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)
2024-07-30 00:55:20 +07:00
GetAll(ctx context.Context, limit, offset int, status string) ([]*entity.LicenseGetAll, int64, error)
2024-07-28 13:00:01 +07:00
}
2024-07-30 23:39:55 +07:00
type Transaction interface {
GetTransactionList(ctx mycontext.Context, req entity.TransactionSearch) ([]*entity.TransactionList, int, error)
2024-07-31 23:54:17 +07:00
Approval(ctx mycontext.Context, req *entity.TransactionApproval) error
2024-07-30 23:39:55 +07:00
}
2024-07-30 23:51:53 +07:00
type Balance interface {
GetByID(ctx context.Context, id int64) (*entity.Balance, error)
2024-07-31 23:02:15 +07:00
WithdrawInquiry(ctx context.Context, req *entity.BalanceWithdrawInquiry) (*entity.BalanceWithdrawInquiryResponse, error)
WithdrawExecute(ctx mycontext.Context, req *entity.WalletWithdrawRequest) (*entity.WalletWithdrawResponse, error)
2024-07-30 23:51:53 +07:00
}
2024-08-03 20:01:25 +07:00
type DiscoverService interface {
Home(ctx context.Context, search *entity.DiscoverySearch) (*entity.DiscoverySearchResp, error)
Search(ctx context.Context, search *entity.DiscoverySearch) (*entity.DiscoverySearchResp, int64, error)
2024-08-04 01:14:59 +07:00
GetByID(ctx context.Context, id int64) (*entity.Site, error)
GetProductsByID(ctx context.Context, id int64) ([]*entity.Product, error)
2024-08-03 20:01:25 +07:00
}