Skip to content

Commit

Permalink
feat: add GetAllByTag to ProjectService (#6)
Browse files Browse the repository at this point in the history
* Add GetAllByTag to ProjectService

Signed-off-by: Mohamed Chiheb Ben Jemaa <mc.benjemaa@gmail.com>

* Change GetAllByTag to return Paging

Signed-off-by: Mohamed Chiheb Ben Jemaa <mc.benjemaa@gmail.com>

* change withPathParams to accept a map

Signed-off-by: Mohamed Chiheb Ben Jemaa <mc.benjemaa@gmail.com>

---------

Signed-off-by: Mohamed Chiheb Ben Jemaa <mc.benjemaa@gmail.com>
  • Loading branch information
mcbenjemaa committed Jul 3, 2023
1 parent a9bb240 commit bf2f1d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit bf2f1d8

Please sign in to comment.