Merge pull request 'add status filter' (#2) from filter into main

Reviewed-on: ESLOGAD/eslogad-backend#2
This commit is contained in:
altru 2025-10-13 01:00:45 +00:00
commit 4e58ce95fb
2 changed files with 17 additions and 10 deletions

View File

@ -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{}{})

View File

@ -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,
}