diff --git a/client.go b/client.go index 166ab69..bc9387e 100644 --- a/client.go +++ b/client.go @@ -148,6 +148,19 @@ func withParams(params map[string]string) requestOption { } } +func withPathParams(params map[string]string) requestOption { + return func(req *http.Request) error { + if len(params) == 0 { + return nil + } + + for k, v := range params { + req.URL.Path = strings.Replace(req.URL.Path, fmt.Sprintf("{%s}", k), v, -1) + } + return nil + } +} + func withBody(body interface{}) requestOption { return func(req *http.Request) error { if body == nil { diff --git a/project.go b/project.go index e9be0f7..fb82c9e 100644 --- a/project.go +++ b/project.go @@ -141,6 +141,25 @@ func (ps ProjectService) Lookup(ctx context.Context, name, version string) (p Pr return } +func (ps ProjectService) GetAllByTag(ctx context.Context, tag string, po PageOptions) (p Page[Project], err error) { + params := map[string]string{ + "tag": tag, + } + + req, err := ps.client.newRequest(ctx, http.MethodGet, "/api/v1/project/tag/{tag}", withPathParams(params), withPageOptions(po)) + if err != nil { + return + } + + res, err := ps.client.doRequest(req, &p.Items) + if err != nil { + return + } + + p.TotalCount = res.TotalCount + return +} + type ProjectCloneRequest struct { ProjectUUID uuid.UUID `json:"project"` Version string `json:"version"`