Skip to content

Commit

Permalink
Updates to the ProjectService (#2)
Browse files Browse the repository at this point in the history
* Add the ParentRef to a Project

Signed-off-by: Duane May <duanemay@gmail.com>

* Add GetProjectsForName to ProjectService

Signed-off-by: Duane May <duanemay@gmail.com>

---------

Signed-off-by: Duane May <duanemay@gmail.com>
  • Loading branch information
duanemay committed Mar 17, 2023
1 parent e451b5e commit 91d8e79
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ type Project struct {
Tags []Tag `json:"tags,omitempty"`
Active bool `json:"active"`
Metrics ProjectMetrics `json:"metrics"`
ParentRef *ParentRef `json:"parent,omitempty"`
LastBOMImport int `json:"lastBomImport"`
}

type ParentRef struct {
UUID uuid.UUID `json:"uuid,omitempty"`
}

type ProjectService struct {
client *Client
}
Expand Down Expand Up @@ -57,6 +62,30 @@ func (ps ProjectService) GetAll(ctx context.Context, po PageOptions) (p Page[Pro
return
}

func (ps ProjectService) GetProjectsForName(ctx context.Context, name string, excludeInactive, onlyRoot bool) (p []Project, err error) {
excludeInactiveStr := "false"
onlyRootStr := "false"
if excludeInactive {
excludeInactiveStr = "true"
}
if onlyRoot {
onlyRootStr = "true"
}
params := map[string]string{
"name": name,
"excludeInactive": excludeInactiveStr,
"onlyRoot": onlyRootStr,
}

req, err := ps.client.newRequest(ctx, http.MethodGet, "/api/v1/project", withParams(params))
if err != nil {
return
}

_, err = ps.client.doRequest(req, &p)
return
}

func (ps ProjectService) Create(ctx context.Context, project Project) (p Project, err error) {
req, err := ps.client.newRequest(ctx, http.MethodPut, "/api/v1/project", withBody(project))
if err != nil {
Expand Down

0 comments on commit 91d8e79

Please sign in to comment.