Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change ListProjects API to request with multiple organizations #810

Merged
merged 5 commits into from
Feb 9, 2024

Conversation

kakcy
Copy link
Contributor

@kakcy kakcy commented Feb 8, 2024

This pull request primarily focuses on modifying the way organization IDs are handled in the project listing functionality. The changes allow for handling multiple organization IDs instead of a single one. This is achieved by replacing the organization_id field with organization_ids in various files and functions. The changes also include updates to related tests to accommodate this new functionality.

Here are the key changes:

Changes to Organization ID Handling:

  • pkg/account/api/api.go: The listProjectsByOrganizationID method in the AccountService struct now accepts a slice of organization IDs instead of a single one.
  • pkg/environment/api/project.go: The ListProjects method in the EnvironmentService struct has been updated to handle a slice of organization IDs.
  • proto/environment/service.proto: The ListProjectsRequest message now includes a repeated field organization_ids instead of a single organization_id.

Updates to Tests:

Changes in UI Code:

@@ -118,7 +118,7 @@ message ListProjectsRequest {
OrderDirection order_direction = 4;
string search_keyword = 5;
google.protobuf.BoolValue disabled = 6;
string organization_id = 7;
repeated string organization_ids = 7;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. Is this API not used by any other services? If it is, we need to add a new field instead of modify it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already checked with him.
He is aware of breaking change, but since there is no place on the console that uses this property, there is no need to add a new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He is aware of breaking change, but since there is no place on the console that uses this property, there is no need to add a new one.

Thank you for review.
Same understanding as above.

defer cancel()
c := newEnvironmentClient(t)
defer c.Close()
pageSize := int64(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we want to test two or more organizations, we must set the pageSize above 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to get two organization IDs.
ada5e82

if err != nil {
t.Fatal(err)
}
length := int(math.Min(float64(len(orgResp.Organizations)), 2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
length := int(math.Min(float64(len(orgResp.Organizations)), 2))
length := int(math.Min(float64(len(orgResp.Organizations)), pageSize))

@@ -118,7 +118,7 @@ message ListProjectsRequest {
OrderDirection order_direction = 4;
string search_keyword = 5;
google.protobuf.BoolValue disabled = 6;
string organization_id = 7;
repeated string organization_ids = 7;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already checked with him.
He is aware of breaking change, but since there is no place on the console that uses this property, there is no need to add a new one.

@@ -120,8 +120,12 @@ func (s *EnvironmentService) ListProjects(
return nil, err
}
whereParts := []mysql.WherePart{}
if req.OrganizationId != "" {
whereParts = append(whereParts, mysql.NewFilter("organization_id", "=", req.OrganizationId))
if req.OrganizationIds != nil && len(req.OrganizationIds) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The len also checks for nil.

Suggested change
if req.OrganizationIds != nil && len(req.OrganizationIds) > 0 {
if len(req.OrganizationIds) > 0 {

if req.OrganizationId != "" {
whereParts = append(whereParts, mysql.NewFilter("organization_id", "=", req.OrganizationId))
if req.OrganizationIds != nil && len(req.OrganizationIds) > 0 {
oIDs := make([]interface{}, 0, len(req.OrganizationIds))
Copy link
Member

@cre8ivejp cre8ivejp Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor this by creating a new function, convToInterfaceSlice.

E.g.

func convToInterfaceSlice(
slice []string,
) []interface{} {
result := make([]interface{}, 0, len(slice))
for _, element := range slice {
result = append(result, element)
}
return result
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added convToInterfaceSlice()and modified it to convert Organization IDs using that function.
b462fb9

}
}
if !found {
t.Fatalf("received a project of a not request organization expected: %v, actual: %v", orgIds, project.OrganizationId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%s for string.

Suggested change
t.Fatalf("received a project of a not request organization expected: %v, actual: %v", orgIds, project.OrganizationId)
t.Fatalf("received a project of a not request organization expected: %v, actual: %s", orgIds, project.OrganizationId)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed a specifier for variable strings.
bcb4b3a

@kakcy
Copy link
Contributor Author

kakcy commented Feb 9, 2024

Thank you for your review!
I have corrected the points you pointed out, so please review them.

@cre8ivejp cre8ivejp changed the title refactor: change ListProjects API to request with multiple organizations chore: change ListProjects API to request with multiple organizations Feb 9, 2024
Copy link
Member

@cre8ivejp cre8ivejp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

When you merge, please use the following commit message.

chore: change ListProjects API to request with multiple organizations

@kakcy
Copy link
Contributor Author

kakcy commented Feb 9, 2024

Thank you for reviews!

@kakcy kakcy merged commit 9a6f9fc into main Feb 9, 2024
16 checks passed
@kakcy kakcy deleted the change-list-projects-api branch February 9, 2024 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants