mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
Merge branch 'feat/BE/Sprint-5' into 'feat/BE/US-159,160/marketing'
# Conflicts: # internal/modules/production/project_flocks/controllers/projectflock.controller.go # internal/modules/production/project_flocks/dto/projectflock.dto.go # internal/modules/production/project_flocks/route.go # internal/modules/production/transfer_layings/dto/transfer_laying.dto.go
This commit is contained in:
@@ -90,13 +90,15 @@ func (u *ProjectflockController) GetAll(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
data := make([]dto.ProjectFlockListDTO, 0)
|
||||
for _, projectFlock := range result {
|
||||
var flock *flockDTO.FlockBaseDTO
|
||||
if flockMap != nil {
|
||||
flock = flockMap[projectFlock.Id]
|
||||
var periodMap map[uint]int
|
||||
if len(result) > 0 {
|
||||
ids := make([]uint, len(result))
|
||||
for i, item := range result {
|
||||
ids[i] = item.Id
|
||||
}
|
||||
if periods, err := u.ProjectflockService.GetProjectPeriods(c, ids); err == nil {
|
||||
periodMap = periods
|
||||
}
|
||||
data = append(data, dto.ToProjectFlockListDTO(projectFlock, flock))
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
@@ -110,7 +112,7 @@ func (u *ProjectflockController) GetAll(c *fiber.Ctx) error {
|
||||
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
|
||||
TotalResults: totalResults,
|
||||
},
|
||||
Data: data,
|
||||
Data: dto.ToProjectFlockListDTOsWithPeriods(result, periodMap),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -127,12 +129,19 @@ func (u *ProjectflockController) GetOne(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var period int
|
||||
if periods, err := u.ProjectflockService.GetProjectPeriods(c, []uint{uint(id)}); err == nil {
|
||||
if p, ok := periods[uint(id)]; ok {
|
||||
period = p
|
||||
}
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get projectflock successfully",
|
||||
Data: dto.ToProjectFlockListDTO(*result, flock),
|
||||
Data: dto.ToProjectFlockListDTOWithPeriod(*result, period),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -219,11 +228,29 @@ func (u *ProjectflockController) Approval(c *fiber.Ctx) error {
|
||||
data interface{}
|
||||
message = "Submit projectflock approval successfully"
|
||||
)
|
||||
|
||||
var periodMap map[uint]int
|
||||
if len(results) > 0 {
|
||||
ids := make([]uint, len(results))
|
||||
for i, item := range results {
|
||||
ids[i] = item.Id
|
||||
}
|
||||
if periods, err := u.ProjectflockService.GetProjectPeriods(c, ids); err == nil {
|
||||
periodMap = periods
|
||||
}
|
||||
}
|
||||
|
||||
if len(results) == 1 {
|
||||
data = dto.ToProjectFlockListDTO(results[0], nil)
|
||||
period := 0
|
||||
if periodMap != nil {
|
||||
if p, ok := periodMap[results[0].Id]; ok {
|
||||
period = p
|
||||
}
|
||||
}
|
||||
data = dto.ToProjectFlockListDTOWithPeriod(results[0], period)
|
||||
} else {
|
||||
message = "Submit projectflock approvals successfully"
|
||||
data = dto.ToProjectFlockListDTOs(results)
|
||||
data = dto.ToProjectFlockListDTOsWithPeriods(results, periodMap)
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
@@ -236,25 +263,32 @@ func (u *ProjectflockController) Approval(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func (u *ProjectflockController) GetFlockPeriodSummary(c *fiber.Ctx) error {
|
||||
param := c.Params("project_flock_kandang_id")
|
||||
param := c.Params("location_id")
|
||||
|
||||
id, err := strconv.Atoi(param)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid project_flock_kandang_id")
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid location_id")
|
||||
}
|
||||
|
||||
summary, err := u.ProjectflockService.GetFlockPeriodSummary(c, uint(id))
|
||||
summaries, err := u.ProjectflockService.GetFlockPeriodSummary(c, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
responseBody := dto.ToFlockPeriodSummaryDTO(summary.Flock, summary.NextPeriod)
|
||||
responseBody := make([]dto.KandangPeriodSummaryDTO, 0, len(summaries))
|
||||
for _, item := range summaries {
|
||||
responseBody = append(responseBody, dto.KandangPeriodSummaryDTO{
|
||||
Id: item.Id,
|
||||
Name: item.Name,
|
||||
Period: item.Period,
|
||||
})
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get flock period summary successfully",
|
||||
Message: "Get kandang period summary successfully",
|
||||
Data: responseBody,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user