Update template email
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func (s *productSvc) GetProductsByIDs(ctx mycontext.Context, ids []int64, partnerID int64) ([]*entity.Product, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*entity.Product{}, nil
|
||||
}
|
||||
|
||||
products, err := s.repo.GetProductsByIDs(ctx, ids, partnerID)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("failed to get products by IDs",
|
||||
zap.Int64s("productIDs", ids),
|
||||
zap.Int64("partnerID", partnerID),
|
||||
zap.Error(err))
|
||||
return nil, errors.Wrap(err, "failed to get products by IDs")
|
||||
}
|
||||
|
||||
// Validate that we found all requested products
|
||||
if len(products) != len(ids) {
|
||||
logger.ContextLogger(ctx).Warn("some products not found",
|
||||
zap.Int("requestedCount", len(ids)),
|
||||
zap.Int("foundCount", len(products)))
|
||||
}
|
||||
|
||||
return products, nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func (s *productSvc) GetProductDetails(ctx mycontext.Context, productIDs []int64, partnerID int64) (*entity.ProductDetails, error) {
|
||||
if len(productIDs) == 0 {
|
||||
return &entity.ProductDetails{
|
||||
Products: make(map[int64]*entity.Product),
|
||||
}, nil
|
||||
}
|
||||
|
||||
productDetails, err := s.repo.GetProductDetails(ctx, productIDs, partnerID)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("failed to get product details",
|
||||
zap.Int64s("productIDs", productIDs),
|
||||
zap.Int64("partnerID", partnerID),
|
||||
zap.Error(err))
|
||||
return nil, errors.Wrap(err, "failed to get product details")
|
||||
}
|
||||
|
||||
if len(productDetails.Products) != len(productIDs) {
|
||||
missingIDs := findMissingProductIDs(productIDs, productDetails.Products)
|
||||
logger.ContextLogger(ctx).Warn("some products not found",
|
||||
zap.Int("requestedCount", len(productIDs)),
|
||||
zap.Int("foundCount", len(productDetails.Products)),
|
||||
zap.Int64s("missingIDs", missingIDs))
|
||||
|
||||
if len(productDetails.Products) == 0 {
|
||||
return nil, errors.New("no products found")
|
||||
}
|
||||
}
|
||||
|
||||
return productDetails, nil
|
||||
}
|
||||
|
||||
func findMissingProductIDs(requestedIDs []int64, foundProducts map[int64]*entity.Product) []int64 {
|
||||
var missingIDs []int64
|
||||
|
||||
for _, id := range requestedIDs {
|
||||
if _, exists := foundProducts[id]; !exists {
|
||||
missingIDs = append(missingIDs, id)
|
||||
}
|
||||
}
|
||||
|
||||
return missingIDs
|
||||
}
|
||||
|
||||
func (s *productSvc) IsProductAvailable(product *entity.Product) bool {
|
||||
return product.Status == "ACTIVE"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"enaklo-pos-be/internal/common/mycontext"
|
||||
"enaklo-pos-be/internal/entity"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
GetProductsByIDs(ctx mycontext.Context, ids []int64, partnerID int64) ([]*entity.Product, error)
|
||||
GetProductDetails(ctx mycontext.Context, productIDs []int64, partnerID int64) (*entity.ProductDetails, error)
|
||||
}
|
||||
|
||||
type Service interface {
|
||||
GetProductsByIDs(ctx mycontext.Context, ids []int64, partnerID int64) ([]*entity.Product, error)
|
||||
GetProductDetails(ctx mycontext.Context, productIDs []int64, partnerID int64) (*entity.ProductDetails, error)
|
||||
}
|
||||
|
||||
type productSvc struct {
|
||||
repo Repository
|
||||
}
|
||||
|
||||
func New(repo Repository) Service {
|
||||
return &productSvc{
|
||||
repo: repo,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user