add pagination approval flows

This commit is contained in:
efrilm
2025-10-10 19:02:52 +07:00
parent 239f052a9a
commit 3717b0b53c
5 changed files with 83 additions and 34 deletions
+23 -18
View File
@@ -159,42 +159,47 @@ func (h *AdminApprovalFlowHandler) DeleteApprovalFlow(c *gin.Context) {
}
func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
// Parse query params
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
offset := (page - 1) * limit
departmentIDStr := c.Query("department_id")
isActiveStr := c.Query("is_active")
// Parse department_id
var departmentID *uuid.UUID
var isActive *bool
if departmentIDStr != "" {
if departmentIDStr := c.Query("department_id"); departmentIDStr != "" {
if id, err := uuid.Parse(departmentIDStr); err == nil {
departmentID = &id
}
}
if isActiveStr != "" {
if isActiveStr == "true" {
active := true
isActive = &active
} else if isActiveStr == "false" {
active := false
// Parse is_active
var isActive *bool
if isActiveStr := c.Query("is_active"); isActiveStr != "" {
if active, err := strconv.ParseBool(isActiveStr); err == nil {
isActive = &active
}
}
// Parse search
var search *string
if searchStr := c.Query("search"); searchStr != "" {
search = &searchStr
}
// Build request - pass PAGE, bukan OFFSET
req := &contract.ListApprovalFlowsRequest{
Page: page, // ✅ Pass page number
Limit: limit,
Offset: offset,
DepartmentID: departmentID,
IsActive: isActive,
Search: search, // tambahkan ini juga
}
resp, err := h.svc.ListApprovalFlows(c.Request.Context(), req)
if err != nil {
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{Error: err.Error(), Code: http.StatusInternalServerError})
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{
Error: err.Error(),
Code: http.StatusInternalServerError,
})
return
}
@@ -210,7 +215,7 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlowsByDepartment(c *gin.Context)
req := &contract.ListApprovalFlowsRequest{
Limit: limit,
Offset: offset,
Page: offset,
DepartmentID: &appCtx.DepartmentID,
}