246 lines
12 KiB
Go
Raw Normal View History

2023-10-08 15:59:42 +07:00
package repository
import (
"context"
2024-06-03 14:40:50 +07:00
"database/sql"
2025-03-04 20:36:17 +07:00
"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"
2024-07-27 15:26:00 +07:00
2023-10-08 15:59:42 +07:00
"github.com/golang-jwt/jwt"
"gorm.io/gorm"
2025-03-04 20:36:17 +07:00
"enaklo-pos-be/config"
"enaklo-pos-be/internal/entity"
"enaklo-pos-be/internal/repository/auth"
"enaklo-pos-be/internal/repository/crypto"
2023-10-08 15:59:42 +07:00
)
type RepoManagerImpl struct {
2024-07-23 01:36:25 +07:00
Crypto Crypto
Auth Auth
User User
Product Product
Order Order
OSS OSSRepository
Partner PartnerRepository
Site SiteRepository
2025-06-27 13:01:39 +07:00
Trx Trx
2024-07-23 01:36:25 +07:00
Wallet WalletRepository
Midtrans Midtrans
Payment Payment
EmailService EmailService
2024-07-28 13:00:01 +07:00
License License
2024-07-30 23:39:55 +07:00
Transaction TransactionRepository
2024-10-15 11:52:34 +07:00
PG PaymentGateway
2024-10-27 19:48:10 +07:00
LinkQu LinkQu
2025-03-08 00:35:23 +07:00
2025-04-05 11:28:06 +08:00
OrderRepo OrderRepository
InProgressOrderRepo InProgressOrderRepository
CustomerRepo CustomerRepo
ProductRepo ProductRepository
TransactionRepo TransactionRepo
MemberRepository MemberRepository
2025-04-10 11:21:08 +07:00
PartnerSetting PartnerSettingsRepository
2025-06-06 14:48:09 +07:00
UndianRepository UndianRepo
2025-06-14 21:17:13 +07:00
CashierSeasionRepo CashierSessionRepository
CategoryRepository CategoryRepository
2023-10-08 15:59:42 +07:00
}
func NewRepoManagerImpl(db *gorm.DB, cfg *config.Config) *RepoManagerImpl {
return &RepoManagerImpl{
2024-07-23 01:36:25 +07:00
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),
2025-06-27 13:01:39 +07:00
Trx: NewTransactionManager(db),
2024-07-23 01:36:25 +07:00
Wallet: repository.NewWalletRepository(db),
Midtrans: mdtrns.New(&cfg.Midtrans),
Payment: payment.NewPaymentRepository(db),
EmailService: brevo.New(&cfg.Brevo),
2024-07-28 13:00:01 +07:00
License: license.NewLicenseRepository(db),
2024-07-30 23:39:55 +07:00
Transaction: transactions.NewTransactionRepository(db),
2024-10-15 11:52:34 +07:00
PG: pg.NewPaymentGatewayRepo(&cfg.Midtrans, &cfg.LinkQu),
2024-10-27 19:48:10 +07:00
LinkQu: linkqu.NewLinkQuService(&cfg.LinkQu),
2025-03-08 00:35:23 +07:00
2025-04-05 11:28:06 +08:00
OrderRepo: NeworderRepository(db),
CustomerRepo: NewCustomerRepository(db),
ProductRepo: NewproductRepository(db),
TransactionRepo: NewTransactionRepository(db),
MemberRepository: NewMemberRepository(db),
InProgressOrderRepo: NewInProgressOrderRepository(db),
2025-04-10 11:21:08 +07:00
PartnerSetting: NewPartnerSettingsRepository(db),
2025-06-06 14:48:09 +07:00
UndianRepository: NewUndianRepository(db),
2025-06-14 21:17:13 +07:00
CashierSeasionRepo: NewCashierSessionRepository(db),
CategoryRepository: NewCategoryRepository(db),
2023-10-08 15:59:42 +07:00
}
}
type Auth interface {
CheckExistsUserAccount(ctx context.Context, email string) (*entity.UserDB, error)
2024-07-23 01:36:25 +07:00
CheckExistsUserAccountByID(ctx context.Context, userID int64) (*entity.UserDB, error)
UpdatePassword(ctx context.Context, trx *gorm.DB, newHashedPassword string, userID int64, resetPassword bool) error
2023-10-08 15:59:42 +07:00
}
type Crypto interface {
CompareHashAndPassword(hash string, password string) bool
ValidateWT(tokenString string) (*jwt.Token, error)
GenerateJWT(user *entity.User) (string, error)
2024-07-23 01:36:25 +07:00
GenerateJWTReseetPassword(user *entity.User) (string, error)
2024-06-04 02:59:31 +07:00
GenerateJWTOrder(order *entity.Order) (string, error)
2025-03-08 00:35:23 +07:00
GenerateJWTOrderInquiry(inquiry *entity.OrderInquiry) (string, error)
ValidateJWTOrderInquiry(tokenString string) (int64, string, error)
2024-06-04 02:59:31 +07:00
ValidateJWTOrder(tokenString string) (int64, int64, error)
2024-07-23 01:36:25 +07:00
ValidateResetPassword(tokenString string) (int64, error)
2023-10-08 15:59:42 +07:00
ParseAndValidateJWT(token string) (*entity.JWTAuthClaims, error)
2024-07-31 23:02:15 +07:00
GenerateJWTWithdraw(req *entity.WalletWithdrawRequest) (string, error)
ValidateJWTWithdraw(tokenString string) (*entity.WalletWithdrawRequest, error)
2025-04-26 12:23:12 +07:00
GenerateJWTCustomer(user *entity.Customer) (string, error)
ParseAndValidateJWTCustomer(tokenString string) (*entity.JWTAuthClaimsCustomer, error)
2023-10-08 15:59:42 +07:00
}
type User interface {
Create(ctx context.Context, user *entity.UserDB) (*entity.UserDB, error)
2024-06-03 14:40:50 +07:00
CreateWithTx(ctx context.Context, tx *gorm.DB, user *entity.UserDB) (*entity.UserDB, error)
2023-10-08 15:59:42 +07:00
GetAllUsers(ctx context.Context, req entity.UserSearch) (entity.UserList, int, error)
2024-08-15 11:01:55 +07:00
GetAllCustomer(ctx context.Context, req entity.CustomerSearch) (entity.CustomerList, int, error)
2023-10-08 15:59:42 +07:00
GetUserByID(ctx context.Context, id int64) (*entity.UserDB, error)
2024-08-21 23:34:54 +07:00
GetPartnerAdmin(ctx context.Context, partnerID int64) (*entity.UserDB, error)
2023-10-08 15:59:42 +07:00
GetUserByEmail(ctx context.Context, email string) (*entity.UserDB, error)
UpdateUser(ctx context.Context, user *entity.UserDB) (*entity.UserDB, error)
2024-07-30 14:18:18 +07:00
UpdateUserWithTx(ctx context.Context, tx *gorm.DB, user *entity.UserDB) (*entity.UserDB, error)
2024-08-02 18:35:42 +07:00
CountUsersByRoleAndSiteOrPartner(ctx context.Context, roleID int, siteID *int64) (int, error)
2023-10-08 15:59:42 +07:00
}
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)
2024-06-05 00:24:53 +07:00
GetProductByPartnerIDAndSiteID(ctx context.Context, partnerID, siteID int64) (entity.ProductList, error)
2023-10-08 15:59:42 +07:00
GetAllProducts(ctx context.Context, req entity.ProductSearch) (entity.ProductList, int, error)
DeleteProduct(ctx context.Context, id int64) error
2024-06-04 02:59:31 +07:00
GetProductsByIDs(ctx context.Context, ids []int64, partnerID int64) ([]*entity.ProductDB, error)
2024-08-04 01:14:59 +07:00
GetProductsBySiteID(ctx context.Context, siteID int64) (entity.ProductList, error)
2023-10-08 15:59:42 +07:00
}
type Order interface {
2024-06-04 02:59:31 +07:00
Create(ctx context.Context, order *entity.Order) (*entity.Order, error)
FindByID(ctx context.Context, id int64) (*entity.Order, error)
2024-08-21 15:48:50 +07:00
FindPrintDetailByID(ctx context.Context, id int64) (*entity.OrderPrintDetail, error)
2024-08-13 23:09:05 +07:00
FindByQRCode(ctx context.Context, refID string) (*entity.Order, error)
2024-06-04 02:59:31 +07:00
Update(ctx context.Context, order *entity.Order) (*entity.Order, error)
2024-06-05 00:24:53 +07:00
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)
2024-08-02 02:27:57 +07:00
GetDailySalesMetrics(ctx context.Context, req entity.OrderSearch) ([]entity.ProductDailySales, error)
GetPaymentTypeDistribution(ctx context.Context, req entity.OrderSearch) ([]entity.PaymentTypeDistribution, error)
2023-10-08 15:59:42 +07:00
}
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)
2024-06-03 14:40:50 +07:00
CreateWithTx(ctx context.Context, tx *gorm.DB, Partner *entity.PartnerDB) (*entity.PartnerDB, error)
2024-07-30 02:48:31 +07:00
UpdateWithTx(ctx context.Context, tx *gorm.DB, Partner *entity.PartnerDB) (*entity.PartnerDB, error)
2023-10-08 15:59:42 +07:00
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
}
2024-06-03 14:40:50 +07:00
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
2024-07-27 15:26:00 +07:00
Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCountDB, error)
2024-08-03 20:01:25 +07:00
GetNearestSites(ctx context.Context, latitude, longitude, radius float64) ([]entity.SiteProductInfo, error)
SearchSites(ctx context.Context, search *entity.DiscoverySearch) ([]entity.SiteProductInfo, int64, error)
2024-06-03 14:40:50 +07:00
}
type WalletRepository interface {
Create(ctx context.Context, tx *gorm.DB, wallet *entity.Wallet) (*entity.Wallet, error)
2024-06-05 00:24:53 +07:00
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)
2024-07-31 23:02:15 +07:00
GetForUpdate(ctx context.Context, tx *gorm.DB, partnerID int64) (*entity.Wallet, error)
2024-06-03 14:40:50 +07:00
}
2024-06-04 02:59:31 +07:00
type Midtrans interface {
CreatePayment(order entity.MidtransRequest) (*entity.MidtransResponse, error)
2024-08-06 16:21:55 +07:00
CreateQrisPayment(order entity.MidtransRequest) (*entity.MidtransQrisResponse, error)
2024-06-04 02:59:31 +07:00
}
type Payment interface {
Create(ctx context.Context, payment *entity.Payment) (*entity.Payment, error)
Update(ctx context.Context, payment *entity.Payment) (*entity.Payment, error)
2024-06-05 00:24:53 +07:00
UpdateWithTx(ctx context.Context, tx *gorm.DB, payment *entity.Payment) (*entity.Payment, error)
2024-06-04 02:59:31 +07:00
FindByOrderAndPartnerID(ctx context.Context, orderID, partnerID int64) (*entity.Payment, error)
2024-06-05 00:24:53 +07:00
FindByReferenceID(ctx context.Context, db *gorm.DB, referenceID string) (*entity.Payment, error)
2024-06-04 02:59:31 +07:00
}
2024-07-23 01:36:25 +07:00
type EmailService interface {
SendEmailTransactional(ctx context.Context, param entity.SendEmailNotificationParam) error
}
2024-07-28 13:00:01 +07:00
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)
2024-07-30 00:55:20 +07:00
GetAll(ctx context.Context, limit, offset int, statusFilter string) ([]*entity.LicenseGetAll, int64, error)
2024-08-02 00:51:54 +07:00
FindByPartnerIDMaxEndDate(ctx context.Context, partnerID *int64) (*entity.LicenseDB, error)
2024-07-28 13:00:01 +07:00
}
2024-07-30 23:39:55 +07:00
type TransactionRepository interface {
2024-07-31 23:54:17 +07:00
FindByID(ctx context.Context, id string) (*entity.Transaction, error)
2024-07-31 23:02:15 +07:00
Create(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error)
2024-07-30 23:39:55 +07:00
GetTransactionList(ctx mycontext.Context, req entity.TransactionSearch) ([]*entity.TransactionList, int, error)
2024-07-31 23:54:17 +07:00
Update(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error)
2024-07-30 23:39:55 +07:00
}
2024-10-15 11:52:34 +07:00
2024-10-27 19:48:10 +07:00
type LinkQu interface {
2024-10-15 11:52:34 +07:00
CreateQrisPayment(linkQuRequest entity.LinkQuRequest) (*entity.LinkQuQRISResponse, error)
CreatePaymentVA(linkQuRequest entity.LinkQuRequest) (*entity.LinkQuPaymentVAResponse, error)
2024-10-27 19:48:10 +07:00
CheckPaymentStatus(partnerReff string) (*entity.LinkQuCheckStatusResponse, error)
2024-10-15 11:52:34 +07:00
}
type PaymentGateway interface {
CreatePayment(request entity.PaymentRequest) (*entity.PaymentResponse, error)
CreateQRISPayment(request entity.PaymentRequest) (*entity.PaymentResponse, error)
CreatePaymentVA(request entity.PaymentRequest) (*entity.PaymentResponse, error)
}
2025-06-27 13:01:39 +07:00
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
}