feat: integrate logging and audit trail in inventory transaction service
Deploy Application / deploy (push) Failing after 16s
Details
Deploy Application / deploy (push) Failing after 16s
Details
This commit is contained in:
parent
e6b19a2478
commit
fd664c5c3f
|
|
@ -7,8 +7,10 @@ import (
|
||||||
dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_transaction/dto"
|
dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_transaction/dto"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_transaction/query"
|
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_transaction/query"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_transaction/repository"
|
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_transaction/repository"
|
||||||
|
"github.com/Caknoooo/go-gin-clean-starter/pkg/constants"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/pkg/utils"
|
"github.com/Caknoooo/go-gin-clean-starter/pkg/utils"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -23,6 +25,7 @@ type InventoryTransactionService interface {
|
||||||
type inventoryTransactionService struct {
|
type inventoryTransactionService struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
inventoryTransactionRepo repository.InventoryTransactionRepository
|
inventoryTransactionRepo repository.InventoryTransactionRepository
|
||||||
|
log *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *inventoryTransactionService) Create(ctx context.Context, req dtodomain.InventoryTransactionCreateRequest) (dtodomain.InventoryTransactionResponse, error) {
|
func (s *inventoryTransactionService) Create(ctx context.Context, req dtodomain.InventoryTransactionCreateRequest) (dtodomain.InventoryTransactionResponse, error) {
|
||||||
|
|
@ -77,6 +80,7 @@ func (s *inventoryTransactionService) Create(ctx context.Context, req dtodomain.
|
||||||
InvReceiptID: invReceiptUUID,
|
InvReceiptID: invReceiptUUID,
|
||||||
InvIssueID: invIssueUUID,
|
InvIssueID: invIssueUUID,
|
||||||
InvMoveID: invMoveUUID,
|
InvMoveID: invMoveUUID,
|
||||||
|
FullAuditTrail: utils.FillAuditTrail(ctx, constants.CREATE),
|
||||||
}
|
}
|
||||||
created, err := s.inventoryTransactionRepo.Create(ctx, tx, entity)
|
created, err := s.inventoryTransactionRepo.Create(ctx, tx, entity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -84,6 +88,12 @@ func (s *inventoryTransactionService) Create(ctx context.Context, req dtodomain.
|
||||||
return dtodomain.InventoryTransactionResponse{}, err
|
return dtodomain.InventoryTransactionResponse{}, err
|
||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
s.log.WithFields(logrus.Fields{
|
||||||
|
"user_id": utils.GetUserID(ctx),
|
||||||
|
"action": constants.CREATE,
|
||||||
|
"entity": "inventory_transaction",
|
||||||
|
"entity_id": created.ID.String(),
|
||||||
|
}).Info("Inventory Transaction created")
|
||||||
result, err := s.inventoryTransactionRepo.GetById(ctx, nil, created.ID.String())
|
result, err := s.inventoryTransactionRepo.GetById(ctx, nil, created.ID.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dtodomain.InventoryTransactionResponse{}, err
|
return dtodomain.InventoryTransactionResponse{}, err
|
||||||
|
|
@ -126,6 +136,9 @@ func (s *inventoryTransactionService) Update(ctx context.Context, req dtodomain.
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return dtodomain.InventoryTransactionResponse{}, err
|
return dtodomain.InventoryTransactionResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
before := entity
|
||||||
|
|
||||||
if req.TransactionType != "" {
|
if req.TransactionType != "" {
|
||||||
entity.TransactionType = req.TransactionType
|
entity.TransactionType = req.TransactionType
|
||||||
}
|
}
|
||||||
|
|
@ -163,12 +176,23 @@ func (s *inventoryTransactionService) Update(ctx context.Context, req dtodomain.
|
||||||
entity.InvMoveID = &invMoveUUID
|
entity.InvMoveID = &invMoveUUID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
entity.FullAuditTrail = utils.FillAuditTrail(ctx, constants.UPDATE)
|
||||||
updated, err := s.inventoryTransactionRepo.Update(ctx, tx, entity)
|
updated, err := s.inventoryTransactionRepo.Update(ctx, tx, entity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return dtodomain.InventoryTransactionResponse{}, err
|
return dtodomain.InventoryTransactionResponse{}, err
|
||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
|
||||||
|
changes := utils.GetChangedFields(before, updated)
|
||||||
|
s.log.WithFields(logrus.Fields{
|
||||||
|
"user_id": utils.GetUserID(ctx),
|
||||||
|
"action": constants.UPDATE,
|
||||||
|
"entity": "inventory_transaction",
|
||||||
|
"entity_id": updated.ID.String(),
|
||||||
|
"changes": changes,
|
||||||
|
}).Info("Inventory Transaction updated")
|
||||||
|
|
||||||
result, err := s.inventoryTransactionRepo.GetById(ctx, nil, updated.ID.String())
|
result, err := s.inventoryTransactionRepo.GetById(ctx, nil, updated.ID.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dtodomain.InventoryTransactionResponse{}, err
|
return dtodomain.InventoryTransactionResponse{}, err
|
||||||
|
|
@ -183,17 +207,37 @@ func (s *inventoryTransactionService) Delete(ctx context.Context, inventoryTrans
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
invTransaction, err := s.inventoryTransactionRepo.GetById(ctx, tx, inventoryTransactionId)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
invTransaction.FullAuditTrail = utils.FillAuditTrail(ctx, constants.DELETE)
|
||||||
|
if _, err := s.inventoryTransactionRepo.Update(ctx, tx, invTransaction); err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := s.inventoryTransactionRepo.Delete(ctx, tx, inventoryTransactionId); err != nil {
|
if err := s.inventoryTransactionRepo.Delete(ctx, tx, inventoryTransactionId); err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
|
||||||
|
s.log.WithFields(logrus.Fields{
|
||||||
|
"user_id": utils.GetUserID(ctx),
|
||||||
|
"action": constants.DELETE,
|
||||||
|
"entity": "inventory_transaction",
|
||||||
|
"entity_id": inventoryTransactionId,
|
||||||
|
}).Info("Inventory Transaction deleted")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInventoryTransactionService(db *gorm.DB, repo repository.InventoryTransactionRepository) InventoryTransactionService {
|
func NewInventoryTransactionService(db *gorm.DB, repo repository.InventoryTransactionRepository, log *logrus.Logger) InventoryTransactionService {
|
||||||
return &inventoryTransactionService{
|
return &inventoryTransactionService{
|
||||||
db: db,
|
db: db,
|
||||||
inventoryTransactionRepo: repo,
|
inventoryTransactionRepo: repo,
|
||||||
|
log: log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ func RegisterDependencies(injector *do.Injector) {
|
||||||
inventoryReturnServ := inventoryReturnService.NewInventoryReturnService(db, inventoryReturnRepository, inventoryReturnLineRepository, inventoryIssueLineRepository, productRepository, sequenceServ, log)
|
inventoryReturnServ := inventoryReturnService.NewInventoryReturnService(db, inventoryReturnRepository, inventoryReturnLineRepository, inventoryIssueLineRepository, productRepository, sequenceServ, log)
|
||||||
inventoryMovementServ := inventoryMovementService.NewInventoryMovementService(db, inventoryMovementRepository, inventoryMovementLineRepository, sequenceServ, log)
|
inventoryMovementServ := inventoryMovementService.NewInventoryMovementService(db, inventoryMovementRepository, inventoryMovementLineRepository, sequenceServ, log)
|
||||||
inventoryStorageService := inventoryStorageService.NewInventoryStorageService(db, inventoryStorageRepository, log)
|
inventoryStorageService := inventoryStorageService.NewInventoryStorageService(db, inventoryStorageRepository, log)
|
||||||
inventoryTransactionServ := inventoryTransactionService.NewInventoryTransactionService(db, inventoryTransactionRepository)
|
inventoryTransactionServ := inventoryTransactionService.NewInventoryTransactionService(db, inventoryTransactionRepository, log)
|
||||||
quarantineServ := quarantineService.NewQuarantineService(db, quarantineRepository, quarantineLineRepository, productRepository, uomRepository, inventoryStorageRepository)
|
quarantineServ := quarantineService.NewQuarantineService(db, quarantineRepository, quarantineLineRepository, productRepository, uomRepository, inventoryStorageRepository)
|
||||||
|
|
||||||
// Controller
|
// Controller
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue