diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2024-02-23 10:59:11 +0200 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2024-02-23 10:59:11 +0200 |
commit | be262805f44256192cadef27612ec49f5302deeb (patch) | |
tree | a65611cd4a92727f24d1995fff84fcd9387c3676 /pkg/app/handler | |
parent | use new go 1.22 mux for show maintainer (diff) | |
download | soko-be262805f44256192cadef27612ec49f5302deeb.tar.gz soko-be262805f44256192cadef27612ec49f5302deeb.tar.bz2 soko-be262805f44256192cadef27612ec49f5302deeb.zip |
maintainer: add simple JSON endpoint for projects info
Was requested by ago
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'pkg/app/handler')
-rw-r--r-- | pkg/app/handler/maintainer/show.go | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/pkg/app/handler/maintainer/show.go b/pkg/app/handler/maintainer/show.go index 8b66a18..67d81ad 100644 --- a/pkg/app/handler/maintainer/show.go +++ b/pkg/app/handler/maintainer/show.go @@ -1,6 +1,7 @@ package maintainer import ( + "encoding/json" "net/http" "soko/pkg/app/handler/packages/components" "soko/pkg/app/layout" @@ -210,7 +211,7 @@ func ShowStabilizationFile(w http.ResponseWriter, r *http.Request) { return q.Where("class = ?", "StableRequest"), nil }).Select() if err != nil { - http.NotFound(w, r) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } utils.StabilizationExport(w, pageName, gpackages) @@ -234,3 +235,35 @@ func ShowPackages(w http.ResponseWriter, r *http.Request) { show(packagesCount, &maintainer, "Packages", showPackages(gpackages, &maintainer)), ).Render(r.Context(), w) } + +func ShowInfoJson(w http.ResponseWriter, r *http.Request) { + maintainer, _, _, err := common(w, r) + if err != nil { + return + } + + var reply struct { + Email string `json:"email"` + Name string `json:"name"` + IsProject bool `json:"is_project"` + Members []string `json:"members"` + MemberOf []string `json:"member_of"` + } + + reply.Email = maintainer.Email + reply.Name = maintainer.Name + reply.IsProject = maintainer.Type == "project" + + for _, member := range maintainer.Project.Members { + reply.Members = append(reply.Members, member.Email) + } + for _, project := range maintainer.Projects { + reply.MemberOf = append(reply.MemberOf, project.Email) + } + + w.Header().Set("Content-Type", "application/json") + err = json.NewEncoder(w).Encode(reply) + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + } +} |