Compare commits

...

2 Commits

Author SHA1 Message Date
Habib Fatkhul Rohman 5c27453315 feat: refactor warehouse service to include logging and audit trail functionality
Deploy Application / deploy (push) Successful in 20s Details
2025-12-01 15:58:35 +07:00
Habib Fatkhul Rohman abb01c5eab feat: enhance UOM service with audit trail and logging capabilities 2025-12-01 15:17:44 +07:00
7 changed files with 256 additions and 118 deletions

View File

@ -3,6 +3,7 @@ package dto
import ( import (
"errors" "errors"
"github.com/Caknoooo/go-gin-clean-starter/database/entities"
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto" pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
) )
@ -55,3 +56,19 @@ type UomResponse struct {
IsActive bool `json:"is_active"` IsActive bool `json:"is_active"`
Client pkgdto.ClientResponse `json:"client"` Client pkgdto.ClientResponse `json:"client"`
} }
func ToUomResponse(e entities.MUomEntity) UomResponse {
return UomResponse{
ID: e.ID.String(),
Name: e.Name,
Description: e.Description,
Symbol: e.Symbol,
Code: e.Code,
StdPrecision: e.StdPrecision,
IsActive: e.IsActive,
Client: pkgdto.ClientResponse{
ID: e.Client.ID.String(),
Name: e.Client.Name,
},
}
}

View File

