Skip to content

Commit

Permalink
Merge pull request #169 from ctreminiom/feature/project-search-params
Browse files Browse the repository at this point in the history
🧱 Added more parameters on the ProjectParamsScheme
  • Loading branch information
ctreminiom authored Dec 27, 2022
2 parents fece2b6 + f527232 commit c55cb65
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 44 deletions.
24 changes: 22 additions & 2 deletions jira/internal/project_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ func (i *internalProjectImpl) Search(ctx context.Context, options *model.Project
params.Add("expand", strings.Join(options.Expand, ","))
}

if len(options.IDs) != 0 {
for _, id := range options.IDs {
params.Add("id", strconv.Itoa(id))
}
}

if len(options.Keys) != 0 {
for _, key := range options.Keys {
params.Add("keys", key)
}
}

if len(options.OrderBy) != 0 {
params.Add("orderBy", options.OrderBy)
}
Expand All @@ -209,8 +221,8 @@ func (i *internalProjectImpl) Search(ctx context.Context, options *model.Project
params.Add("query", options.Query)
}

if len(options.ProjectKeyType) != 0 {
params.Add("typeKey", options.ProjectKeyType)
if len(options.TypeKeys) != 0 {
params.Add("typeKey", strings.Join(options.TypeKeys, ","))
}

if options.CategoryID != 0 {
Expand All @@ -220,6 +232,14 @@ func (i *internalProjectImpl) Search(ctx context.Context, options *model.Project
if len(options.Action) != 0 {
params.Add("action", options.Action)
}

if len(options.Status) != 0 {
params.Add("status", strings.Join(options.Status, ","))
}

if len(options.Properties) != 0 {
params.Add("properties", strings.Join(options.Properties, ","))
}
}

endpoint := fmt.Sprintf("rest/api/%v/project/search?%v", i.version, params.Encode())
Expand Down
53 changes: 23 additions & 30 deletions jira/internal/project_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ func Test_internalProjectImpl_Create(t *testing.T) {

func Test_internalProjectImpl_Search(t *testing.T) {

mockedParams := &model.ProjectSearchOptionsScheme{
OrderBy: "category",
IDs: []int{10000, 10001},
Keys: []string{"PA", "PB"},
Query: "ADM",
TypeKeys: []string{"business", "service_desk"},
CategoryID: 48882,
Action: "view",
Status: []string{"live", "archived"},
Expand: []string{"description"},
Properties: []string{"data.is.completed?"},
PropertyQuery: "[thepropertykey].something.nested=1",
}

type fields struct {
c service.Client
version string
Expand All @@ -200,15 +214,8 @@ func Test_internalProjectImpl_Search(t *testing.T) {
name: "when the api version is v3",
fields: fields{version: "3"},
args: args{
ctx: context.TODO(),
options: &model.ProjectSearchOptionsScheme{
OrderBy: "category",
Query: "dummy project",
Action: "view",
ProjectKeyType: "[thepropertykey].something.nested=1",
CategoryID: 400,
Expand: []string{"description", "projectKeys"},
},
ctx: context.TODO(),
options: mockedParams,
startAt: 0,
maxResults: 50,
},
Expand All @@ -219,7 +226,7 @@ func Test_internalProjectImpl_Search(t *testing.T) {
client.On("NewRequest",
context.Background(),
http.MethodGet,
"rest/api/3/project/search?action=view&categoryId=400&expand=description%2CprojectKeys&maxResults=50&orderBy=category&query=dummy+project&startAt=0&typeKey=%5Bthepropertykey%5D.something.nested%3D1",
"rest/api/3/project/search?action=view&categoryId=48882&expand=description&id=10000&id=10001&keys=PA&keys=PB&maxResults=50&orderBy=category&properties=data.is.completed%3F&query=ADM&startAt=0&status=live%2Carchived&typeKey=business%2Cservice_desk",
nil).
Return(&http.Request{}, nil)

Expand All @@ -238,15 +245,8 @@ func Test_internalProjectImpl_Search(t *testing.T) {
name: "when the api version is v2",
fields: fields{version: "2"},
args: args{
ctx: context.TODO(),
options: &model.ProjectSearchOptionsScheme{
OrderBy: "category",
Query: "dummy project",
Action: "view",
ProjectKeyType: "[thepropertykey].something.nested=1",
CategoryID: 400,
Expand: []string{"description", "projectKeys"},
},
ctx: context.TODO(),
options: mockedParams,
startAt: 0,
maxResults: 50,
},
Expand All @@ -257,7 +257,7 @@ func Test_internalProjectImpl_Search(t *testing.T) {
client.On("NewRequest",
context.Background(),
http.MethodGet,
"rest/api/2/project/search?action=view&categoryId=400&expand=description%2CprojectKeys&maxResults=50&orderBy=category&query=dummy+project&startAt=0&typeKey=%5Bthepropertykey%5D.something.nested%3D1",
"rest/api/2/project/search?action=view&categoryId=48882&expand=description&id=10000&id=10001&keys=PA&keys=PB&maxResults=50&orderBy=category&properties=data.is.completed%3F&query=ADM&startAt=0&status=live%2Carchived&typeKey=business%2Cservice_desk",
nil).
Return(&http.Request{}, nil)

Expand All @@ -276,15 +276,8 @@ func Test_internalProjectImpl_Search(t *testing.T) {
name: "when the http request cannot be created",
fields: fields{version: "3"},
args: args{
ctx: context.TODO(),
options: &model.ProjectSearchOptionsScheme{
OrderBy: "category",
Query: "dummy project",
Action: "view",
ProjectKeyType: "[thepropertykey].something.nested=1",
CategoryID: 400,
Expand: []string{"description", "projectKeys"},
},
ctx: context.TODO(),
options: mockedParams,
startAt: 0,
maxResults: 50,
},
Expand All @@ -295,7 +288,7 @@ func Test_internalProjectImpl_Search(t *testing.T) {
client.On("NewRequest",
context.Background(),
http.MethodGet,
"rest/api/3/project/search?action=view&categoryId=400&expand=description%2CprojectKeys&maxResults=50&orderBy=category&query=dummy+project&startAt=0&typeKey=%5Bthepropertykey%5D.something.nested%3D1",
"rest/api/3/project/search?action=view&categoryId=48882&expand=description&id=10000&id=10001&keys=PA&keys=PB&maxResults=50&orderBy=category&properties=data.is.completed%3F&query=ADM&startAt=0&status=live%2Carchived&typeKey=business%2Cservice_desk",
nil).
Return(&http.Request{}, errors.New("error, unable to create the http request"))

Expand Down
12 changes: 6 additions & 6 deletions pkg/infra/models/confluence_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ type ContentExtensionScheme struct {
}

type BodyScheme struct {
View *BodyNodeScheme `json:"view"`
ExportView *BodyNodeScheme `json:"export_view"`
StyledView *BodyNodeScheme `json:"styled_view"`
Storage *BodyNodeScheme `json:"storage"`
Editor2 *BodyNodeScheme `json:"editor2"`
AnonymousExportView *BodyNodeScheme `json:"anonymous_export_view"`
View *BodyNodeScheme `json:"view,omitempty"`
ExportView *BodyNodeScheme `json:"export_view,omitempty"`
StyledView *BodyNodeScheme `json:"styled_view,omitempty"`
Storage *BodyNodeScheme `json:"storage,omitempty"`
Editor2 *BodyNodeScheme `json:"editor2,omitempty"`
AnonymousExportView *BodyNodeScheme `json:"anonymous_export_view,omitempty"`
}

type BodyNodeScheme struct {
Expand Down
51 changes: 45 additions & 6 deletions pkg/infra/models/jira_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,51 @@ type NewProjectCreatedScheme struct {
}

type ProjectSearchOptionsScheme struct {
OrderBy string
Query string
Action string
ProjectKeyType string
CategoryID int
Expand []string
OrderBy string

// The project IDs to filter the results by.
// To include multiple IDs, provide an ampersand-separated list.
IDs []int

// The project keys to filter the results by.
// To include multiple keys, provide an ampersand-separated list.
Keys []string

// Filter the results using a literal string.
// Projects with a matching key or name are returned (case-insensitive).
Query string

// Orders results by the project type.
// This parameter accepts a comma-separated list.
// Valid values are business, service_desk, and software.
TypeKeys []string

// The ID of the project's category.
// A complete list of category IDs is found using the Get all project categories operation.
CategoryID int

Action string

// EXPERIMENTAL. Filter results by project status:
// 1. live: Search live projects.
// 2. archived: Search archived projects.
// 3. deleted: Search deleted projects, those in the recycle bin.
Status []string

// Use expand to include additional information in the response.
// This parameter accepts a comma-separated list.
Expand []string

// EXPERIMENTAL. A list of project properties to return for the project.
// This parameter accepts a comma-separated list.
Properties []string

// EXPERIMENTAL. A query string used to search properties.
// The query string cannot be specified using a JSON object.
// For example, to search for the value of nested from {"something":{"nested":1,"other":2}}
// use [thepropertykey].something.nested=1.
// Note that thepropertykey is only returned when included in properties.
PropertyQuery string
}

type ProjectSearchScheme struct {
Expand Down

0 comments on commit c55cb65

Please sign in to comment.