feat(service): add pagination to GetJobs endpoint

GetJobs now accepts page/page_size query parameters and returns JobListResponse instead of raw array. Uses in-memory pagination matching GetJobHistory pattern.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-10 15:14:56 +08:00
parent 35a4017b8e
commit 2cb6fbecdd
5 changed files with 155 additions and 14 deletions

View File

@@ -46,16 +46,30 @@ func (h *JobHandler) SubmitJob(c *gin.Context) {
server.Created(c, resp)
}
// GetJobs handles GET /api/v1/jobs.
// GetJobs handles GET /api/v1/jobs with pagination.
func (h *JobHandler) GetJobs(c *gin.Context) {
jobs, err := h.jobSvc.GetJobs(c.Request.Context())
var query model.JobListQuery
if err := c.ShouldBindQuery(&query); err != nil {
h.logger.Warn("bad request", zap.String("method", "GetJobs"), zap.String("error", "invalid query params"))
server.BadRequest(c, "invalid query params")
return
}
if query.Page < 1 {
query.Page = 1
}
if query.PageSize < 1 {
query.PageSize = 20
}
resp, err := h.jobSvc.GetJobs(c.Request.Context(), &query)
if err != nil {
h.logger.Error("handler error", zap.String("method", "GetJobs"), zap.Int("status", http.StatusInternalServerError), zap.Error(err))
server.InternalError(c, err.Error())
return
}
server.OK(c, jobs)
server.OK(c, resp)
}
// GetJob handles GET /api/v1/jobs/:id.