@ -8,8 +8,11 @@ import (
dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/uom/dto" dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/uom/dto"
"github.com/Caknoooo/go-gin-clean-starter/modules/uom/query" "github.com/Caknoooo/go-gin-clean-starter/modules/uom/query"
"github.com/Caknoooo/go-gin-clean-starter/modules/uom/repository" "github.com/Caknoooo/go-gin-clean-starter/modules/uom/repository"
"github.com/Caknoooo/go-gin-clean-starter/pkg/constants"
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto" pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
"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"
) )
@ -25,13 +28,15 @@ type uomService struct {
db *gorm.DB db *gorm.DB
uomRepo repository.UomRepository uomRepo repository.UomRepository
sequenceService sequenceservice.SequenceService sequenceService sequenceservice.SequenceService
log *logrus.Logger
} }
func NewUomService(uomRepo repository.UomRepository, sequenceService sequenceservice.SequenceService, db *gorm.DB) UomService { func NewUomService(uomRepo repository.UomRepository, sequenceService sequenceservice.SequenceService, db *gorm.DB, log *logrus.Logger) UomService {
return &uomService{ return &uomService{
uomRepo: uomRepo, uomRepo: uomRepo,
sequenceService: sequenceService, sequenceService: sequenceService,
db: db, db: db,
log: log,
} }
} }
@ -56,12 +61,13 @@ func (s *uomService) Create(ctx context.Context, req dtodomain.UomCreateRequest)
} }
uom := entities.MUomEntity{ uom := entities.MUomEntity{
Name: req.Name, Name: req.Name,
Description: req.Description, Description: req.Description,
Symbol: req.Symbol, Symbol: req.Symbol,
Code: code, Code: code,
StdPrecision: req.StdPrecision, StdPrecision: req.StdPrecision,
IsActive: req.IsActive, IsActive: req.IsActive,
FullAuditTrail: utils.FillAuditTrail(ctx, constants.CREATE),
} }
clientUUID, err := uuid.Parse(req.ClientID) clientUUID, err := uuid.Parse(req.ClientID)
@ -81,7 +87,7 @@ func (s *uomService) Create(ctx context.Context, req dtodomain.UomCreateRequest)
if err != nil { if err != nil {
return dtodomain.UomResponse{}, err return dtodomain.UomResponse{}, err
} }
return toUomResponse(result), nil return dtodomain.ToUomResponse(result), nil
} }
func (s *uomService) GetById(ctx context.Context, uomId string) (dtodomain.UomResponse, error) { func (s *uomService) GetById(ctx context.Context, uomId string) (dtodomain.UomResponse, error) {
@ -89,7 +95,7 @@ func (s *uomService) GetById(ctx context.Context, uomId string) (dtodomain.UomRe
if err != nil { if err != nil {
return dtodomain.UomResponse{}, err return dtodomain.UomResponse{}, err
} }
return toUomResponse(uom), nil return dtodomain.ToUomResponse(uom), nil
} }
func (s *uomService) GetAll(ctx context.Context, filter query.UomFilter) ([]dtodomain.UomResponse, int64, error) { func (s *uomService) GetAll(ctx context.Context, filter query.UomFilter) ([]dtodomain.UomResponse, int64, error) {
@ -99,7 +105,7 @@ func (s *uomService) GetAll(ctx context.Context, filter query.UomFilter) ([]dtod
} }
var responses []dtodomain.UomResponse var responses []dtodomain.UomResponse
for _, u := range uoms { for _, u := range uoms {
responses = append(responses, toUomResponse(u)) responses = append(responses, dtodomain.ToUomResponse(u))
} }
if responses == nil { if responses == nil {
responses = make([]dtodomain.UomResponse, 0) responses = make([]dtodomain.UomResponse, 0)
@ -119,6 +125,9 @@ func (s *uomService) Update(ctx context.Context, req dtodomain.UomUpdateRequest,
tx.Rollback() tx.Rollback()
return dtodomain.UomResponse{}, err return dtodomain.UomResponse{}, err
} }
before := uom
uom.Name = req.Name uom.Name = req.Name
uom.Description = req.Description uom.Description = req.Description
uom.Symbol = req.Symbol uom.Symbol = req.Symbol
@ -136,6 +145,7 @@ func (s *uomService) Update(ctx context.Context, req dtodomain.UomUpdateRequest,
} else { } else {
uom.Client = entities.M_Client{} uom.Client = entities.M_Client{}
} }
uom.FullAuditTrail = utils.FillAuditTrail(ctx, constants.UPDATE)
updated, err := s.uomRepo.Update(ctx, tx, uom) updated, err := s.uomRepo.Update(ctx, tx, uom)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
@ -144,11 +154,19 @@ func (s *uomService) Update(ctx context.Context, req dtodomain.UomUpdateRequest,
tx.Commit() tx.Commit()
result, err := s.uomRepo.GetById(ctx, nil, updated.ID.String()) result, err := s.uomRepo.GetById(ctx, nil, updated.ID.String())
changes := utils.GetChangedFields(before, result)
s.log.WithFields(logrus.Fields{
"user_id": utils.GetUserID(ctx),
"action": "update",
"entity": "uom",
"entity_id": uomId,
"changes": changes, // berisi field yang berubah saja
}).Info("UOM updated")
if err != nil { if err != nil {
return dtodomain.UomResponse{}, err return dtodomain.UomResponse{}, err
} }
return toUomResponse(result), nil return dtodomain.ToUomResponse(result), nil
} }
func (s *uomService) Delete(ctx context.Context, uomId string) error { func (s *uomService) Delete(ctx context.Context, uomId string) error {
@ -158,26 +176,32 @@ func (s *uomService) Delete(ctx context.Context, uomId string) error {
tx.Rollback() tx.Rollback()
} }
}() }()
uom, err := s.uomRepo.GetById(ctx, tx, uomId)
if err != nil {
tx.Rollback()
return err
}
// Isi audit trail DeletedBy
uom.FullAuditTrail = utils.FillAuditTrail(ctx, constants.DELETE)
// Update audit trail sebelum delete
if _, err := s.uomRepo.Update(ctx, tx, uom); err != nil {
tx.Rollback()
return err
}
if err := s.uomRepo.Delete(ctx, tx, uomId); err != nil { if err := s.uomRepo.Delete(ctx, tx, uomId); 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": "delete",
"entity": "uom",
"entity_id": uomId,
}).Info("UOM deleted")
return nil return nil
} }
func toUomResponse(e entities.MUomEntity) dtodomain.UomResponse {
return dtodomain.UomResponse{
ID: e.ID.String(),
Name: e.Name,
Description: e.Description,
Symbol: e.Symbol,
Code: e.Code,
StdPrecision: e.StdPrecision,
IsActive: e.IsActive,
Client: pkgdto.ClientResponse{
ID: e.Client.ID.String(),
Name: e.Client.Name,
},
}
}

View File

