mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +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 {
|
type LocationDTO struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Area *AreaDTO `json:"area"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type WarehouseDetailDTO struct {
|
type WarehouseDetailDTO struct {
|
||||||
@@ -119,11 +118,9 @@ func toLocationDTO(l *entity.Location) *LocationDTO {
|
|||||||
if l == nil {
|
if l == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Area selalu diisi jika l.Area ada
|
|
||||||
return &LocationDTO{
|
return &LocationDTO{
|
||||||
Id: l.Id,
|
Id: l.Id,
|
||||||
Name: l.Name,
|
Name: l.Name,
|
||||||
Area: toAreaDTO(&l.Area),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +132,7 @@ func toWarehouseDetailDTO(w *entity.Warehouse) *WarehouseDetailDTO {
|
|||||||
Id: w.Id,
|
Id: w.Id,
|
||||||
Name: w.Name,
|
Name: w.Name,
|
||||||
Location: toLocationDTO(w.Location),
|
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) {
|
func (s transferService) GetOne(c *fiber.Ctx, id uint) (*entity.StockTransfer, error) {
|
||||||
var transfer entity.StockTransfer
|
var transfer entity.StockTransfer
|
||||||
|
|
||||||
db := s.StockTransferRepo.DB().WithContext(c.Context())
|
// gunakan repo secara langsung
|
||||||
db = s.withRelations(db)
|
transferPtr, err := s.StockTransferRepo.GetByID(c.Context(), id, func(db *gorm.DB) *gorm.DB {
|
||||||
|
return s.withRelations(db)
|
||||||
if err := db.First(&transfer, id).Error; err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, fiber.NewError(fiber.StatusNotFound, "Transfer not found")
|
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 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) {
|
func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferRequest) (*entity.StockTransfer, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user