mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-22 06:15:44 +00:00
Merge branch 'development' of https://gitlab.com/mbugroup/lti-api into dev/teguh
This commit is contained in:
@@ -517,27 +517,6 @@ func (s projectflockService) GetAvailableDocQuantity(ctx *fiber.Ctx, kandangID u
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// getProjectFlockClosingDate mengembalikan tanggal closing Project Flock jika sudah mencapai step SELESAI (Approved).
|
||||
// func (s projectflockService) getProjectFlockClosingDate(ctx context.Context, projectFlockID uint) (*time.Time, error) {
|
||||
// if projectFlockID == 0 || s.ApprovalSvc == nil {
|
||||
// return nil, nil
|
||||
// }
|
||||
|
||||
// latest, err := s.ApprovalSvc.LatestByTarget(ctx, utils.ApprovalWorkflowProjectFlock, projectFlockID, nil)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if latest == nil || latest.Action == nil || *latest.Action != entity.ApprovalActionApproved {
|
||||
// return nil, nil
|
||||
// }
|
||||
// if latest.StepNumber != uint16(utils.ProjectFlockStepSelesai) {
|
||||
// return nil, nil
|
||||
// }
|
||||
|
||||
// t := latest.ActionAt
|
||||
// return &t, nil
|
||||
// }
|
||||
|
||||
func (s projectflockService) GetProjectPeriods(c *fiber.Ctx, projectIDs []uint) (map[uint]int, error) {
|
||||
if len(projectIDs) == 0 {
|
||||
return map[uint]int{}, nil
|
||||
|
||||
@@ -36,6 +36,10 @@ func (u *UniformityController) GetAll(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
documents, err := u.UniformityService.MapDocuments(c, result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.SuccessWithPaginate[dto.UniformityListDTO]{
|
||||
@@ -53,7 +57,7 @@ func (u *UniformityController) GetAll(c *fiber.Ctx) error {
|
||||
"status": "Pengajuan",
|
||||
},
|
||||
},
|
||||
Data: dto.ToUniformityListDTOsWithStandard(result, standards),
|
||||
Data: dto.ToUniformityListDTOsWithStandard(result, standards, documents),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ type UniformityDetailDTO struct {
|
||||
Sampling UniformitySamplingDTO `json:"sampling"`
|
||||
Result UniformityResultDTO `json:"result"`
|
||||
Standard *UniformityStandardDTO `json:"standard"`
|
||||
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval"`
|
||||
UniformityDetails []UniformityDetailItemDTO `json:"uniformity_details"`
|
||||
}
|
||||
|
||||
@@ -63,6 +64,7 @@ type UniformityListDTO struct {
|
||||
LocationName string `json:"location_name"`
|
||||
FlockName string `json:"flock_name"`
|
||||
KandangName string `json:"kandang_name"`
|
||||
FileName string `json:"file_name"`
|
||||
AppliedAt *time.Time `json:"applied_at"`
|
||||
Week int `json:"week"`
|
||||
Status string `json:"status"`
|
||||
@@ -115,12 +117,19 @@ func ToUniformityDetailDTO(
|
||||
info.FileURL = documentURL
|
||||
}
|
||||
|
||||
var latestApproval *approvalDTO.ApprovalRelationDTO
|
||||
if entityData.LatestApproval != nil {
|
||||
mapped := approvalDTO.ToApprovalDTO(*entityData.LatestApproval)
|
||||
latestApproval = &mapped
|
||||
}
|
||||
|
||||
return UniformityDetailDTO{
|
||||
Id: entityData.Id,
|
||||
InfoUmum: info,
|
||||
Sampling: toUniformitySamplingDTO(calc),
|
||||
Result: toUniformityResultDTO(calc),
|
||||
Standard: standard,
|
||||
LatestApproval: latestApproval,
|
||||
UniformityDetails: toUniformityDetailItemsDTO(calc),
|
||||
}
|
||||
}
|
||||
@@ -163,9 +172,15 @@ func ToUniformityListDTOs(items []entity.ProjectFlockKandangUniformity) []Unifor
|
||||
func ToUniformityListDTOsWithStandard(
|
||||
items []entity.ProjectFlockKandangUniformity,
|
||||
standards map[uint]service.UniformityStandard,
|
||||
documentNames map[uint]string,
|
||||
) []UniformityListDTO {
|
||||
result := ToUniformityListDTOs(items)
|
||||
if len(result) == 0 || len(standards) == 0 {
|
||||
for i := range result {
|
||||
if name, ok := documentNames[result[i].Id]; ok {
|
||||
result[i].FileName = name
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -174,6 +189,9 @@ func ToUniformityListDTOsWithStandard(
|
||||
result[i].StandardMeanWeight = std.MeanWeight
|
||||
result[i].StandardUniformity = std.Uniformity
|
||||
}
|
||||
if name, ok := documentNames[result[i].Id]; ok {
|
||||
result[i].FileName = name
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ type UniformityService interface {
|
||||
GetSummary(ctx *fiber.Ctx, id uint) (*entity.ProjectFlockKandangUniformity, error)
|
||||
GetStandard(ctx *fiber.Ctx, uniformity *entity.ProjectFlockKandangUniformity) (*UniformityStandard, error)
|
||||
MapStandards(ctx *fiber.Ctx, items []entity.ProjectFlockKandangUniformity) (map[uint]UniformityStandard, error)
|
||||
MapDocuments(ctx *fiber.Ctx, items []entity.ProjectFlockKandangUniformity) (map[uint]string, error)
|
||||
CreateOne(ctx *fiber.Ctx, req *validation.Create, file *multipart.FileHeader, rows []BodyWeightExcelRow) (*entity.ProjectFlockKandangUniformity, error)
|
||||
UpdateOne(ctx *fiber.Ctx, req *validation.Update, id uint, file *multipart.FileHeader, rows []BodyWeightExcelRow) (*entity.ProjectFlockKandangUniformity, error)
|
||||
DeleteOne(ctx *fiber.Ctx, id uint) error
|
||||
@@ -189,6 +190,29 @@ func (s uniformityService) MapStandards(c *fiber.Ctx, items []entity.ProjectFloc
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s uniformityService) MapDocuments(c *fiber.Ctx, items []entity.ProjectFlockKandangUniformity) (map[uint]string, error) {
|
||||
if s.DocumentSvc == nil || len(items) == 0 {
|
||||
return map[uint]string{}, nil
|
||||
}
|
||||
|
||||
result := make(map[uint]string, len(items))
|
||||
for _, item := range items {
|
||||
if item.Id == 0 {
|
||||
continue
|
||||
}
|
||||
documents, err := s.DocumentSvc.ListByTarget(c.Context(), "UNIFORMITY", uint64(item.Id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(documents) == 0 {
|
||||
continue
|
||||
}
|
||||
result[item.Id] = documents[len(documents)-1].Name
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *uniformityService) CreateOne(c *fiber.Ctx, req *validation.Create, file *multipart.FileHeader, rows []BodyWeightExcelRow) (*entity.ProjectFlockKandangUniformity, error) {
|
||||
if err := s.Validate.Struct(req); err != nil {
|
||||
return nil, err
|
||||
@@ -649,7 +673,7 @@ func (s uniformityService) fetchUniformityDocument(ctx context.Context, uniformi
|
||||
return nil, "", fiber.NewError(fiber.StatusNotFound, "Uniformity document not found")
|
||||
}
|
||||
|
||||
document := documents[0]
|
||||
document := documents[len(documents)-1]
|
||||
url, err := s.DocumentSvc.PresignURL(ctx, document, 15*time.Minute)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
|
||||
Reference in New Issue
Block a user