@ -3,7 +3,9 @@ package dto
import ( import (
"errors" "errors"
"github.com/Caknoooo/go-gin-clean-starter/database/entities"
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto" pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
"github.com/google/uuid"
) )
const ( const (
@ -54,7 +56,7 @@ type WarehouseResponse struct {
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"` DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
Client pkgdto.IdNameResponse `json:"client"` Client pkgdto.IdNameResponse `json:"client"`
PIC *pkgdto.IdNameResponse `json:"pic"` PIC *pkgdto.IdNameResponse `json:"pic"`
Zonas []WarehouseZonaResponse `json:"zones"` Zonas []WarehouseZonaResponse `json:"zonas"`
} }
type WarehouseZonaResponse struct { type WarehouseZonaResponse struct {
@ -88,3 +90,84 @@ type ZonaAisleResponse struct {
WeightUom pkgdto.IdNameResponse `json:"weight_uom_id"` WeightUom pkgdto.IdNameResponse `json:"weight_uom_id"`
Client pkgdto.IdNameResponse `json:"client_id"` Client pkgdto.IdNameResponse `json:"client_id"`
} }
func ToWarehouseResponse(e entities.MWarehouseEntity) WarehouseResponse {
client := pkgdto.IdNameResponse{}
if e.Client.ID != uuid.Nil {
client = pkgdto.IdNameResponse{
ID: e.Client.ID.String(),
Name: e.Client.Name,
}
}
pic := pkgdto.IdNameResponse{}
if e.PIC.ID != uuid.Nil {
pic = pkgdto.IdNameResponse{
ID: e.PIC.ID.String(),
Name: e.PIC.Name,
}
}
zonas := make([]WarehouseZonaResponse, 0)
for _, zona := range e.Zonas {
zonas = append(zonas, WarehouseZonaResponse{
ID: zona.ID.String(),
Code: zona.Code,
Name: zona.Name,
Type: zona.Type,
Temperature: zona.Temperature,
Hazardous: zona.Hazardous,
QRCodeZone: zona.QRCodeZone,
IsActive: zona.IsActive,
Client: pkgdto.IdNameResponse{
ID: zona.Client.ID.String(),
Name: zona.Client.Name,
},
Aisles: make([]ZonaAisleResponse, 0),
})
for _, aisle := range zona.Aisles {
zonas[len(zonas)-1].Aisles = append(zonas[len(zonas)-1].Aisles, ZonaAisleResponse{
ID: aisle.ID.String(),
Code: aisle.Code,
Name: aisle.Name,
IsleX: aisle.IsleX,
BinY: aisle.BinY,
LevelZ: aisle.LevelZ,
DimLength: aisle.DimLength,
DimWidth: aisle.DimWidth,
DimHeight: aisle.DimHeight,
Weight: aisle.Weight,
QrCodeAisle: aisle.QrCodeAisle,
IsActive: aisle.IsActive,
Zone: pkgdto.IdNameResponse{
ID: aisle.Zona.ID.String(),
Name: aisle.Zona.Name,
},
DimUom: pkgdto.IdNameResponse{
ID: aisle.DimUom.ID.String(),
Name: aisle.DimUom.Name,
},
WeightUom: pkgdto.IdNameResponse{
ID: aisle.WeightUom.ID.String(),
Name: aisle.WeightUom.Name,
},
Client: pkgdto.IdNameResponse{
ID: aisle.Client.ID.String(),
Name: aisle.Client.Name,
},
})
}
}
return WarehouseResponse{
ID: e.ID.String(),
Code: e.Code,
Name: e.Name,
Description: e.Description,
Status: e.Status,
DissallowNegativeInventory: e.DissallowNegativeInventory,
Client: client,
PIC: &pic,
Zonas: zonas,
}
}

View File

@ -7,9 +7,10 @@ import (
dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/warehouse/dto" dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/warehouse/dto"
"github.com/Caknoooo/go-gin-clean-starter/modules/warehouse/query" "github.com/Caknoooo/go-gin-clean-starter/modules/warehouse/query"
"github.com/Caknoooo/go-gin-clean-starter/modules/warehouse/repository" "github.com/Caknoooo/go-gin-clean-starter/modules/warehouse/repository"
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto" "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"
) )
@ -24,87 +25,7 @@ type WarehouseService interface {
type warehouseService struct { type warehouseService struct {
db *gorm.DB db *gorm.DB
warehouseRepo repository.WarehouseRepository warehouseRepo repository.WarehouseRepository
} log *logrus.Logger
func toWarehouseResponse(e entities.MWarehouseEntity) dtodomain.WarehouseResponse {
client := pkgdto.IdNameResponse{}
if e.Client.ID != uuid.Nil {
client = pkgdto.IdNameResponse{
ID: e.Client.ID.String(),
Name: e.Client.Name,
}
}
pic := pkgdto.IdNameResponse{}
if e.PIC.ID != uuid.Nil {
pic = pkgdto.IdNameResponse{
ID: e.PIC.ID.String(),
Name: e.PIC.Name,
}
}
zonas := make([]dtodomain.WarehouseZonaResponse, 0)
for _, zona := range e.Zonas {
zonas = append(zonas, dtodomain.WarehouseZonaResponse{
ID: zona.ID.String(),
Code: zona.Code,
Name: zona.Name,
Type: zona.Type,
Temperature: zona.Temperature,
Hazardous: zona.Hazardous,
QRCodeZone: zona.QRCodeZone,
IsActive: zona.IsActive,
Client: pkgdto.IdNameResponse{
ID: zona.Client.ID.String(),
Name: zona.Client.Name,
},
Aisles: make([]dtodomain.ZonaAisleResponse, 0),
})
for _, aisle := range zona.Aisles {
zonas[len(zonas)-1].Aisles = append(zonas[len(zonas)-1].Aisles, dtodomain.ZonaAisleResponse{
ID: aisle.ID.String(),
Code: aisle.Code,
Name: aisle.Name,
IsleX: aisle.IsleX,
BinY: aisle.BinY,
LevelZ: aisle.LevelZ,
DimLength: aisle.DimLength,
DimWidth: aisle.DimWidth,
DimHeight: aisle.DimHeight,
Weight: aisle.Weight,
QrCodeAisle: aisle.QrCodeAisle,
IsActive: aisle.IsActive,
Zone: pkgdto.IdNameResponse{
ID: aisle.Zona.ID.String(),
Name: aisle.Zona.Name,
},
DimUom: pkgdto.IdNameResponse{
ID: aisle.DimUom.ID.String(),
Name: aisle.DimUom.Name,
},
WeightUom: pkgdto.IdNameResponse{
ID: aisle.WeightUom.ID.String(),
Name: aisle.WeightUom.Name,
},
Client: pkgdto.IdNameResponse{
ID: aisle.Client.ID.String(),
Name: aisle.Client.Name,
},
})
}
}
return dtodomain.WarehouseResponse{
ID: e.ID.String(),
Code: e.Code,
Name: e.Name,
Description: e.Description,
Status: e.Status,
DissallowNegativeInventory: e.DissallowNegativeInventory,
Client: client,
PIC: &pic,
Zonas: zonas,
}
} }
func (w *warehouseService) Create(ctx context.Context, req dtodomain.WarehouseCreateRequest) (dtodomain.WarehouseResponse, error) { func (w *warehouseService) Create(ctx context.Context, req dtodomain.WarehouseCreateRequest) (dtodomain.WarehouseResponse, error) {
@ -127,6 +48,7 @@ func (w *warehouseService) Create(ctx context.Context, req dtodomain.WarehouseCr
DissallowNegativeInventory: req.DissallowNegativeInventory, DissallowNegativeInventory: req.DissallowNegativeInventory,
PICID: utils.ParseNullableUUID(req.PICID), PICID: utils.ParseNullableUUID(req.PICID),
ClientID: clientUUID, ClientID: clientUUID,
FullAuditTrail: utils.FillAuditTrail(ctx, constants.CREATE),
} }
created, err := w.warehouseRepo.Create(ctx, tx, warehouse) created, err := w.warehouseRepo.Create(ctx, tx, warehouse)
@ -139,7 +61,13 @@ func (w *warehouseService) Create(ctx context.Context, req dtodomain.WarehouseCr
if err != nil { if err != nil {
return dtodomain.WarehouseResponse{}, err return dtodomain.WarehouseResponse{}, err
} }
return toWarehouseResponse(result), nil w.log.WithFields(logrus.Fields{
"user_id": utils.GetUserID(ctx),
"action": "create",
"entity": "warehouse",
"entity_id": created.ID.String(),
}).Info("Warehouse created")
return dtodomain.ToWarehouseResponse(result), nil
} }
func (w *warehouseService) GetById(ctx context.Context, warehouseId string) (dtodomain.WarehouseResponse, error) { func (w *warehouseService) GetById(ctx context.Context, warehouseId string) (dtodomain.WarehouseResponse, error) {
@ -147,7 +75,7 @@ func (w *warehouseService) GetById(ctx context.Context, warehouseId string) (dto
if err != nil { if err != nil {
return dtodomain.WarehouseResponse{}, err return dtodomain.WarehouseResponse{}, err
} }
return toWarehouseResponse(warehouse), nil return dtodomain.ToWarehouseResponse(warehouse), nil
} }
func (w *warehouseService) GetAll(ctx context.Context, filter query.WarehouseFilter) ([]dtodomain.WarehouseResponse, int64, error) { func (w *warehouseService) GetAll(ctx context.Context, filter query.WarehouseFilter) ([]dtodomain.WarehouseResponse, int64, error) {
@ -157,7 +85,7 @@ func (w *warehouseService) GetAll(ctx context.Context, filter query.WarehouseFil
} }
var responses []dtodomain.WarehouseResponse var responses []dtodomain.WarehouseResponse
for _, e := range warehouses { for _, e := range warehouses {
responses = append(responses, toWarehouseResponse(e)) responses = append(responses, dtodomain.ToWarehouseResponse(e))
} }
if responses == nil { if responses == nil {
responses = make([]dtodomain.WarehouseResponse, 0) responses = make([]dtodomain.WarehouseResponse, 0)
@ -177,6 +105,7 @@ func (w *warehouseService) Update(ctx context.Context, req dtodomain.WarehouseUp
tx.Rollback() tx.Rollback()
return dtodomain.WarehouseResponse{}, err return dtodomain.WarehouseResponse{}, err
} }
before := warehouse
if req.Code != "" { if req.Code != "" {
warehouse.Code = req.Code warehouse.Code = req.Code
} }
@ -193,6 +122,7 @@ func (w *warehouseService) Update(ctx context.Context, req dtodomain.WarehouseUp
} }
} }
warehouse.PICID = utils.ParseNullableUUID(req.PICID) warehouse.PICID = utils.ParseNullableUUID(req.PICID)
warehouse.FullAuditTrail = utils.FillAuditTrail(ctx, constants.UPDATE)
updated, err := w.warehouseRepo.Update(ctx, tx, warehouse) updated, err := w.warehouseRepo.Update(ctx, tx, warehouse)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
@ -203,7 +133,15 @@ func (w *warehouseService) Update(ctx context.Context, req dtodomain.WarehouseUp
if err != nil { if err != nil {
return dtodomain.WarehouseResponse{}, err return dtodomain.WarehouseResponse{}, err
} }
return toWarehouseResponse(result), nil changes := utils.GetChangedFields(before, result)
w.log.WithFields(logrus.Fields{
"user_id": utils.GetUserID(ctx),
"action": "update",
"entity": "warehouse",
"entity_id": warehouseId,
"changes": changes,
}).Info("Warehouse updated")
return dtodomain.ToWarehouseResponse(result), nil
} }
func (w *warehouseService) Delete(ctx context.Context, warehouseId string) error { func (w *warehouseService) Delete(ctx context.Context, warehouseId string) error {
@ -213,17 +151,34 @@ func (w *warehouseService) Delete(ctx context.Context, warehouseId string) error
tx.Rollback() tx.Rollback()
} }
}() }()
warehouse, err := w.warehouseRepo.GetById(ctx, tx, warehouseId)
if err != nil {
tx.Rollback()
return err
}
warehouse.FullAuditTrail = utils.FillAuditTrail(ctx, constants.DELETE)
if _, err := w.warehouseRepo.Update(ctx, tx, warehouse); err != nil {
tx.Rollback()
return err
}
if err := w.warehouseRepo.Delete(ctx, tx, warehouseId); err != nil { if err := w.warehouseRepo.Delete(ctx, tx, warehouseId); err != nil {
tx.Rollback() tx.Rollback()
return err return err
} }
tx.Commit() tx.Commit()
w.log.WithFields(logrus.Fields{
"user_id": utils.GetUserID(ctx),
"action": "delete",
"entity": "warehouse",
"entity_id": warehouseId,
}).Info("Warehouse deleted")
return nil return nil
} }
func NewWarehouseService(warehouseRepo repository.WarehouseRepository, db *gorm.DB) WarehouseService { func NewWarehouseService(warehouseRepo repository.WarehouseRepository, db *gorm.DB, log *logrus.Logger) WarehouseService {
return &warehouseService{ return &warehouseService{
warehouseRepo: warehouseRepo, warehouseRepo: warehouseRepo,
db: db, db: db,
log: log,
} }
} }

