Add keywords filter to ListJobs function for enhanced job search
- Implemented a keywords filter in the ListJobs function to allow searching by job name and description. - Refactored enabled status handling to support multiple truthy and falsy values, improving flexibility in job retrieval. - Default behavior remains to show all records regardless of enabled status, ensuring no data is inadvertently filtered out.
This commit is contained in:
parent
71f7dcbbad
commit
e3d7d049cc
1 changed files with 24 additions and 4 deletions
|
|
@ -52,20 +52,40 @@ func ListJobs(c *gin.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add keywords filter if provided (search in name and description)
|
||||||
|
if keywords := c.Query("keywords"); keywords != "" {
|
||||||
|
param.Wheres = append(param.Wheres, model.QueryWhere{
|
||||||
|
Wheres: []model.QueryWhere{
|
||||||
|
{
|
||||||
|
Column: "name",
|
||||||
|
Value: "%" + keywords + "%",
|
||||||
|
OP: "like",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Column: "description",
|
||||||
|
Value: "%" + keywords + "%",
|
||||||
|
OP: "like",
|
||||||
|
Method: "orwhere",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Add enabled filter (default to show all for debugging)
|
// Add enabled filter (default to show all for debugging)
|
||||||
enabled := c.Query("enabled")
|
switch enabled := c.Query("enabled"); enabled {
|
||||||
if enabled == "true" {
|
case "true", "1", "yes", "on":
|
||||||
param.Wheres = append(param.Wheres, model.QueryWhere{
|
param.Wheres = append(param.Wheres, model.QueryWhere{
|
||||||
Column: "enabled",
|
Column: "enabled",
|
||||||
Value: true,
|
Value: true,
|
||||||
})
|
})
|
||||||
} else if enabled == "false" {
|
case "false", "0", "no", "off":
|
||||||
param.Wheres = append(param.Wheres, model.QueryWhere{
|
param.Wheres = append(param.Wheres, model.QueryWhere{
|
||||||
Column: "enabled",
|
Column: "enabled",
|
||||||
Value: false,
|
Value: false,
|
||||||
})
|
})
|
||||||
|
default:
|
||||||
|
// Default: show all records regardless of enabled status
|
||||||
}
|
}
|
||||||
// Default: show all records regardless of enabled status
|
|
||||||
|
|
||||||
// Call job.ListJobs function
|
// Call job.ListJobs function
|
||||||
result, err := job.ListJobs(param, page, pagesize)
|
result, err := job.ListJobs(param, page, pagesize)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue