38 lines
877 B
Go
38 lines
877 B
Go
|
|
package job
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"haixun-backend/internal/svc"
|
||
|
|
"haixun-backend/internal/types"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListJobsLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListJobsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListJobsLogic {
|
||
|
|
return &ListJobsLogic{ctx: ctx, svcCtx: svcCtx}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListJobsLogic) ListJobs(req *types.ListJobsReq) (*types.JobListData, error) {
|
||
|
|
runs, total, page, pageSize, totalPages, err := l.svcCtx.Job.ListRuns(l.ctx, req.Scope, req.ScopeID, req.Page, req.PageSize)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
list := make([]types.JobData, 0, len(runs))
|
||
|
|
for _, run := range runs {
|
||
|
|
list = append(list, toJobData(run))
|
||
|
|
}
|
||
|
|
return &types.JobListData{
|
||
|
|
Pagination: types.PaginationData{
|
||
|
|
Total: total,
|
||
|
|
Page: page,
|
||
|
|
PageSize: pageSize,
|
||
|
|
TotalPages: totalPages,
|
||
|
|
},
|
||
|
|
List: list,
|
||
|
|
}, nil
|
||
|
|
}
|