Merge pull request 'add status filter' (#2) from filter into main
Reviewed-on: ESLOGAD/eslogad-backend#2
This commit is contained in:
commit
4e58ce95fb
@ -30,6 +30,10 @@ type ContextInfo struct {
|
|||||||
UserName string
|
UserName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ContextInfo) IsSuperAdmin() bool {
|
||||||
|
return c.UserRole == "superadmin" || c.UserRole == "admin"
|
||||||
|
}
|
||||||
|
|
||||||
type ctxKeyType struct{}
|
type ctxKeyType struct{}
|
||||||
|
|
||||||
var ctxKey = ctxKeyType(struct{}{})
|
var ctxKey = ctxKeyType(struct{}{})
|
||||||
|
|||||||
@ -163,7 +163,6 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
|
|||||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||||
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
||||||
|
|
||||||
// Parse department_id
|
|
||||||
var departmentID *uuid.UUID
|
var departmentID *uuid.UUID
|
||||||
if departmentIDStr := c.Query("department_id"); departmentIDStr != "" {
|
if departmentIDStr := c.Query("department_id"); departmentIDStr != "" {
|
||||||
if id, err := uuid.Parse(departmentIDStr); err == nil {
|
if id, err := uuid.Parse(departmentIDStr); err == nil {
|
||||||
@ -171,7 +170,12 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse is_active
|
appCtx := appcontext.FromGinContext(c.Request.Context())
|
||||||
|
|
||||||
|
if !appCtx.IsSuperAdmin() {
|
||||||
|
departmentID = &appCtx.DepartmentID
|
||||||
|
}
|
||||||
|
|
||||||
var isActive *bool
|
var isActive *bool
|
||||||
if isActiveStr := c.Query("is_active"); isActiveStr != "" {
|
if isActiveStr := c.Query("is_active"); isActiveStr != "" {
|
||||||
if active, err := strconv.ParseBool(isActiveStr); err == nil {
|
if active, err := strconv.ParseBool(isActiveStr); err == nil {
|
||||||
@ -179,7 +183,6 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse search
|
|
||||||
var search *string
|
var search *string
|
||||||
if searchStr := c.Query("search"); searchStr != "" {
|
if searchStr := c.Query("search"); searchStr != "" {
|
||||||
search = &searchStr
|
search = &searchStr
|
||||||
@ -187,7 +190,7 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
|
|||||||
|
|
||||||
// Build request - pass PAGE, bukan OFFSET
|
// Build request - pass PAGE, bukan OFFSET
|
||||||
req := &contract.ListApprovalFlowsRequest{
|
req := &contract.ListApprovalFlowsRequest{
|
||||||
Page: page, // ✅ Pass page number
|
Page: page, // ✅ Pass page number
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
DepartmentID: departmentID,
|
DepartmentID: departmentID,
|
||||||
IsActive: isActive,
|
IsActive: isActive,
|
||||||
@ -198,7 +201,7 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlows(c *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{
|
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
Code: http.StatusInternalServerError,
|
Code: http.StatusInternalServerError,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -215,7 +218,7 @@ func (h *AdminApprovalFlowHandler) ListApprovalFlowsByDepartment(c *gin.Context)
|
|||||||
|
|
||||||
req := &contract.ListApprovalFlowsRequest{
|
req := &contract.ListApprovalFlowsRequest{
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
Page: offset,
|
Page: offset,
|
||||||
DepartmentID: &appCtx.DepartmentID,
|
DepartmentID: &appCtx.DepartmentID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user