mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Add metadata to REST-API
This commit is contained in:
parent
7be38277a9
commit
641959101c
@ -38,6 +38,9 @@ paths:
|
|||||||
- name: items-per-page
|
- name: items-per-page
|
||||||
in: query
|
in: query
|
||||||
schema: { type: integer }
|
schema: { type: integer }
|
||||||
|
- name: with-metadata
|
||||||
|
in: query
|
||||||
|
schema: { type: boolean }
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: 'Array of jobs'
|
description: 'Array of jobs'
|
||||||
|
10
api/rest.go
10
api/rest.go
@ -108,6 +108,7 @@ type TagJobApiRequest []*struct {
|
|||||||
|
|
||||||
// Return a list of jobs
|
// Return a list of jobs
|
||||||
func (api *RestApi) getJobs(rw http.ResponseWriter, r *http.Request) {
|
func (api *RestApi) getJobs(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
withMetadata := false
|
||||||
filter := &model.JobFilter{}
|
filter := &model.JobFilter{}
|
||||||
page := &model.PageRequest{ItemsPerPage: -1, Page: 1}
|
page := &model.PageRequest{ItemsPerPage: -1, Page: 1}
|
||||||
order := &model.OrderByInput{Field: "startTime", Order: model.SortDirectionEnumDesc}
|
order := &model.OrderByInput{Field: "startTime", Order: model.SortDirectionEnumDesc}
|
||||||
@ -156,6 +157,8 @@ func (api *RestApi) getJobs(rw http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
page.ItemsPerPage = x
|
page.ItemsPerPage = x
|
||||||
|
case "with-metadata":
|
||||||
|
withMetadata = true
|
||||||
default:
|
default:
|
||||||
http.Error(rw, "invalid query parameter: "+key, http.StatusBadRequest)
|
http.Error(rw, "invalid query parameter: "+key, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -170,6 +173,13 @@ func (api *RestApi) getJobs(rw http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
results := make([]*schema.JobMeta, 0, len(jobs))
|
results := make([]*schema.JobMeta, 0, len(jobs))
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
|
if withMetadata {
|
||||||
|
if _, err := api.JobRepository.FetchMetadata(job); err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res := &schema.JobMeta{
|
res := &schema.JobMeta{
|
||||||
ID: &job.ID,
|
ID: &job.ID,
|
||||||
BaseJob: job.BaseJob,
|
BaseJob: job.BaseJob,
|
||||||
|
Loading…
Reference in New Issue
Block a user