repo.me/internal/handler/catalog.go
2024-04-14 21:48:27 +08:00

38 lines
709 B
Go

package handler
import (
"github.com/loveuer/nf"
"net/http"
"nf-repo/internal/interfaces"
"nf-repo/internal/model"
"nf-repo/internal/util/rerr"
"strconv"
)
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
)
if list, re = m.Catelog(ctx.Request.Context(), n, 0); re != nil {
return rerr.Error(ctx, re)
}
return ctx.JSON(list)
}