170 lines
5.9 KiB
Go
170 lines
5.9 KiB
Go
package order
|
|
|
|
import (
|
|
"context"
|
|
"enaklo-pos-be/internal/common/mycontext"
|
|
"enaklo-pos-be/internal/entity"
|
|
)
|
|
|
|
type Repository interface {
|
|
Create(ctx mycontext.Context, order *entity.Order) (*entity.Order, error)
|
|
FindByID(ctx mycontext.Context, id int64) (*entity.Order, error)
|
|
CreateInquiry(ctx mycontext.Context, inquiry *entity.OrderInquiry) (*entity.OrderInquiry, error)
|
|
FindInquiryByID(ctx mycontext.Context, id string) (*entity.OrderInquiry, error)
|
|
UpdateInquiryStatus(ctx mycontext.Context, id string, status string) error
|
|
UpdateOrder(ctx mycontext.Context, id int64, status string, description string) error
|
|
GetOrderHistoryByPartnerID(ctx mycontext.Context, partnerID int64, req entity.SearchRequest) ([]*entity.Order, int64, error)
|
|
GetOrderPaymentMethodBreakdown(
|
|
ctx mycontext.Context,
|
|
partnerID int64,
|
|
req entity.SearchRequest,
|
|
) ([]entity.PaymentMethodBreakdown, error)
|
|
GetRevenueOverview(
|
|
ctx mycontext.Context,
|
|
req entity.RevenueOverviewRequest,
|
|
) ([]entity.RevenueOverviewItem, error)
|
|
GetSalesByCategory(
|
|
ctx mycontext.Context,
|
|
req entity.SalesByCategoryRequest,
|
|
) ([]entity.SalesByCategoryItem, error)
|
|
GetPopularProducts(
|
|
ctx mycontext.Context,
|
|
req entity.PopularProductsRequest,
|
|
) ([]entity.PopularProductItem, error)
|
|
GetOrderHistoryByUserID(ctx mycontext.Context, userID int64, req entity.SearchRequest) ([]*entity.Order, int64, error)
|
|
FindByIDAndPartnerID(ctx mycontext.Context, id int64, partnerID int64) (*entity.Order, error)
|
|
FindByIDAndCustomerID(ctx mycontext.Context, id int64, customerID int64) (*entity.Order, error)
|
|
}
|
|
|
|
type ProductService interface {
|
|
GetProductDetails(ctx mycontext.Context, productIDs []int64, partnerID int64) (*entity.ProductDetails, error)
|
|
GetProductsByIDs(ctx mycontext.Context, ids []int64, partnerID int64) ([]*entity.Product, error)
|
|
}
|
|
|
|
type CustomerService interface {
|
|
ResolveCustomer(ctx mycontext.Context, req *entity.CustomerResolutionRequest) (int64, error)
|
|
AddPoints(ctx mycontext.Context, customerID int64, points int, reference string) error
|
|
GetCustomer(ctx mycontext.Context, id int64) (*entity.Customer, error)
|
|
GetCustomerPoints(ctx mycontext.Context, customerID int64) (*entity.CustomerPoints, error)
|
|
}
|
|
|
|
type TransactionService interface {
|
|
Create(ctx mycontext.Context, transaction *entity.Transaction) (*entity.Transaction, error)
|
|
}
|
|
|
|
type CryptService interface {
|
|
GenerateJWTOrderInquiry(inquiry *entity.OrderInquiry) (string, error)
|
|
ValidateJWTOrderInquiry(tokenString string) (int64, string, error)
|
|
}
|
|
|
|
type NotificationService interface {
|
|
SendEmailTransactional(ctx context.Context, param entity.SendEmailNotificationParam) error
|
|
}
|
|
|
|
type Service interface {
|
|
CreateOrderInquiry(ctx mycontext.Context,
|
|
req *entity.OrderRequest) (*entity.OrderInquiryResponse, error)
|
|
ExecuteOrderInquiry(ctx mycontext.Context,
|
|
token string, paymentMethod, paymentProvider string, inProgressOrderID int64) (*entity.OrderResponse, error)
|
|
RefundRequest(ctx mycontext.Context, partnerID, orderID int64, reason string) error
|
|
GetOrderHistory(ctx mycontext.Context, partnerID int64, request entity.SearchRequest) ([]*entity.Order, int64, error)
|
|
CalculateOrderTotals(
|
|
ctx mycontext.Context,
|
|
items []entity.OrderItemRequest,
|
|
productDetails *entity.ProductDetails,
|
|
source string,
|
|
partnerID int64,
|
|
) (*entity.OrderCalculation, error)
|
|
ValidateOrderItems(ctx mycontext.Context, items []entity.OrderItemRequest) ([]int64, []entity.OrderItemRequest, error)
|
|
GetOrderPaymentAnalysis(
|
|
ctx mycontext.Context,
|
|
partnerID int64,
|
|
req entity.SearchRequest,
|
|
) (*entity.OrderPaymentAnalysis, error)
|
|
GetRevenueOverview(
|
|
ctx mycontext.Context,
|
|
partnerID int64,
|
|
year int,
|
|
granularity string,
|
|
status string,
|
|
) ([]entity.RevenueOverviewItem, error)
|
|
GetSalesByCategory(
|
|
ctx mycontext.Context,
|
|
partnerID int64,
|
|
period string,
|
|
status string,
|
|
) ([]entity.SalesByCategoryItem, error)
|
|
GetPopularProducts(
|
|
ctx mycontext.Context,
|
|
partnerID int64,
|
|
period string,
|
|
status string,
|
|
limit int,
|
|
sortBy string,
|
|
) ([]entity.PopularProductItem, error)
|
|
GetCustomerOrderHistory(ctx mycontext.Context, userID int64, request entity.SearchRequest) ([]*entity.Order, int64, error)
|
|
GetOrderByOrderAndCustomerID(ctx mycontext.Context, customerID int64, orderID int64) (*entity.Order, error)
|
|
}
|
|
|
|
type Config interface {
|
|
GetOrderFee(source string) float64
|
|
}
|
|
|
|
type PartnerSettings interface {
|
|
GetSettings(ctx mycontext.Context, partnerID int64) (*entity.PartnerSettings, error)
|
|
}
|
|
|
|
type InProgressOrderRepository interface {
|
|
GetListByPartnerID(ctx mycontext.Context, partnerID int64, limit, offset int) ([]*entity.InProgressOrder, error)
|
|
}
|
|
|
|
type VoucherUndianRepo interface {
|
|
GetActiveUndianEvents(ctx mycontext.Context) ([]*entity.UndianEventDB, error)
|
|
GetNextVoucherSequenceBatch(ctx mycontext.Context, count int) (int64, error)
|
|
CreateUndianVouchers(ctx mycontext.Context, vouchers []*entity.UndianVoucherDB) error
|
|
}
|
|
|
|
type CashierSvc interface {
|
|
GetOpenSession(ctx mycontext.Context, cashierID int64) (*entity.CashierSession, error)
|
|
}
|
|
|
|
type orderSvc struct {
|
|
repo Repository
|
|
product ProductService
|
|
customer CustomerService
|
|
transaction TransactionService
|
|
crypt CryptService
|
|
cfg Config
|
|
notification NotificationService
|
|
partnerSetting PartnerSettings
|
|
inprogressOrder InProgressOrderRepository
|
|
voucherUndianRepo VoucherUndianRepo
|
|
cashierSvc CashierSvc
|
|
}
|
|
|
|
func New(
|
|
repo Repository,
|
|
product ProductService,
|
|
customer CustomerService,
|
|
transaction TransactionService,
|
|
crypt CryptService,
|
|
cfg Config,
|
|
notification NotificationService,
|
|
partnerSetting PartnerSettings,
|
|
voucherUndianRepo VoucherUndianRepo,
|
|
cashierSvc CashierSvc,
|
|
) Service {
|
|
return &orderSvc{
|
|
repo: repo,
|
|
product: product,
|
|
customer: customer,
|
|
transaction: transaction,
|
|
crypt: crypt,
|
|
cfg: cfg,
|
|
notification: notification,
|
|
partnerSetting: partnerSetting,
|
|
voucherUndianRepo: voucherUndianRepo,
|
|
cashierSvc: cashierSvc,
|
|
}
|
|
}
|