40 lines
715 B
Go
Raw Permalink Normal View History

2024-04-10 22:10:09 +08:00
package handler
import (
"net/http"
"strconv"
2024-04-10 22:10:09 +08:00
"nf-repo/internal/interfaces"
"nf-repo/internal/model"
"nf-repo/internal/tool/rerr"
"github.com/loveuer/nf"
2024-04-10 22:10:09 +08:00
)
func handleCatalog(ctx *nf.Ctx, m interfaces.ManifestHandler) error {
if ctx.Method() != "GET" {
return rerr.Error(ctx, &rerr.RepositoryError{
Status: http.StatusBadRequest,
Code: "METHOD_UNKNOWN",
Message: "We don't understand your method + url",
})
}
nStr := ctx.Query("n")
n := 10000
if nStr != "" {
n, _ = strconv.Atoi(nStr)
}
var (
re *rerr.RepositoryError
list *model.Catalog
)
2024-04-15 18:02:54 +08:00
if list, re = m.Catalog(ctx.Request.Context(), n, 0, ""); re != nil {
2024-04-10 22:10:09 +08:00
return rerr.Error(ctx, re)
}
return ctx.JSON(list)
}