55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
|
// Use of this source code is governed by the Drone Non-Commercial License
|
|
// that can be found in the LICENSE file.
|
|
|
|
// +build !oss
|
|
|
|
package card
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/drone/drone/core"
|
|
"github.com/drone/drone/handler/api/render"
|
|
|
|
"github.com/go-chi/chi"
|
|
)
|
|
|
|
// HandleFindAll returns an http.HandlerFunc that writes a json-encoded
|
|
func HandleFindAll(
|
|
buildStore core.BuildStore,
|
|
cardStore core.CardStore,
|
|
repoStore core.RepositoryStore,
|
|
) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var (
|
|
namespace = chi.URLParam(r, "owner")
|
|
name = chi.URLParam(r, "name")
|
|
)
|
|
|
|
buildNumber, err := strconv.ParseInt(chi.URLParam(r, "build"), 10, 64)
|
|
if err != nil {
|
|
render.BadRequest(w, err)
|
|
return
|
|
}
|
|
|
|
repo, err := repoStore.FindName(r.Context(), namespace, name)
|
|
if err != nil {
|
|
render.NotFound(w, err)
|
|
return
|
|
}
|
|
build, err := buildStore.FindNumber(r.Context(), repo.ID, buildNumber)
|
|
if err != nil {
|
|
render.NotFound(w, err)
|
|
return
|
|
}
|
|
|
|
list, err := cardStore.FindCardByBuild(r.Context(), build.ID)
|
|
if err != nil {
|
|
render.NotFound(w, err)
|
|
return
|
|
}
|
|
render.JSON(w, list, 200)
|
|
}
|
|
}
|