View File

@ -15,4 +15,8 @@ const (
LOGGER = "logger" LOGGER = "logger"
SUPERADMIN = "superadmin" SUPERADMIN = "superadmin"
COMPLETED = "completed" COMPLETED = "completed"
USERID = "user_id"
CREATE = "create"
UPDATE = "update"
DELETE = "delete"
) )

View File

@ -1,6 +1,14 @@
package utils package utils
import "strings" import (
"context"
"reflect"
"strings"
"github.com/Caknoooo/go-gin-clean-starter/database/entities"
"github.com/Caknoooo/go-gin-clean-starter/pkg/constants"
"github.com/google/uuid"
)
func GetInitials(name string) string { func GetInitials(name string) string {
name = strings.TrimSpace(name) name = strings.TrimSpace(name)
@ -25,3 +33,49 @@ func GetInitials(name string) string {
} }
return strings.ToUpper(initials) return strings.ToUpper(initials)
} }
func GetUserID(ctx context.Context) string {
val := ctx.Value(constants.USERID)
if id, ok := val.(string); ok {
return id
}
return ""
}
func FillAuditTrail(ctx context.Context, action string) entities.FullAuditTrail {
userID := GetUserID(ctx)
uid, _ := uuid.Parse(userID)
audit := entities.Audit{}
switch action {
case "create":
audit.CreatedBy = uid
case "update":
audit.UpdatedBy = uid
case "delete":
audit.DeletedBy = uid
}
return entities.FullAuditTrail{Audit: audit}
}
func GetChangedFields(before, after interface{}) map[string]map[string]interface{} {
changes := make(map[string]map[string]interface{})
vBefore := reflect.ValueOf(before)
vAfter := reflect.ValueOf(after)
t := vBefore.Type()
for i := 0; i < vBefore.NumField(); i++ {
field := t.Field(i).Name
if field == "FullAuditTrail" {
continue
}
valBefore := vBefore.Field(i).Interface()
valAfter := vAfter.Field(i).Interface()
if !reflect.DeepEqual(valBefore, valAfter) {
changes[field] = map[string]interface{}{
"old": valBefore,
"new": valAfter,
}
}
}
return changes
}

