Skip to content
Snippets Groups Projects
Verified Commit 02aaf8a9 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

feat: make /imports a valid request without showId

parent e6072d9c
No related branches found
No related tags found
No related merge requests found
......@@ -19,17 +19,18 @@
package v1
import (
"gitlab.servus.at/autoradio/tank/importer"
"net/http"
"github.com/gin-gonic/gin"
)
// ListImportsOfShow returns a list of all running and pending imports for files belonging to this show.
// ListImportsOfShow returns a list of all running and pending imports for files belonging to a show if specified.
//
// @Summary List imports
// @Description Lists all running and pending imports
// @Produce json
// @Param showId query int true "ID of the show"
// @Param showId query int false "ID of the show"
// @Param limit query int false "Limit number of results"
// @Param offset query int false "Start listing from offset"
// @Success 200 {object} JobsListing
......@@ -38,24 +39,49 @@ import (
// @Failure 500 {object} ErrorResponse
// @Router /api/v1/imports [get]
func (api *API) ListImportsOfShow(c *gin.Context) {
showID, err := idFromString(c.Query("showId"))
if err != nil {
return
}
var err error
var jobs []*importer.Job
var showIDs []uint64
var showID uint64
if authorized, _ := authorizeRequestForShow(c, showID); !authorized {
return
if showId := c.Query("showId"); showId != "" {
if showID, err = idFromString(showId); err != nil {
c.JSON(http.StatusBadRequest, ErrorResponse{Error: "invalid showId: " + err.Error()})
return
} else {
if authorized, _ := authorizeRequestForShow(c, showID); !authorized {
return
}
}
} else {
if authorized, sess := authorizeRequestPrivilegedOrEntitled(c); !authorized {
return
} else {
if sess.Privileged {
showIDs = sess.PublicShows
}
if sess.Entitled {
showIDs = sess.Shows
}
}
}
offset, limit, ok := getPaginationParameter(c)
if !ok {
return
}
jobs, err := api.importer.ListJobs(showID, offset, limit)
if showID != 0 {
jobs, err = api.importer.ListJobsForShows([]uint64{showID}, offset, limit)
} else {
jobs, err = api.importer.ListJobsForShows(showIDs, offset, limit)
}
if err != nil {
sendError(c, err)
return
}
c.JSON(http.StatusOK, JobsListing{jobs})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment