Feat(BE-36,37,38,39): finish master data management api

This commit is contained in:
Hafizh A. Y
2025-10-03 21:04:21 +07:00
parent e8905be856
commit 2d49ffe4cd
103 changed files with 6974 additions and 117 deletions
@@ -122,7 +122,7 @@ func (s *warehouseService) CreateOne(c *fiber.Ctx, req *validation.Create) (*ent
return nil, err
}
return s.Repository.GetByID(c.Context(), createBody.Id, s.withRelations)
return s.GetOne(c, createBody.Id)
}
func (s warehouseService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint) (*entity.Warehouse, error) {
@@ -152,22 +152,20 @@ func (s warehouseService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uin
updateBody["type"] = normalizedType
req.Type = &normalizedType
}
if err := common.EnsureRelations(c.Context(),
common.RelationCheck{Name: "Area", ID: req.AreaId, Exists: s.Repository.AreaExists},
common.RelationCheck{Name: "Location", ID: req.LocationId, Exists: s.Repository.LocationExists},
common.RelationCheck{Name: "Kandang", ID: req.KandangId, Exists: s.Repository.KandangExists},
); err != nil {
return nil, err
}
if req.AreaId != nil {
if err := common.EnsureRelations(c.Context(), common.RelationCheck{Name: "Area", ID: req.AreaId, Exists: s.Repository.AreaExists}); err != nil {
return nil, err
}
updateBody["area_id"] = *req.AreaId
}
if req.LocationId != nil {
if err := common.EnsureRelations(c.Context(), common.RelationCheck{Name: "Location", ID: req.LocationId, Exists: s.Repository.LocationExists}); err != nil {
return nil, err
}
updateBody["location_id"] = req.LocationId
}
if req.KandangId != nil {
if err := common.EnsureRelations(c.Context(), common.RelationCheck{Name: "Kandang", ID: req.KandangId, Exists: s.Repository.KandangExists}); err != nil {
return nil, err
}
updateBody["kandang_id"] = req.KandangId
}