Add refund order

This commit is contained in:
aditya.siregar
2025-06-14 21:17:13 +07:00
parent 58d3b32c40
commit ebb33186b8
42 changed files with 1152 additions and 2094 deletions
-168
View File
@@ -1,168 +0,0 @@
package discovery
import (
"context"
"enaklo-pos-be/config"
"errors"
"gorm.io/gorm"
"enaklo-pos-be/internal/entity"
"enaklo-pos-be/internal/repository"
)
const (
defaultLatitude = -6.2088
defaultLongitude = 106.8456
radius = 10000
)
type DiscoveryService struct {
repo repository.SiteRepository
cfg config.Discovery
product repository.Product
}
func NewDiscoveryService(repo repository.SiteRepository, cfg config.Discovery, product repository.Product) *DiscoveryService {
return &DiscoveryService{
repo: repo,
cfg: cfg,
product: product,
}
}
func (s *DiscoveryService) Home(ctx context.Context, search *entity.DiscoverySearch) (*entity.DiscoverySearchResp, error) {
if search.Lat == 0 || search.Long == 0 {
search.Lat = defaultLatitude
search.Long = defaultLongitude
}
siteProducts, err := s.repo.GetNearestSites(ctx, search.Lat, search.Long, radius)
if err != nil {
return nil, err
}
exploreDestinations := []entity.ExploreDestination{}
for _, exploreDestination := range s.cfg.ExploreDestinations {
exploreDestinations = append(exploreDestinations, entity.ExploreDestination{
Name: exploreDestination.Name,
ImageURL: exploreDestination.ImageURL,
})
}
exploreRegions := []entity.ExploreRegion{}
for _, exploreRegion := range s.cfg.ExploreRegions {
exploreRegions = append(exploreRegions, entity.ExploreRegion{
Name: exploreRegion.Name,
})
}
mustVisits := []entity.MustVisit{}
for _, siteProduct := range siteProducts {
if siteProduct.Status == "Active" {
mustVisits = append(mustVisits, entity.MustVisit{
Name: siteProduct.SiteName,
Price: siteProduct.ProductPrice,
Region: siteProduct.Region,
SiteID: siteProduct.SiteID,
ImageURL: siteProduct.Image,
})
}
}
response := &entity.DiscoverySearchResp{
ExploreRegions: exploreRegions,
ExploreDestinations: exploreDestinations,
MustVisit: mustVisits,
}
return response, nil
}
func (s *DiscoveryService) Search(ctx context.Context, search *entity.DiscoverySearch) (*entity.DiscoverySearchResp, int64, error) {
if search.Lat == 0 || search.Long == 0 {
search.Lat = defaultLatitude
search.Long = defaultLongitude
search.Radius = radius
}
search.Status = "Active"
siteProducts, total, err := s.repo.SearchSites(ctx, search)
if err != nil {
return nil, 0, err
}
exploreDestinations := []entity.ExploreDestination{}
for _, exploreDestination := range s.cfg.ExploreDestinations {
exploreDestinations = append(exploreDestinations, entity.ExploreDestination{
Name: exploreDestination.Name,
ImageURL: exploreDestination.ImageURL,
})
}
exploreRegions := []entity.ExploreRegion{}
for _, exploreRegion := range s.cfg.ExploreRegions {
exploreRegions = append(exploreRegions, entity.ExploreRegion{
Name: exploreRegion.Name,
})
}
mustVisits := []entity.MustVisit{}
for _, siteProduct := range siteProducts {
mustVisits = append(mustVisits, entity.MustVisit{
Name: siteProduct.SiteName,
Price: siteProduct.ProductPrice,
Region: siteProduct.Region,
SiteID: siteProduct.SiteID,
ImageURL: siteProduct.Image,
Regency: siteProduct.Regency,
})
}
response := &entity.DiscoverySearchResp{
ExploreRegions: exploreRegions,
ExploreDestinations: exploreDestinations,
MustVisit: mustVisits,
}
return response, total, nil
}
func (s *DiscoveryService) GetByID(ctx context.Context, id int64) (*entity.Site, error) {
site, err := s.repo.GetByID(ctx, id)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, err
}
if site.Status != "Active" {
return nil, nil
}
return site.ToSite(), nil
}
func (s *DiscoveryService) GetProductsByID(ctx context.Context, id int64) ([]*entity.Product, error) {
site, err := s.repo.GetByID(ctx, id)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, err
}
if site.Status == "Inactive" {
return nil, nil
}
product, err := s.product.GetProductsBySiteID(ctx, site.ID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, err
}
return product.ToProductList(), nil
}
-88
View File
@@ -1,88 +0,0 @@
package event
import (
"context"
"go.uber.org/zap"
"enaklo-pos-be/internal/common/logger"
"enaklo-pos-be/internal/entity"
"enaklo-pos-be/internal/repository"
)
type EventService struct {
repo repository.Event
}
func NewEventService(repo repository.Event) *EventService {
return &EventService{
repo: repo,
}
}
func (s *EventService) Create(ctx context.Context, eventReq *entity.Event) (*entity.Event, error) {
eventDB := eventReq.ToEventDB()
eventDB, err := s.repo.CreateEvent(ctx, eventDB)
if err != nil {
logger.ContextLogger(ctx).Error("error when create event", zap.Error(err))
return nil, err
}
return eventDB.ToEvent(), nil
}
func (s *EventService) Update(ctx context.Context, id int64, eventReq *entity.Event) (*entity.Event, error) {
existingEvent, err := s.repo.GetEventByID(ctx, id)
if err != nil {
return nil, err
}
existingEvent.ToUpdatedEvent(*eventReq)
updatedEventDB, err := s.repo.UpdateEvent(ctx, existingEvent.ToEventDB())
if err != nil {
logger.ContextLogger(ctx).Error("error when update event", zap.Error(err))
return nil, err
}
return updatedEventDB.ToEvent(), nil
}
func (s *EventService) GetByID(ctx context.Context, id int64) (*entity.Event, error) {
eventDB, err := s.repo.GetEventByID(ctx, id)
if err != nil {
logger.ContextLogger(ctx).Error("error when get event by id", zap.Error(err))
return nil, err
}
return eventDB.ToEvent(), nil
}
func (s *EventService) GetAll(ctx context.Context, search entity.EventSearch) ([]*entity.Event, int, error) {
events, total, err := s.repo.GetAllEvents(ctx, search.Name, search.Limit, search.Offset)
if err != nil {
logger.ContextLogger(ctx).Error("error when get all events", zap.Error(err))
return nil, 0, err
}
return events.ToEventList(), total, nil
}
func (s *EventService) Delete(ctx context.Context, id int64) error {
eventDB, err := s.repo.GetEventByID(ctx, id)
if err != nil {
logger.ContextLogger(ctx).Error("error when get event by id", zap.Error(err))
return err
}
eventDB.SetDeleted()
_, err = s.repo.UpdateEvent(ctx, eventDB)
if err != nil {
logger.ContextLogger(ctx).Error("error when update event", zap.Error(err))
return err
}
return nil
}
+22 -60
View File
@@ -4,17 +4,17 @@ import (
"context"
"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"
"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/studio"
"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"
@@ -29,22 +29,18 @@ import (
"enaklo-pos-be/internal/entity"
"enaklo-pos-be/internal/repository"
"enaklo-pos-be/internal/services/auth"
"enaklo-pos-be/internal/services/event"
)
type ServiceManagerImpl struct {
AuthSvc Auth
EventSvc Event
UserSvc User
StudioSvc Studio
ProductSvc Product
OSSSvc OSSService
PartnerSvc Partner
SiteSvc Site
LicenseSvc License
Transaction Transaction
Balance Balance
DiscoverService DiscoverService
AuthSvc Auth
UserSvc User
ProductSvc Product
OSSSvc OSSService
PartnerSvc Partner
SiteSvc Site
LicenseSvc License
Transaction Transaction
Balance Balance
OrderV2Svc orderSvc.Service
CustomerV2Svc customerSvc.Service
@@ -53,6 +49,8 @@ type ServiceManagerImpl struct {
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 {
@@ -60,14 +58,16 @@ func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl)
custSvcV2 := customerSvc.New(repo.CustomerRepo, repo.EmailService)
productSvcV2 := productSvc.New(repo.ProductRepo)
partnerSettings := partner_settings.NewPartnerSettingsService(repo.PartnerSetting)
orderService := orderSvc.New(repo.OrderRepo, productSvcV2, custSvcV2, repo.TransactionRepo, repo.Crypto, &cfg.Order, repo.EmailService, partnerSettings, repo.UndianRepository)
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)
categorySvc := category.New(repo.CategoryRepository)
return &ServiceManagerImpl{
AuthSvc: auth.New(repo.Auth, repo.Crypto, repo.User, repo.EmailService, cfg.Email, repo.Trx, repo.License),
EventSvc: event.NewEventService(repo.Event),
UserSvc: users.NewUserService(repo.User),
StudioSvc: studio.NewStudioService(repo.Studio),
ProductSvc: product.NewProductService(repo.Product),
OSSSvc: oss.NewOSSService(repo.OSS),
PartnerSvc: partner.NewPartnerService(
@@ -76,14 +76,15 @@ func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl)
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),
OrderV2Svc: orderSvc.New(repo.OrderRepo, productSvcV2, custSvcV2, repo.TransactionRepo, repo.Crypto, &cfg.Order, repo.EmailService, partnerSettings, repo.UndianRepository),
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,
}
}
@@ -93,14 +94,6 @@ type Auth interface {
ResetPassword(ctx mycontext.Context, oldPassword, newPassword string) error
}
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)
CreateWithTx(ctx mycontext.Context, tx *gorm.DB, userReq *entity.User) (*entity.User, error)
@@ -112,13 +105,6 @@ type User interface {
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)
@@ -128,23 +114,6 @@ type Product interface {
Delete(ctx mycontext.Context, id int64) error
}
type Order interface {
CreateOrder(ctx mycontext.Context, req *entity.OrderRequest) (*entity.OrderResponse, error)
CheckInInquiry(ctx mycontext.Context, qrCode string, partnerID *int64) (*entity.CheckinResponse, error)
CheckInExecute(ctx mycontext.Context,
token string, partnerID *int64) (*entity.CheckinExecute, error)
Execute(ctx mycontext.Context, req *entity.OrderExecuteRequest) (*entity.ExecuteOrderResponse, error)
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)
GetDailySales(ctx mycontext.Context, req entity.OrderSearch) ([]entity.ProductDailySales, error)
GetPaymentDistribution(ctx mycontext.Context, req entity.OrderSearch) ([]entity.PaymentTypeDistribution, error)
GetByID(ctx mycontext.Context, id int64, referenceID string) (*entity.Order, error)
GetPrintDetail(ctx mycontext.Context, id int64) (*entity.OrderPrintDetail, error)
ProcessLinkQuCallback(ctx context.Context, req *entity.LinkQuCallback) error
}
type OSSService interface {
UploadFile(ctx context.Context, req *entity.UploadFileRequest) (*entity.UploadFileResponse, error)
}
@@ -183,10 +152,3 @@ type Balance interface {
WithdrawInquiry(ctx context.Context, req *entity.BalanceWithdrawInquiry) (*entity.BalanceWithdrawInquiryResponse, error)
WithdrawExecute(ctx mycontext.Context, req *entity.WalletWithdrawRequest) (*entity.WalletWithdrawResponse, error)
}
type DiscoverService interface {
Home(ctx context.Context, search *entity.DiscoverySearch) (*entity.DiscoverySearchResp, error)
Search(ctx context.Context, search *entity.DiscoverySearch) (*entity.DiscoverySearchResp, int64, error)
GetByID(ctx context.Context, id int64) (*entity.Site, error)
GetProductsByID(ctx context.Context, id int64) ([]*entity.Product, error)
}
-70
View File
@@ -1,70 +0,0 @@
package studio
import (
"context"
"enaklo-pos-be/internal/common/logger"
"enaklo-pos-be/internal/common/mycontext"
"enaklo-pos-be/internal/entity"
"enaklo-pos-be/internal/repository"
"go.uber.org/zap"
)
type StudioService struct {
repo repository.Studio
}
func NewStudioService(repo repository.Studio) *StudioService {
return &StudioService{
repo: repo,
}
}
func (s *StudioService) Create(ctx mycontext.Context, studioReq *entity.Studio) (*entity.Studio, error) {
newStudioDB := studioReq.NewStudiosDB()
newStudioDB.CreatedBy = ctx.RequestedBy()
newStudioDB, err := s.repo.CreateStudio(ctx, newStudioDB)
if err != nil {
logger.ContextLogger(ctx).Error("error when creating studio", zap.Error(err))
return nil, err
}
return newStudioDB.ToStudio(), nil
}
func (s *StudioService) Update(ctx mycontext.Context, id int64, studioReq *entity.Studio) (*entity.Studio, error) {
existingStudio, err := s.repo.GetStudioByID(ctx, id)
if err != nil {
return nil, err
}
existingStudio.ToUpdatedStudio(ctx.RequestedBy(), *studioReq)
updatedStudioDB, err := s.repo.UpdateStudio(ctx, existingStudio.ToStudioDB())
if err != nil {
logger.ContextLogger(ctx).Error("error when updating studio", zap.Error(err))
return nil, err
}
return updatedStudioDB.ToStudio(), nil
}
func (s *StudioService) GetByID(ctx context.Context, id int64) (*entity.Studio, error) {
studioDB, err := s.repo.GetStudioByID(ctx, id)
if err != nil {
logger.ContextLogger(ctx).Error("error when getting studio by id", zap.Error(err))
return nil, err
}
return studioDB.ToStudio(), nil
}
func (s *StudioService) Search(ctx context.Context, search entity.StudioSearch) ([]*entity.Studio, int, error) {
studios, total, err := s.repo.SearchStudios(ctx, search)
if err != nil {
logger.ContextLogger(ctx).Error("error when getting all studios", zap.Error(err))
return nil, 0, err
}
return studios.ToStudioList(), total, nil
}
@@ -0,0 +1,99 @@
package cashier_session
import (
"enaklo-pos-be/internal/common/logger"
"enaklo-pos-be/internal/common/mycontext"
"enaklo-pos-be/internal/entity"
"github.com/pkg/errors"
"go.uber.org/zap"
)
type Service interface {
OpenSession(ctx mycontext.Context, session *entity.CashierSession) (*entity.CashierSession, error)
CloseSession(ctx mycontext.Context, sessionID int64, closingAmount float64) (*entity.CashierSessionReport, error)
GetOpenSession(ctx mycontext.Context, cashierID int64) (*entity.CashierSession, error)
GetSessionReport(ctx mycontext.Context, sessionID int64) (*entity.CashierSessionReport, error)
}
type Repository interface {
CreateSession(ctx mycontext.Context, session *entity.CashierSession) (*entity.CashierSession, error)
CloseSession(ctx mycontext.Context, sessionID int64, closingAmount, expectedAmount float64) error
GetOpenSessionByCashierID(ctx mycontext.Context, cashierID int64) (*entity.CashierSession, error)
GetSessionByID(ctx mycontext.Context, sessionID int64) (*entity.CashierSession, error)
GetPaymentSummaryBySessionID(ctx mycontext.Context, sessionID int64) ([]entity.PaymentSummary, error)
}
type cashierSessionSvc struct {
repo Repository
}
func New(repo Repository) Service {
return &cashierSessionSvc{repo: repo}
}
func (s *cashierSessionSvc) OpenSession(ctx mycontext.Context, session *entity.CashierSession) (*entity.CashierSession, error) {
openSession, err := s.repo.GetOpenSessionByCashierID(ctx, session.CashierID)
if err != nil {
return nil, errors.Wrap(err, "failed to check existing open session")
}
if openSession != nil {
return nil, errors.New("cashier already has an open session")
}
newSession, err := s.repo.CreateSession(ctx, session)
if err != nil {
logger.ContextLogger(ctx).Error("failed to create cashier session", zap.Error(err))
return nil, errors.Wrap(err, "failed to create cashier session")
}
return newSession, nil
}
func (s *cashierSessionSvc) CloseSession(ctx mycontext.Context, sessionID int64, closingAmount float64) (*entity.CashierSessionReport, error) {
report, err := s.repo.GetPaymentSummaryBySessionID(ctx, sessionID)
if err != nil {
return nil, errors.Wrap(err, "failed to get payment summary")
}
var expectedAmount float64
for _, r := range report {
expectedAmount += r.TotalAmount
}
if err := s.repo.CloseSession(ctx, sessionID, closingAmount, expectedAmount); err != nil {
return nil, errors.Wrap(err, "failed to close session")
}
return &entity.CashierSessionReport{
SessionID: sessionID,
ClosingAmount: closingAmount,
ExpectedAmount: expectedAmount,
Payments: report,
}, nil
}
func (s *cashierSessionSvc) GetOpenSession(ctx mycontext.Context, cashierID int64) (*entity.CashierSession, error) {
session, err := s.repo.GetOpenSessionByCashierID(ctx, cashierID)
if err != nil {
return nil, errors.Wrap(err, "failed to get open session")
}
return session, nil
}
func (s *cashierSessionSvc) GetSessionReport(ctx mycontext.Context, sessionID int64) (*entity.CashierSessionReport, error) {
report, err := s.repo.GetPaymentSummaryBySessionID(ctx, sessionID)
if err != nil {
return nil, errors.Wrap(err, "failed to get payment summary")
}
var expectedAmount float64
for _, r := range report {
expectedAmount += r.TotalAmount
}
return &entity.CashierSessionReport{
SessionID: sessionID,
ExpectedAmount: expectedAmount,
Payments: report,
}, nil
}
@@ -0,0 +1,88 @@
package category
import (
"enaklo-pos-be/internal/common/logger"
"enaklo-pos-be/internal/common/mycontext"
"enaklo-pos-be/internal/entity"
"github.com/pkg/errors"
"go.uber.org/zap"
)
type Service interface {
Create(ctx mycontext.Context, category *entity.Category) (*entity.Category, error)
GetByPartnerID(ctx mycontext.Context, partnerID int64) ([]*entity.Category, error)
Update(ctx mycontext.Context, category *entity.Category) error
Delete(ctx mycontext.Context, id int64) error
GetByID(ctx mycontext.Context, id int64) (*entity.Category, error)
}
type Repository interface {
Create(ctx mycontext.Context, category *entity.Category) (*entity.Category, error)
GetByPartnerID(ctx mycontext.Context, partnerID int64) ([]*entity.Category, error)
Update(ctx mycontext.Context, category *entity.Category) error
Delete(ctx mycontext.Context, id int64) error
GetByID(ctx mycontext.Context, id int64) (*entity.Category, error)
}
type categorySvc struct {
repo Repository
}
func New(repo Repository) Service {
return &categorySvc{repo: repo}
}
func (s *categorySvc) Create(ctx mycontext.Context, category *entity.Category) (*entity.Category, error) {
existing, err := s.repo.GetByPartnerID(ctx, category.PartnerID)
if err != nil {
return nil, errors.Wrap(err, "failed to fetch categories")
}
for _, cat := range existing {
if cat.Name == category.Name {
return nil, errors.New("category name already exists for this partner")
}
}
newCategory, err := s.repo.Create(ctx, category)
if err != nil {
logger.ContextLogger(ctx).Error("failed to create category", zap.Error(err))
return nil, errors.Wrap(err, "failed to create category")
}
return newCategory, nil
}
func (s *categorySvc) GetByPartnerID(ctx mycontext.Context, partnerID int64) ([]*entity.Category, error) {
categories, err := s.repo.GetByPartnerID(ctx, partnerID)
if err != nil {
return nil, errors.Wrap(err, "failed to get categories by partner")
}
return categories, nil
}
func (s *categorySvc) Update(ctx mycontext.Context, category *entity.Category) error {
err := s.repo.Update(ctx, category)
if err != nil {
logger.ContextLogger(ctx).Error("failed to update category", zap.Error(err))
return errors.Wrap(err, "failed to update category")
}
return nil
}
func (s *categorySvc) Delete(ctx mycontext.Context, id int64) error {
err := s.repo.Delete(ctx, id)
if err != nil {
logger.ContextLogger(ctx).Error("failed to delete category", zap.Error(err))
return errors.Wrap(err, "failed to delete category")
}
return nil
}
func (s *categorySvc) GetByID(ctx mycontext.Context, id int64) (*entity.Category, error) {
category, err := s.repo.GetByID(ctx, id)
if err != nil {
return nil, errors.Wrap(err, "failed to get category by ID")
}
return category, nil
}
@@ -12,6 +12,13 @@ import (
func (s *orderSvc) CreateOrderInquiry(ctx mycontext.Context,
req *entity.OrderRequest) (*entity.OrderInquiryResponse, error) {
cashierSession, err := s.cashierSvc.GetOpenSession(ctx, ctx.RequestedBy())
if err != nil {
logger.ContextLogger(ctx).Error("no open session found for cashier", zap.Error(err))
return nil, err
}
productIDs, filteredItems, err := s.ValidateOrderItems(ctx, req.OrderItems)
if err != nil {
return nil, err
@@ -60,6 +67,7 @@ func (s *orderSvc) CreateOrderInquiry(ctx mycontext.Context,
req.PaymentProvider,
req.TableNumber,
req.OrderType,
cashierSession.ID,
)
for _, item := range req.OrderItems {
@@ -6,6 +6,7 @@ import (
"enaklo-pos-be/internal/constants"
"enaklo-pos-be/internal/entity"
"fmt"
"github.com/pkg/errors"
"go.uber.org/zap"
"time"
)
@@ -36,6 +37,20 @@ func (s *orderSvc) ExecuteOrderInquiry(ctx mycontext.Context,
}, nil
}
func (s *orderSvc) RefundRequest(ctx mycontext.Context, partnerID, orderID int64, reason string) error {
order, err := s.repo.FindByIDAndPartnerID(ctx, partnerID, orderID)
if err != nil {
logger.ContextLogger(ctx).Error("failed to create order", zap.Error(err))
return err
}
if order.Status != "PAID" {
return errors.New("only paid order can be refund")
}
return s.repo.UpdateOrder(ctx, order.ID, "REFUNDED", reason)
}
func (s *orderSvc) processPostOrderActions(
ctx mycontext.Context,
order *entity.Order,
+9
View File
@@ -12,6 +12,7 @@ type Repository interface {
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,
@@ -65,6 +66,7 @@ type Service interface {
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,
@@ -122,6 +124,10 @@ type VoucherUndianRepo interface {
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
@@ -133,6 +139,7 @@ type orderSvc struct {
partnerSetting PartnerSettings
inprogressOrder InProgressOrderRepository
voucherUndianRepo VoucherUndianRepo
cashierSvc CashierSvc
}
func New(
@@ -145,6 +152,7 @@ func New(
notification NotificationService,
partnerSetting PartnerSettings,
voucherUndianRepo VoucherUndianRepo,
cashierSvc CashierSvc,
) Service {
return &orderSvc{
repo: repo,
@@ -156,5 +164,6 @@ func New(
notification: notification,
partnerSetting: partnerSetting,
voucherUndianRepo: voucherUndianRepo,
cashierSvc: cashierSvc,
}
}