add status filter
This commit is contained in:
parent
e67b9a357f
commit
1a9cc40c7f
@ -30,6 +30,10 @@ type ContextInfo struct {
|
||||
UserName string
|
||||
}
|
||||
|
||||
func (c *ContextInfo) IsSuperAdmin() bool {
|
||||
return c.UserRole == "superadmin" || c.UserRole == "admin"
|
||||
}
|
||||
|
||||
type ctxKeyType struct{}
|
||||
|
||||
var ctxKey = ctxKeyType(struct{}{})
|
||||
|
||||
@ -162,24 +162,27 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
|
||||
// Parse query params
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
||||
|
||||
// Parse department_id
|
||||
|
||||
var departmentID *uuid.UUID
|
||||
if departmentIDStr := c.Query("department_id"); departmentIDStr != "" {
|
||||
if id, err := uuid.Parse(departmentIDStr); err == nil {
|
||||
departmentID = &id
|
||||
}
|
||||
}
|
||||
|
||||
// Parse is_active
|
||||
|
||||
appCtx := appcontext.FromGinContext(c.Request.Context())
|
||||
|
||||
if !appCtx.IsSuperAdmin() {
|
||||
departmentID = &appCtx.DepartmentID
|
||||
}
|
||||
|
||||
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
|
||||
@ -187,7 +190,7 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
|
||||
|
||||
// Build request - pass PAGE, bukan OFFSET
|
||||
req := &contract.ListApprovalFlowsRequest{
|
||||
Page: page, // ✅ Pass page number
|
||||
Page: page, // ✅ Pass page number
|
||||
Limit: limit,
|
||||
DepartmentID: departmentID,
|
||||
IsActive: isActive,
|
||||
@ -197,8 +200,8 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
|
||||
resp, err := h.svc.ListApprovalFlows(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{
|
||||
Error: err.Error(),
|
||||
Code: http.StatusInternalServerError,
|
||||
Error: err.Error(),
|
||||
Code: http.StatusInternalServerError,
|
||||
})
|
||||
return
|
||||
}
|
||||
@ -215,7 +218,7 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlowsByDepartment(c *gin.Context)
|
||||
|
||||
req := &contract.ListApprovalFlowsRequest{
|
||||
Limit: limit,
|
||||
Page: offset,
|
||||
Page: offset,
|
||||
DepartmentID: &appCtx.DepartmentID,
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user