mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Feat(BE-36,37,38,39): finish master data management api
This commit is contained in:
@@ -67,3 +67,9 @@ func ToLocationListDTOs(e []entity.Location) []LocationListDTO {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToLocationDetailDTO(e entity.Location) LocationDetailDTO {
|
||||
return LocationDetailDTO{
|
||||
LocationListDTO: ToLocationListDTO(e),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +107,7 @@ func (s *locationService) CreateOne(c *fiber.Ctx, req *validation.Create) (*enti
|
||||
return nil, err
|
||||
}
|
||||
|
||||
created, err := s.Repository.GetByID(c.Context(), createBody.Id, s.withRelations)
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to reload created location: %+v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return created, nil
|
||||
return s.GetOne(c, createBody.Id)
|
||||
}
|
||||
|
||||
func (s locationService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint) (*entity.Location, error) {
|
||||
@@ -137,10 +131,11 @@ func (s locationService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint
|
||||
updateBody["address"] = *req.Address
|
||||
}
|
||||
|
||||
if err := common.EnsureRelations(c.Context(), common.RelationCheck{Name: "Area", ID: req.AreaId, Exists: s.Repository.AreaExists}); 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
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ type Create struct {
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
Name *string `json:"name,omitempty" validate:"omitempty,max=50"`
|
||||
Name *string `json:"name,omitempty" validate:"omitempty"`
|
||||
Address *string `json:"address,omitempty" validate:"omitempty"`
|
||||
AreaId *uint `json:"area_id,omitempty" validate:"omitempty,number,gt=0"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user