Add ingredieints
This commit is contained in:
@@ -43,19 +43,16 @@ func (p *IngredientProcessorImpl) CreateIngredient(ctx context.Context, req *mod
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
|
||||
// Save to database
|
||||
err = p.ingredientRepo.Create(ctx, ingredient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get with relations
|
||||
ingredientWithUnit, err := p.ingredientRepo.GetByID(ctx, ingredient.ID, req.OrganizationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Map to response
|
||||
ingredientModel := mappers.MapIngredientEntityToModel(ingredientWithUnit)
|
||||
response := &models.IngredientResponse{
|
||||
ID: ingredientModel.ID,
|
||||
|
||||
@@ -82,10 +82,6 @@ type PaymentMethodRepository interface {
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*entities.PaymentMethod, error)
|
||||
}
|
||||
|
||||
type ProductVariantRepository interface {
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*entities.ProductVariant, error)
|
||||
}
|
||||
|
||||
type CustomerRepository interface {
|
||||
GetByIDAndOrganization(ctx context.Context, id, organizationID uuid.UUID) (*entities.Customer, error)
|
||||
}
|
||||
@@ -111,7 +107,7 @@ type OrderProcessorImpl struct {
|
||||
paymentMethodRepo PaymentMethodRepository
|
||||
inventoryRepo repository.InventoryRepository
|
||||
inventoryMovementRepo repository.InventoryMovementRepository
|
||||
productVariantRepo ProductVariantRepository
|
||||
productVariantRepo repository.ProductVariantRepository
|
||||
outletRepo OutletRepository
|
||||
customerRepo CustomerRepository
|
||||
}
|
||||
@@ -125,7 +121,7 @@ func NewOrderProcessorImpl(
|
||||
paymentMethodRepo PaymentMethodRepository,
|
||||
inventoryRepo repository.InventoryRepository,
|
||||
inventoryMovementRepo repository.InventoryMovementRepository,
|
||||
productVariantRepo ProductVariantRepository,
|
||||
productVariantRepo repository.ProductVariantRepository,
|
||||
outletRepo OutletRepository,
|
||||
customerRepo CustomerRepository,
|
||||
) *OrderProcessorImpl {
|
||||
@@ -193,7 +189,7 @@ func (p *OrderProcessorImpl) CreateOrder(ctx context.Context, req *models.Create
|
||||
ProductID: itemReq.ProductID,
|
||||
ProductVariantID: itemReq.ProductVariantID,
|
||||
Quantity: itemReq.Quantity,
|
||||
UnitPrice: unitPrice, // Use price from database
|
||||
UnitPrice: unitPrice,
|
||||
TotalPrice: itemTotalPrice,
|
||||
UnitCost: unitCost,
|
||||
TotalCost: itemTotalCost,
|
||||
|
||||
@@ -13,11 +13,11 @@ import (
|
||||
)
|
||||
|
||||
type TableProcessor struct {
|
||||
tableRepo *repository.TableRepository
|
||||
tableRepo repository.TableRepositoryInterface
|
||||
orderRepo repository.OrderRepository
|
||||
}
|
||||
|
||||
func NewTableProcessor(tableRepo *repository.TableRepository, orderRepo repository.OrderRepository) *TableProcessor {
|
||||
func NewTableProcessor(tableRepo repository.TableRepositoryInterface, orderRepo repository.OrderRepository) *TableProcessor {
|
||||
return &TableProcessor{
|
||||
tableRepo: tableRepo,
|
||||
orderRepo: orderRepo,
|
||||
|
||||
@@ -45,6 +45,7 @@ func (p *UnitProcessorImpl) CreateUnit(ctx context.Context, req *models.CreateUn
|
||||
Name: unitModel.Name,
|
||||
Abbreviation: unitModel.Abbreviation,
|
||||
IsActive: unitModel.IsActive,
|
||||
DeletedAt: unitModel.DeletedAt,
|
||||
CreatedAt: unitModel.CreatedAt,
|
||||
UpdatedAt: unitModel.UpdatedAt,
|
||||
}
|
||||
@@ -68,6 +69,7 @@ func (p *UnitProcessorImpl) GetUnitByID(ctx context.Context, id uuid.UUID) (*mod
|
||||
Name: unitModel.Name,
|
||||
Abbreviation: unitModel.Abbreviation,
|
||||
IsActive: unitModel.IsActive,
|
||||
DeletedAt: unitModel.DeletedAt,
|
||||
CreatedAt: unitModel.CreatedAt,
|
||||
UpdatedAt: unitModel.UpdatedAt,
|
||||
}
|
||||
@@ -102,6 +104,7 @@ func (p *UnitProcessorImpl) ListUnits(ctx context.Context, organizationID uuid.U
|
||||
Name: unitModel.Name,
|
||||
Abbreviation: unitModel.Abbreviation,
|
||||
IsActive: unitModel.IsActive,
|
||||
DeletedAt: unitModel.DeletedAt,
|
||||
CreatedAt: unitModel.CreatedAt,
|
||||
UpdatedAt: unitModel.UpdatedAt,
|
||||
}
|
||||
@@ -147,6 +150,7 @@ func (p *UnitProcessorImpl) UpdateUnit(ctx context.Context, id uuid.UUID, req *m
|
||||
Name: unitModel.Name,
|
||||
Abbreviation: unitModel.Abbreviation,
|
||||
IsActive: unitModel.IsActive,
|
||||
DeletedAt: unitModel.DeletedAt,
|
||||
CreatedAt: unitModel.CreatedAt,
|
||||
UpdatedAt: unitModel.UpdatedAt,
|
||||
}
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/models"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// MockUnitRepository is a mock implementation of the unit repository
|
||||
type MockUnitRepository struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *MockUnitRepository) Create(ctx context.Context, unit *models.Unit) error {
|
||||
args := m.Called(ctx, unit)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (m *MockUnitRepository) GetByID(ctx context.Context, id, organizationID uuid.UUID) (*models.Unit, error) {
|
||||
args := m.Called(ctx, id, organizationID)
|
||||
if args.Get(0) == nil {
|
||||
return nil, args.Error(1)
|
||||
}
|
||||
return args.Get(0).(*models.Unit), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockUnitRepository) GetAll(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID, page, limit int, search string) ([]*models.Unit, int, error) {
|
||||
args := m.Called(ctx, organizationID, outletID, page, limit, search)
|
||||
if args.Get(0) == nil {
|
||||
return nil, args.Int(1), args.Error(2)
|
||||
}
|
||||
return args.Get(0).([]*models.Unit), args.Int(1), args.Error(2)
|
||||
}
|
||||
|
||||
func (m *MockUnitRepository) Update(ctx context.Context, unit *models.Unit) error {
|
||||
args := m.Called(ctx, unit)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (m *MockUnitRepository) Delete(ctx context.Context, id, organizationID uuid.UUID) error {
|
||||
args := m.Called(ctx, id, organizationID)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func TestUnitProcessor_Create(t *testing.T) {
|
||||
// Create mock repository
|
||||
mockRepo := &MockUnitRepository{}
|
||||
|
||||
// Create processor
|
||||
processor := NewUnitProcessor(mockRepo)
|
||||
|
||||
// Test data
|
||||
organizationID := uuid.New()
|
||||
request := &models.CreateUnitRequest{
|
||||
Name: "Gram",
|
||||
Abbreviation: "g",
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
// Mock expectations
|
||||
mockRepo.On("Create", mock.Anything, mock.AnythingOfType("*models.Unit")).Return(nil)
|
||||
|
||||
// Execute
|
||||
result, err := processor.Create(request, organizationID)
|
||||
|
||||
// Assertions
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
assert.Equal(t, request.Name, result.Name)
|
||||
assert.Equal(t, request.Abbreviation, result.Abbreviation)
|
||||
assert.Equal(t, request.IsActive, result.IsActive)
|
||||
assert.Equal(t, organizationID, result.OrganizationID)
|
||||
|
||||
mockRepo.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestUnitProcessor_GetByID(t *testing.T) {
|
||||
// Create mock repository
|
||||
mockRepo := &MockUnitRepository{}
|
||||
|
||||
// Create processor
|
||||
processor := NewUnitProcessor(mockRepo)
|
||||
|
||||
// Test data
|
||||
unitID := uuid.New()
|
||||
organizationID := uuid.New()
|
||||
expectedUnit := &models.Unit{
|
||||
ID: unitID,
|
||||
OrganizationID: organizationID,
|
||||
Name: "Gram",
|
||||
Abbreviation: "g",
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
// Mock expectations
|
||||
mockRepo.On("GetByID", mock.Anything, unitID, organizationID).Return(expectedUnit, nil)
|
||||
|
||||
// Execute
|
||||
result, err := processor.GetByID(unitID, organizationID)
|
||||
|
||||
// Assertions
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
assert.Equal(t, expectedUnit.ID, result.ID)
|
||||
assert.Equal(t, expectedUnit.Name, result.Name)
|
||||
|
||||
mockRepo.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestUnitProcessor_GetAll(t *testing.T) {
|
||||
// Create mock repository
|
||||
mockRepo := &MockUnitRepository{}
|
||||
|
||||
// Create processor
|
||||
processor := NewUnitProcessor(mockRepo)
|
||||
|
||||
// Test data
|
||||
organizationID := uuid.New()
|
||||
expectedUnits := []*models.Unit{
|
||||
{
|
||||
ID: uuid.New(),
|
||||
OrganizationID: organizationID,
|
||||
Name: "Gram",
|
||||
Abbreviation: "g",
|
||||
IsActive: true,
|
||||
},
|
||||
{
|
||||
ID: uuid.New(),
|
||||
OrganizationID: organizationID,
|
||||
Name: "Liter",
|
||||
Abbreviation: "L",
|
||||
IsActive: true,
|
||||
},
|
||||
}
|
||||
|
||||
// Mock expectations
|
||||
mockRepo.On("GetAll", mock.Anything, organizationID, (*uuid.UUID)(nil), 1, 10, "").Return(expectedUnits, 2, nil)
|
||||
|
||||
// Execute
|
||||
result, err := processor.GetAll(organizationID, nil, 1, 10, "")
|
||||
|
||||
// Assertions
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
assert.Len(t, result.Data, 2)
|
||||
assert.Equal(t, 2, result.Pagination.Total)
|
||||
|
||||
mockRepo.AssertExpectations(t)
|
||||
}
|
||||
Reference in New Issue
Block a user