Add Customer users
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/models"
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type IngredientProcessor interface {
|
||||
CreateIngredient(ctx context.Context, req *models.CreateIngredientRequest) (*models.IngredientResponse, error)
|
||||
UpdateIngredient(ctx context.Context, id uuid.UUID, req *models.UpdateIngredientRequest) (*models.IngredientResponse, error)
|
||||
DeleteIngredient(ctx context.Context, id uuid.UUID) error
|
||||
GetIngredientByID(ctx context.Context, id uuid.UUID) (*models.IngredientResponse, error)
|
||||
ListIngredients(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID, page, limit int, search string) (*models.PaginatedResponse[models.IngredientResponse], error)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/models"
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type IngredientServiceImpl struct {
|
||||
ingredientProcessor IngredientProcessor
|
||||
}
|
||||
|
||||
func NewIngredientService(ingredientProcessor IngredientProcessor) *IngredientServiceImpl {
|
||||
return &IngredientServiceImpl{
|
||||
ingredientProcessor: ingredientProcessor,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IngredientServiceImpl) CreateIngredient(ctx context.Context, req *models.CreateIngredientRequest) (*models.IngredientResponse, error) {
|
||||
return s.ingredientProcessor.CreateIngredient(ctx, req)
|
||||
}
|
||||
|
||||
func (s *IngredientServiceImpl) UpdateIngredient(ctx context.Context, id uuid.UUID, req *models.UpdateIngredientRequest) (*models.IngredientResponse, error) {
|
||||
return s.ingredientProcessor.UpdateIngredient(ctx, id, req)
|
||||
}
|
||||
|
||||
func (s *IngredientServiceImpl) DeleteIngredient(ctx context.Context, id uuid.UUID) error {
|
||||
return s.ingredientProcessor.DeleteIngredient(ctx, id)
|
||||
}
|
||||
|
||||
func (s *IngredientServiceImpl) GetIngredientByID(ctx context.Context, id uuid.UUID) (*models.IngredientResponse, error) {
|
||||
return s.ingredientProcessor.GetIngredientByID(ctx, id)
|
||||
}
|
||||
|
||||
func (s *IngredientServiceImpl) ListIngredients(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID, page, limit int, search string) (*models.PaginatedResponse[models.IngredientResponse], error) {
|
||||
return s.ingredientProcessor.ListIngredients(ctx, organizationID, outletID, page, limit, search)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/models"
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type InventoryMovementProcessor interface {
|
||||
CreateInventoryMovement(ctx context.Context, req *models.CreateInventoryMovementRequest) (*models.InventoryMovementResponse, error)
|
||||
GetInventoryMovementByID(ctx context.Context, id uuid.UUID) (*models.InventoryMovementResponse, error)
|
||||
ListInventoryMovements(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID, page, limit int, search string) (*models.PaginatedResponse[models.InventoryMovementResponse], error)
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/entities"
|
||||
"apskel-pos-be/internal/repository"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type InventoryMovementService interface {
|
||||
CreateIngredientMovement(ctx context.Context, ingredientID, organizationID, outletID, userID uuid.UUID, movementType entities.InventoryMovementType, quantity float64, unitCost float64, reason string, referenceType *entities.InventoryMovementReferenceType, referenceID *uuid.UUID) error
|
||||
CreateProductMovement(ctx context.Context, productID, organizationID, outletID, userID uuid.UUID, movementType entities.InventoryMovementType, quantity float64, unitCost float64, reason string, referenceType *entities.InventoryMovementReferenceType, referenceID *uuid.UUID) error
|
||||
}
|
||||
|
||||
type InventoryMovementServiceImpl struct {
|
||||
inventoryMovementRepo repository.InventoryMovementRepository
|
||||
ingredientRepo *repository.IngredientRepository
|
||||
}
|
||||
|
||||
func NewInventoryMovementService(inventoryMovementRepo repository.InventoryMovementRepository, ingredientRepo *repository.IngredientRepository) InventoryMovementService {
|
||||
return &InventoryMovementServiceImpl{
|
||||
inventoryMovementRepo: inventoryMovementRepo,
|
||||
ingredientRepo: ingredientRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *InventoryMovementServiceImpl) CreateIngredientMovement(ctx context.Context, ingredientID, organizationID, outletID, userID uuid.UUID, movementType entities.InventoryMovementType, quantity float64, unitCost float64, reason string, referenceType *entities.InventoryMovementReferenceType, referenceID *uuid.UUID) error {
|
||||
ingredient, err := s.ingredientRepo.GetByID(ctx, ingredientID, organizationID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
previousQuantity := ingredient.Stock
|
||||
newQuantity := previousQuantity + quantity
|
||||
|
||||
movement := &entities.InventoryMovement{
|
||||
ID: uuid.New(),
|
||||
OrganizationID: organizationID,
|
||||
OutletID: outletID,
|
||||
ItemID: ingredientID,
|
||||
ItemType: "INGREDIENT",
|
||||
MovementType: movementType,
|
||||
Quantity: quantity,
|
||||
PreviousQuantity: previousQuantity,
|
||||
NewQuantity: newQuantity,
|
||||
UnitCost: unitCost,
|
||||
TotalCost: unitCost * quantity,
|
||||
ReferenceType: referenceType,
|
||||
ReferenceID: referenceID,
|
||||
UserID: userID,
|
||||
Reason: &reason,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
err = s.inventoryMovementRepo.Create(ctx, movement)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.ingredientRepo.UpdateStock(ctx, ingredientID, quantity, organizationID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *InventoryMovementServiceImpl) CreateProductMovement(ctx context.Context, productID, organizationID, outletID, userID uuid.UUID, movementType entities.InventoryMovementType, quantity float64, unitCost float64, reason string, referenceType *entities.InventoryMovementReferenceType, referenceID *uuid.UUID) error {
|
||||
movement := &entities.InventoryMovement{
|
||||
ID: uuid.New(),
|
||||
OrganizationID: organizationID,
|
||||
OutletID: outletID,
|
||||
ItemID: productID,
|
||||
ItemType: "PRODUCT",
|
||||
MovementType: movementType,
|
||||
Quantity: quantity,
|
||||
PreviousQuantity: 0, // TODO This would be fetched from product inventory
|
||||
NewQuantity: 0, // TODO This would be calculated
|
||||
UnitCost: unitCost,
|
||||
TotalCost: unitCost * quantity,
|
||||
ReferenceType: referenceType,
|
||||
ReferenceID: referenceID,
|
||||
UserID: userID,
|
||||
Reason: &reason,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
err := s.inventoryMovementRepo.Create(ctx, movement)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -31,15 +31,11 @@ func NewPaymentMethodService(paymentMethodProcessor processor.PaymentMethodProce
|
||||
}
|
||||
|
||||
func (s *PaymentMethodServiceImpl) CreatePaymentMethod(ctx context.Context, contextInfo *appcontext.ContextInfo, req *contract.CreatePaymentMethodRequest) *contract.Response {
|
||||
// Convert contract to model
|
||||
modelReq := mappers.CreatePaymentMethodContractToModel(req)
|
||||
|
||||
// Set organization ID from context if not provided
|
||||
if modelReq.OrganizationID == uuid.Nil && contextInfo != nil {
|
||||
modelReq.OrganizationID = contextInfo.OrganizationID
|
||||
}
|
||||
|
||||
// Process request
|
||||
response, err := s.paymentMethodProcessor.CreatePaymentMethod(ctx, modelReq)
|
||||
if err != nil {
|
||||
return contract.BuildErrorResponse([]*contract.ResponseError{
|
||||
@@ -47,7 +43,6 @@ func (s *PaymentMethodServiceImpl) CreatePaymentMethod(ctx context.Context, cont
|
||||
})
|
||||
}
|
||||
|
||||
// Convert model to contract
|
||||
contractResponse := mappers.PaymentMethodResponseToContract(response)
|
||||
return contract.BuildSuccessResponse(contractResponse)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/models"
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type UnitProcessor interface {
|
||||
CreateUnit(ctx context.Context, req *models.CreateUnitRequest) (*models.UnitResponse, error)
|
||||
UpdateUnit(ctx context.Context, id uuid.UUID, req *models.UpdateUnitRequest) (*models.UnitResponse, error)
|
||||
DeleteUnit(ctx context.Context, id uuid.UUID) error
|
||||
GetUnitByID(ctx context.Context, id uuid.UUID) (*models.UnitResponse, error)
|
||||
ListUnits(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID, page, limit int, search string) (*models.PaginatedResponse[models.UnitResponse], error)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/models"
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type UnitServiceImpl struct {
|
||||
unitProcessor UnitProcessor
|
||||
}
|
||||
|
||||
func NewUnitService(unitProcessor UnitProcessor) *UnitServiceImpl {
|
||||
return &UnitServiceImpl{
|
||||
unitProcessor: unitProcessor,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UnitServiceImpl) CreateUnit(ctx context.Context, req *models.CreateUnitRequest) (*models.UnitResponse, error) {
|
||||
return s.unitProcessor.CreateUnit(ctx, req)
|
||||
}
|
||||
|
||||
func (s *UnitServiceImpl) UpdateUnit(ctx context.Context, id uuid.UUID, req *models.UpdateUnitRequest) (*models.UnitResponse, error) {
|
||||
return s.unitProcessor.UpdateUnit(ctx, id, req)
|
||||
}
|
||||
|
||||
func (s *UnitServiceImpl) DeleteUnit(ctx context.Context, id uuid.UUID) error {
|
||||
return s.unitProcessor.DeleteUnit(ctx, id)
|
||||
}
|
||||
|
||||
func (s *UnitServiceImpl) GetUnitByID(ctx context.Context, id uuid.UUID) (*models.UnitResponse, error) {
|
||||
return s.unitProcessor.GetUnitByID(ctx, id)
|
||||
}
|
||||
|
||||
func (s *UnitServiceImpl) ListUnits(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID, page, limit int, search string) (*models.PaginatedResponse[models.UnitResponse], error) {
|
||||
return s.unitProcessor.ListUnits(ctx, organizationID, outletID, page, limit, search)
|
||||
}
|
||||
Reference in New Issue
Block a user