mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-59,60,61): build stock transfer API with validation and audit log
This commit is contained in:
@@ -29,9 +29,8 @@ type AreaDTO struct {
|
||||
}
|
||||
|
||||
type LocationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Area *AreaDTO `json:"area"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type WarehouseDetailDTO struct {
|
||||
@@ -119,11 +118,9 @@ func toLocationDTO(l *entity.Location) *LocationDTO {
|
||||
if l == nil {
|
||||
return nil
|
||||
}
|
||||
// Area selalu diisi jika l.Area ada
|
||||
return &LocationDTO{
|
||||
Id: l.Id,
|
||||
Name: l.Name,
|
||||
Area: toAreaDTO(&l.Area),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +132,7 @@ func toWarehouseDetailDTO(w *entity.Warehouse) *WarehouseDetailDTO {
|
||||
Id: w.Id,
|
||||
Name: w.Name,
|
||||
Location: toLocationDTO(w.Location),
|
||||
Area: toAreaDTO(&w.Area),
|
||||
Area: toAreaDTO(&w.Area), // Ambil area langsung dari warehouse (area_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,16 +91,21 @@ func (s transferService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
func (s transferService) GetOne(c *fiber.Ctx, id uint) (*entity.StockTransfer, error) {
|
||||
var transfer entity.StockTransfer
|
||||
|
||||
db := s.StockTransferRepo.DB().WithContext(c.Context())
|
||||
db = s.withRelations(db)
|
||||
|
||||
if err := db.First(&transfer, id).Error; err != nil {
|
||||
// gunakan repo secara langsung
|
||||
transferPtr, err := s.StockTransferRepo.GetByID(c.Context(), id, func(db *gorm.DB) *gorm.DB {
|
||||
return s.withRelations(db)
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "Transfer not found")
|
||||
}
|
||||
s.Log.Errorf("Failed to get transfer by ID: %+v", err)
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to get transfer")
|
||||
}
|
||||
return &transfer, nil
|
||||
|
||||
s.Log.Infof("Retrieved transfer: %+v", transfer)
|
||||
|
||||
return transferPtr, nil
|
||||
}
|
||||
|
||||
func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferRequest) (*entity.StockTransfer, error) {
|
||||
|
||||
Reference in New Issue
Block a user