mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
add api summary and update status
This commit is contained in:
@@ -53,6 +53,81 @@ func (u *DailyChecklistController) GetAll(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (u *DailyChecklistController) GetSummary(c *fiber.Ctx) error {
|
||||
query := &validation.SummaryQuery{
|
||||
DateFrom: c.Query("date_from"),
|
||||
DateTo: c.Query("date_to"),
|
||||
Category: c.Query("category"),
|
||||
}
|
||||
|
||||
if query.DateFrom == "" || query.DateTo == "" {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "date_from and date_to are required")
|
||||
}
|
||||
|
||||
if kandangParam := c.Query("kandang_id"); kandangParam != "" {
|
||||
kandangID, err := strconv.ParseUint(kandangParam, 10, 64)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid kandang_id")
|
||||
}
|
||||
value := uint(kandangID)
|
||||
query.KandangID = &value
|
||||
}
|
||||
|
||||
result, err := u.DailyChecklistService.GetSummary(c, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
type summaryResponse struct {
|
||||
PerformanceOverview []dto.DailyChecklistPerformanceOverviewDTO `json:"performance_overview"`
|
||||
TrackingABK []dto.DailyChecklistSummaryDTO `json:"tracking_abk"`
|
||||
}
|
||||
|
||||
performanceMap := make(map[uint]*dto.DailyChecklistPerformanceOverviewDTO)
|
||||
tracking := make([]dto.DailyChecklistSummaryDTO, len(result))
|
||||
|
||||
for i, summary := range result {
|
||||
tracking[i] = dto.DailyChecklistSummaryDTO{
|
||||
EmployeeID: summary.EmployeeID,
|
||||
EmployeeName: summary.EmployeeName,
|
||||
KandangID: summary.KandangID,
|
||||
KandangName: summary.KandangName,
|
||||
TotalActivity: summary.TotalActivity,
|
||||
ActivityDone: summary.ActivityDone,
|
||||
ActivityLeft: summary.ActivityLeft,
|
||||
CompletionRate: summary.CompletionRate,
|
||||
LastActivity: summary.LastActivity,
|
||||
}
|
||||
|
||||
if _, ok := performanceMap[summary.EmployeeID]; !ok {
|
||||
performanceMap[summary.EmployeeID] = &dto.DailyChecklistPerformanceOverviewDTO{
|
||||
EmployeeID: summary.EmployeeID,
|
||||
EmployeeName: summary.EmployeeName,
|
||||
}
|
||||
}
|
||||
|
||||
performanceMap[summary.EmployeeID].TotalActivity += summary.TotalActivity
|
||||
performanceMap[summary.EmployeeID].ActivityDone += summary.ActivityDone
|
||||
performanceMap[summary.EmployeeID].ActivityLeft += summary.ActivityLeft
|
||||
}
|
||||
|
||||
performance := make([]dto.DailyChecklistPerformanceOverviewDTO, 0, len(performanceMap))
|
||||
for _, v := range performanceMap {
|
||||
performance = append(performance, *v)
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get daily checklist summary successfully",
|
||||
Data: summaryResponse{
|
||||
PerformanceOverview: performance,
|
||||
TrackingABK: tracking,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (u *DailyChecklistController) GetOne(c *fiber.Ctx) error {
|
||||
param := c.Params("idDailyChecklist")
|
||||
|
||||
@@ -98,7 +173,7 @@ func (u *DailyChecklistController) CreateOne(c *fiber.Ctx) error {
|
||||
|
||||
func (u *DailyChecklistController) UpdateOne(c *fiber.Ctx) error {
|
||||
req := new(validation.Update)
|
||||
param := c.Params("id")
|
||||
param := c.Params("idDailyChecklist")
|
||||
|
||||
id, err := strconv.Atoi(param)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user