Skip to content

Commit bf2f1d8

Browse files
authored
feat: add GetAllByTag to ProjectService (#6)
* Add GetAllByTag to ProjectService Signed-off-by: Mohamed Chiheb Ben Jemaa <[email protected]> * Change GetAllByTag to return Paging Signed-off-by: Mohamed Chiheb Ben Jemaa <[email protected]> * change withPathParams to accept a map Signed-off-by: Mohamed Chiheb Ben Jemaa <[email protected]> --------- Signed-off-by: Mohamed Chiheb Ben Jemaa <[email protected]>
1 parent a9bb240 commit bf2f1d8

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ func withParams(params map[string]string) requestOption {
148148
}
149149
}
150150

151+
func withPathParams(params map[string]string) requestOption {
152+
return func(req *http.Request) error {
153+
if len(params) == 0 {
154+
return nil
155+
}
156+
157+
for k, v := range params {
158+
req.URL.Path = strings.Replace(req.URL.Path, fmt.Sprintf("{%s}", k), v, -1)
159+
}
160+
return nil
161+
}
162+
}
163+
151164
func withBody(body interface{}) requestOption {
152165
return func(req *http.Request) error {
153166
if body == nil {

project.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ func (ps ProjectService) Lookup(ctx context.Context, name, version string) (p Pr
141141
return
142142
}
143143

144+
func (ps ProjectService) GetAllByTag(ctx context.Context, tag string, po PageOptions) (p Page[Project], err error) {
145+
params := map[string]string{
146+
"tag": tag,
147+
}
148+
149+
req, err := ps.client.newRequest(ctx, http.MethodGet, "/api/v1/project/tag/{tag}", withPathParams(params), withPageOptions(po))
150+
if err != nil {
151+
return
152+
}
153+
154+
res, err := ps.client.doRequest(req, &p.Items)
155+
if err != nil {
156+
return
157+
}
158+
159+
p.TotalCount = res.TotalCount
160+
return
161+
}
162+
144163
type ProjectCloneRequest struct {
145164
ProjectUUID uuid.UUID `json:"project"`
146165
Version string `json:"version"`

0 commit comments

Comments
 (0)