package repository import ( "context" "database/sql" "enaklo-pos-be/internal/common/mycontext" "enaklo-pos-be/internal/repository/brevo" "enaklo-pos-be/internal/repository/license" "enaklo-pos-be/internal/repository/linkqu" mdtrns "enaklo-pos-be/internal/repository/midtrans" "enaklo-pos-be/internal/repository/orders" "enaklo-pos-be/internal/repository/oss" "enaklo-pos-be/internal/repository/partners" "enaklo-pos-be/internal/repository/payment" pg "enaklo-pos-be/internal/repository/payment_gateway" "enaklo-pos-be/internal/repository/products" "enaklo-pos-be/internal/repository/sites" transactions "enaklo-pos-be/internal/repository/transaction" "enaklo-pos-be/internal/repository/users" repository "enaklo-pos-be/internal/repository/wallet" "github.com/golang-jwt/jwt" "gorm.io/gorm" "enaklo-pos-be/config" "enaklo-pos-be/internal/entity" "enaklo-pos-be/internal/repository/auth" "enaklo-pos-be/internal/repository/crypto" ) type RepoManagerImpl struct { Crypto Crypto Auth Auth User User Product Product Order Order OSS OSSRepository Partner PartnerRepository Site SiteRepository Trx Trx Wallet WalletRepository Midtrans Midtrans Payment Payment EmailService EmailService License License Transaction TransactionRepository PG PaymentGateway LinkQu LinkQu OrderRepo OrderRepository InProgressOrderRepo InProgressOrderRepository CustomerRepo CustomerRepo ProductRepo ProductRepository TransactionRepo TransactionRepo MemberRepository MemberRepository PartnerSetting PartnerSettingsRepository UndianRepository UndianRepo CashierSeasionRepo CashierSessionRepository CategoryRepository CategoryRepository } func NewRepoManagerImpl(db *gorm.DB, cfg *config.Config) *RepoManagerImpl { return &RepoManagerImpl{ Crypto: crypto.NewCrypto(cfg.Auth()), Auth: auth.NewAuthRepository(db), User: users.NewUserRepository(db), Product: products.NewProductRepository(db), Order: orders.NewOrderRepository(db), OSS: oss.NewOssRepositoryImpl(cfg.OSSConfig), Partner: partners.NewPartnerRepository(db), Site: sites.NewSiteRepository(db), Trx: NewTransactionManager(db), Wallet: repository.NewWalletRepository(db), Midtrans: mdtrns.New(&cfg.Midtrans), Payment: payment.NewPaymentRepository(db), EmailService: brevo.New(&cfg.Brevo), License: license.NewLicenseRepository(db), Transaction: transactions.NewTransactionRepository(db), PG: pg.NewPaymentGatewayRepo(&cfg.Midtrans, &cfg.LinkQu), LinkQu: linkqu.NewLinkQuService(&cfg.LinkQu), OrderRepo: NeworderRepository(db), CustomerRepo: NewCustomerRepository(db), ProductRepo: NewproductRepository(db), TransactionRepo: NewTransactionRepository(db), MemberRepository: NewMemberRepository(db), InProgressOrderRepo: NewInProgressOrderRepository(db), PartnerSetting: NewPartnerSettingsRepository(db), UndianRepository: NewUndianRepository(db), CashierSeasionRepo: NewCashierSessionRepository(db), CategoryRepository: NewCategoryRepository(db), } } type Auth interface { CheckExistsUserAccount(ctx context.Context, email string) (*entity.UserDB, error) CheckExistsUserAccountByID(ctx context.Context, userID int64) (*entity.UserDB, error) UpdatePassword(ctx context.Context, trx *gorm.DB, newHashedPassword string, userID int64, resetPassword bool) error } type Crypto interface { CompareHashAndPassword(hash string, password string) bool ValidateWT(tokenString string) (*jwt.Token, error) GenerateJWT(user *entity.User) (string, error) GenerateJWTReseetPassword(user *entity.User) (string, error) GenerateJWTOrder(order *entity.Order) (string, error) GenerateJWTOrderInquiry(inquiry *entity.OrderInquiry) (string, error) ValidateJWTOrderInquiry(tokenString string) (int64, string, error) ValidateJWTOrder(tokenString string) (int64, int64, error) ValidateResetPassword(tokenString string) (int64, error) ParseAndValidateJWT(token string) (*entity.JWTAuthClaims, error) GenerateJWTWithdraw(req *entity.WalletWithdrawRequest) (string, error) ValidateJWTWithdraw(tokenString string) (*entity.WalletWithdrawRequest, error) GenerateJWTCustomer(user *entity.Customer) (string, error) ParseAndValidateJWTCustomer(tokenString string) (*entity.JWTAuthClaimsCustomer, error) } type User interface { Create(ctx context.Context, user *entity.UserDB) (*entity.UserDB, error) CreateWithTx(ctx context.Context, tx *gorm.DB, user *entity.UserDB) (*entity.UserDB, error) GetAllUsers(ctx context.Context, req entity.UserSearch) (entity.UserList, int, error) GetAllCustomer(ctx context.Context, req entity.CustomerSearch) (entity.CustomerList, int, error) GetUserByID(ctx context.Context, id int64) (*entity.UserDB, error) GetPartnerAdmin(ctx context.Context, partnerID int64) (*entity.UserDB, error) GetUserByEmail(ctx context.Context, email string) (*entity.UserDB, error) UpdateUser(ctx context.Context, user *entity.UserDB) (*entity.UserDB, error) UpdateUserWithTx(ctx context.Context, tx *gorm.DB, user *entity.UserDB) (*entity.UserDB, error) CountUsersByRoleAndSiteOrPartner(ctx context.Context, roleID int, siteID *int64) (int, error) } type Studio interface { CreateStudio(ctx context.Context, studio *entity.StudioDB) (*entity.StudioDB, error) UpdateStudio(ctx context.Context, studio *entity.StudioDB) (*entity.StudioDB, error) GetStudioByID(ctx context.Context, id int64) (*entity.StudioDB, error) SearchStudios(ctx context.Context, req entity.StudioSearch) (entity.StudioList, int, error) } type Product interface { CreateProduct(ctx context.Context, product *entity.ProductDB) (*entity.ProductDB, error) UpdateProduct(ctx context.Context, product *entity.ProductDB) (*entity.ProductDB, error) GetProductByID(ctx context.Context, id int64) (*entity.ProductDB, error) GetProductByPartnerIDAndSiteID(ctx context.Context, partnerID, siteID int64) (entity.ProductList, error) GetAllProducts(ctx context.Context, req entity.ProductSearch) (entity.ProductList, int, error) DeleteProduct(ctx context.Context, id int64) error GetProductsByIDs(ctx context.Context, ids []int64, partnerID int64) ([]*entity.ProductDB, error) GetProductsBySiteID(ctx context.Context, siteID int64) (entity.ProductList, error) } type Order interface { Create(ctx context.Context, order *entity.Order) (*entity.Order, error) FindByID(ctx context.Context, id int64) (*entity.Order, error) FindPrintDetailByID(ctx context.Context, id int64) (*entity.OrderPrintDetail, error) FindByQRCode(ctx context.Context, refID string) (*entity.Order, error) Update(ctx context.Context, order *entity.Order) (*entity.Order, error) SetOrderStatus(ctx context.Context, db *gorm.DB, orderID int64, status string) error GetAllHystoryOrders(ctx context.Context, req entity.OrderSearch) (entity.HistoryOrderList, int, error) SumAmount(ctx mycontext.Context, req entity.OrderSearch) (*entity.OrderDB, error) CountSoldOfTicket(ctx mycontext.Context, req entity.OrderSearch) (*entity.TicketSoldDB, error) GetDailySalesMetrics(ctx context.Context, req entity.OrderSearch) ([]entity.ProductDailySales, error) GetPaymentTypeDistribution(ctx context.Context, req entity.OrderSearch) ([]entity.PaymentTypeDistribution, error) } type OSSRepository interface { UploadFile(ctx context.Context, fileName string, fileContent []byte) (fileUrl string, err error) GetPublicURL(fileName string) string } type PartnerRepository interface { Create(ctx context.Context, branch *entity.PartnerDB) (*entity.PartnerDB, error) CreateWithTx(ctx context.Context, tx *gorm.DB, Partner *entity.PartnerDB) (*entity.PartnerDB, error) UpdateWithTx(ctx context.Context, tx *gorm.DB, Partner *entity.PartnerDB) (*entity.PartnerDB, error) Update(ctx context.Context, branch *entity.PartnerDB) (*entity.PartnerDB, error) GetByID(ctx context.Context, id int64) (*entity.PartnerDB, error) GetAll(ctx context.Context, req entity.PartnerSearch) (entity.PartnerList, int, error) Delete(ctx context.Context, id int64) error } type SiteRepository interface { Upsert(ctx context.Context, site *entity.Site) (*entity.Site, error) Create(ctx context.Context, branch *entity.SiteDB) (*entity.SiteDB, error) Update(ctx context.Context, branch *entity.SiteDB) (*entity.SiteDB, error) GetByID(ctx context.Context, id int64) (*entity.SiteDB, error) GetAll(ctx context.Context, req entity.SiteSearch) (entity.SiteList, int, error) Delete(ctx context.Context, id int64) error Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCountDB, error) GetNearestSites(ctx context.Context, latitude, longitude, radius float64) ([]entity.SiteProductInfo, error) SearchSites(ctx context.Context, search *entity.DiscoverySearch) ([]entity.SiteProductInfo, int64, error) } type WalletRepository interface { Create(ctx context.Context, tx *gorm.DB, wallet *entity.Wallet) (*entity.Wallet, error) Update(ctx context.Context, db *gorm.DB, wallet *entity.Wallet) (*entity.Wallet, error) GetByPartnerID(ctx context.Context, db *gorm.DB, partnerID int64) (*entity.Wallet, error) GetForUpdate(ctx context.Context, tx *gorm.DB, partnerID int64) (*entity.Wallet, error) } type Midtrans interface { CreatePayment(order entity.MidtransRequest) (*entity.MidtransResponse, error) CreateQrisPayment(order entity.MidtransRequest) (*entity.MidtransQrisResponse, error) } type Payment interface { Create(ctx context.Context, payment *entity.Payment) (*entity.Payment, error) Update(ctx context.Context, payment *entity.Payment) (*entity.Payment, error) UpdateWithTx(ctx context.Context, tx *gorm.DB, payment *entity.Payment) (*entity.Payment, error) FindByOrderAndPartnerID(ctx context.Context, orderID, partnerID int64) (*entity.Payment, error) FindByReferenceID(ctx context.Context, db *gorm.DB, referenceID string) (*entity.Payment, error) } type EmailService interface { SendEmailTransactional(ctx context.Context, param entity.SendEmailNotificationParam) error } type License interface { Create(ctx context.Context, license *entity.LicenseDB) (*entity.LicenseDB, error) Update(ctx context.Context, license *entity.LicenseDB) (*entity.LicenseDB, error) FindByID(ctx context.Context, id string) (*entity.LicenseDB, error) GetAll(ctx context.Context, limit, offset int, statusFilter string) ([]*entity.LicenseGetAll, int64, error) FindByPartnerIDMaxEndDate(ctx context.Context, partnerID *int64) (*entity.LicenseDB, error) } type TransactionRepository interface { FindByID(ctx context.Context, id string) (*entity.Transaction, error) Create(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error) GetTransactionList(ctx mycontext.Context, req entity.TransactionSearch) ([]*entity.TransactionList, int, error) Update(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error) } type LinkQu interface { CreateQrisPayment(linkQuRequest entity.LinkQuRequest) (*entity.LinkQuQRISResponse, error) CreatePaymentVA(linkQuRequest entity.LinkQuRequest) (*entity.LinkQuPaymentVAResponse, error) CheckPaymentStatus(partnerReff string) (*entity.LinkQuCheckStatusResponse, error) } type PaymentGateway interface { CreatePayment(request entity.PaymentRequest) (*entity.PaymentResponse, error) CreateQRISPayment(request entity.PaymentRequest) (*entity.PaymentResponse, error) CreatePaymentVA(request entity.PaymentRequest) (*entity.PaymentResponse, error) } type Trx interface { Begin(ctx context.Context, opts ...*sql.TxOptions) (*gorm.DB, error) Commit(session *gorm.DB) *gorm.DB Rollback(session *gorm.DB) *gorm.DB }