mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
Merge branch 'development' of https://gitlab.com/mbugroup/lti-api into fix/BE/Purchase-edit-qty
This commit is contained in:
@@ -28,10 +28,31 @@ func NewClosingController(closingService service.ClosingService, sapronakService
|
||||
}
|
||||
|
||||
func (u *ClosingController) GetAll(c *fiber.Ctx) error {
|
||||
var projectStatus *int
|
||||
if raw := c.Query("project_status"); raw != "" {
|
||||
statusValue, err := strconv.Atoi(raw)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid project_status")
|
||||
}
|
||||
projectStatus = &statusValue
|
||||
}
|
||||
|
||||
var locationID *uint
|
||||
if raw := c.Query("location_id"); raw != "" {
|
||||
locationValue, err := strconv.Atoi(raw)
|
||||
if err != nil || locationValue <= 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid location_id")
|
||||
}
|
||||
locationUint := uint(locationValue)
|
||||
locationID = &locationUint
|
||||
}
|
||||
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
ProjectStatus: projectStatus,
|
||||
LocationID: locationID,
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
|
||||
@@ -99,9 +99,31 @@ func (s closingService) GetAll(c *fiber.Ctx, params *validation.Query) ([]dto.Cl
|
||||
}
|
||||
|
||||
offset := (params.Page - 1) * params.Limit
|
||||
statusFilter := ""
|
||||
if params.ProjectStatus != nil {
|
||||
switch *params.ProjectStatus {
|
||||
case 1:
|
||||
statusFilter = "Pengajuan"
|
||||
case 2:
|
||||
statusFilter = "Aktif"
|
||||
}
|
||||
}
|
||||
|
||||
closings, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
||||
db = s.withClosingRelations(db)
|
||||
if params.LocationID != nil {
|
||||
db = db.Where("location_id = ?", *params.LocationID)
|
||||
}
|
||||
if statusFilter != "" {
|
||||
latestApprovalSubQuery := s.Repository.DB().
|
||||
WithContext(c.Context()).
|
||||
Table("approvals").
|
||||
Select("DISTINCT ON (approvable_id) approvable_id, step_name, id").
|
||||
Where("approvable_type = ?", utils.ApprovalWorkflowProjectFlock.String()).
|
||||
Order("approvable_id, id DESC")
|
||||
db = db.Joins("JOIN (?) AS latest_approval ON latest_approval.approvable_id = project_flocks.id", latestApprovalSubQuery).
|
||||
Where("LOWER(latest_approval.step_name) = LOWER(?)", statusFilter)
|
||||
}
|
||||
if params.Search != "" {
|
||||
return db.Where("flock_name ILIKE ?", "%"+params.Search+"%")
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ type Update struct {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
ProjectStatus *int `query:"project_status" validate:"omitempty,oneof=1 2"`
|
||||
LocationID *uint `query:"location_id" validate:"omitempty,gt=0"`
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user