From 641959101ccc22ff9be030dd37668946f8b2a59b Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Tue, 15 Mar 2022 09:49:41 +0100 Subject: [PATCH] Add metadata to REST-API --- api/openapi.yaml | 3 +++ api/rest.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/api/openapi.yaml b/api/openapi.yaml index 6249f04..2babbf5 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -38,6 +38,9 @@ paths: - name: items-per-page in: query schema: { type: integer } + - name: with-metadata + in: query + schema: { type: boolean } responses: 200: description: 'Array of jobs' diff --git a/api/rest.go b/api/rest.go index eb031e6..ee83b6c 100644 --- a/api/rest.go +++ b/api/rest.go @@ -108,6 +108,7 @@ type TagJobApiRequest []*struct { // Return a list of jobs func (api *RestApi) getJobs(rw http.ResponseWriter, r *http.Request) { + withMetadata := false filter := &model.JobFilter{} page := &model.PageRequest{ItemsPerPage: -1, Page: 1} order := &model.OrderByInput{Field: "startTime", Order: model.SortDirectionEnumDesc} @@ -156,6 +157,8 @@ func (api *RestApi) getJobs(rw http.ResponseWriter, r *http.Request) { return } page.ItemsPerPage = x + case "with-metadata": + withMetadata = true default: http.Error(rw, "invalid query parameter: "+key, http.StatusBadRequest) return @@ -170,6 +173,13 @@ func (api *RestApi) getJobs(rw http.ResponseWriter, r *http.Request) { results := make([]*schema.JobMeta, 0, len(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{ ID: &job.ID, BaseJob: job.BaseJob,