View File

@ -135,6 +135,7 @@ func RegisterDependencies(injector *do.Injector) {
// Initialize // Initialize
db := do.MustInvokeNamed[*gorm.DB](injector, constants.DB) db := do.MustInvokeNamed[*gorm.DB](injector, constants.DB)
jwtService := do.MustInvokeNamed[service.JWTService](injector, constants.JWTService) jwtService := do.MustInvokeNamed[service.JWTService](injector, constants.JWTService)
log := do.MustInvokeNamed[*logrus.Logger](injector, constants.LOGGER)
// Repository // Repository
userRepository := repository.NewUserRepository(db) userRepository := repository.NewUserRepository(db)
@ -181,9 +182,9 @@ func RegisterDependencies(injector *do.Injector) {
clientServ := clientService.NewClientService(clientRepository, db) clientServ := clientService.NewClientService(clientRepository, db)
permissionsServ := permissionsService.NewPermissionsService(permissionsRepository, db) permissionsServ := permissionsService.NewPermissionsService(permissionsRepository, db)
categoryServ := categoryService.NewCategoryService(categoryRepository, db) categoryServ := categoryService.NewCategoryService(categoryRepository, db)
uomServ := uomService.NewUomService(uomRepository, sequenceServ, db) uomServ := uomService.NewUomService(uomRepository, sequenceServ, db, log)
mvendorServ := mvendorService.NewVendorService(mvendorRepository, sequenceServ, db) mvendorServ := mvendorService.NewVendorService(mvendorRepository, sequenceServ, db)
warehouseServ := warehouseService.NewWarehouseService(warehouseRepository, db) warehouseServ := warehouseService.NewWarehouseService(warehouseRepository, db, log)
zonaServ := zonaService.NewZonaService(zonaRepository, db) zonaServ := zonaService.NewZonaService(zonaRepository, db)
aisleServ := aisleService.NewAisleService(aisleRepository, db) aisleServ := aisleService.NewAisleService(aisleRepository, db)
inventoryReceiptServ := inventoryReceiptService.NewInventoryReceiptService(db, inventoryReceiptRepository, inventoryReceiptLineRepository, productRepository, uomRepository, inventoryStorageRepository, sequenceServ) inventoryReceiptServ := inventoryReceiptService.NewInventoryReceiptService(db, inventoryReceiptRepository, inventoryReceiptLineRepository, productRepository, uomRepository, inventoryStorageRepository, sequenceServ)