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

Group users by company #81

Merged
merged 11 commits into from
Feb 13, 2024
Merged

Group users by company #81

merged 11 commits into from
Feb 13, 2024

Conversation

NicMcPhee
Copy link
Member

@NicMcPhee NicMcPhee commented Feb 12, 2024

This adds a new usersByCompany endpoint which returns the users (just ID and name) grouped by company. It supports two modifiers: sortBy and sortOrder. sortBy can be either company or count, and sortOrder can be either asc or desc.

I had to create two new Java classes to capture the structure of these results. UserGroupResult (which should be renamed) holds the company (_id), the count (how many users work for that company), and users (a list of UserIdName objects). The UserIdName objects just contain the _id and name of a User.

GitHub CoPilot was a huge help here, both in helping generate the queries, but also in debugging some IOException errors that were the result of mismatches between the structures being generated by the queries and my Java classes.

This adds a new `usersByCompany` endpoint which returns the users (just ID and name) grouped by company.

I had to create two new Java classes to capture the structure of these results. `UserGroupResult` (which should be renamed) holds the company (`_id`), the `count` (how many users work for that company), and `users` (a list of `UserIdName` objects). The `UserIdName` objects just contain the `_id` and `name` of a `User`.

GitHub CoPilot was a huge help here, both in helping generate the queries, but also in debugging some `IOException` errors that were the result of mismatches between the structures being generated by the queries and my Java classes.
@NicMcPhee NicMcPhee marked this pull request as draft February 12, 2024 05:18
Both `UserByCompany` and `UserIdName` have `public` fields (generally bad, but necessary for Jackson/MongoDB), so we needed to suppress the `VisibilityModifier` warning. We also needed to suppress the `MemberName` warning for `_id` since Mongo requires that name.
I think this gets the `getUsersGroupedByCompany` in a pretty solid place.
This adds several tests that check the behavior of the `getUsersGroupedByCompany` functionality.
This adds the necessary bits to the routing and the `AppComponent` so that we display the new company view.
This generated the initial stubs with `ng generate`, and then provided a simple implementation of the component and the HTML file.

This also adds the `Company` and `UserNameId` classes, which hold the necessary data.
I probably could have put this in a new `CompaniesService`, but I didn't want to mess with that right away. The fact that I ended up using `${enviornment.apiUrl}usersByCompany` instead of the `userUrl` probably is a strong argument that this should have been in a separate service.
I had hoped to fancy this up more (esp. the HTML), but it works and I need to go to bed.

The one really nice thing is that I was able to use a `Signal` in the component to avoid having any subscriptions anywhere!
This wasn't actually passing because I hadn't sorted out the dependency on `UserService` yet.
@NicMcPhee NicMcPhee marked this pull request as ready for review February 13, 2024 07:46
// Look for a (sub)element with the company name
.contains(companyName)
// Return the containing company card element
.parents('.company-card');
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I'm thrilled about this "go down to the company name" and then "go up one step to the .company-card approach, but I'm not sure of a better way.

<mat-card-content>
<ul class="company-card-users">
@for (user of this.company.users; track user._id) {
<li><span class="company-card-user-name">{{ user.name }}</span></li>
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't the most beautiful of UIs, and I'm sure we can make it nicer.


it('should create', () => {
expect(component).toBeTruthy();
});
Copy link
Member Author

@NicMcPhee NicMcPhee Feb 13, 2024

Choose a reason for hiding this comment

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

At the moment all this tests is that this can be successfully constructed. We might want more testing here, although it's not entirely clear what we'd test. There's no real logic in the component except for the call to the userService. I guess we should check that the value of companies has the same number as in testCompanies.

@NicMcPhee NicMcPhee requested a review from kklamberty February 13, 2024 07:55
@NicMcPhee NicMcPhee merged commit 59e3e44 into main Feb 13, 2024
4 checks passed
@NicMcPhee NicMcPhee deleted the group-users-by-company branch February 13, 2024 14:26
NicMcPhee added a commit to UMM-CSci-3601/3601-iteration-template that referenced this pull request Feb 22, 2024
This adds a new usersByCompany endpoint which returns the users (just ID and name) grouped by company. It supports two modifiers: sortBy and sortOrder. sortBy can be either company or count, and sortOrder can be either asc or desc.

I had to create two new Java classes to capture the structure of these results. UserGroupResult (which should be renamed) holds the company (_id), the count (how many users work for that company), and users (a list of UserIdName objects). The UserIdName objects just contain the _id and name of a User.

This is essentially a copy of the changes in PR 81 in Lab 4: UMM-CSci-3601/3601-lab4-mongo#81

GitHub CoPilot was a huge help here, both in helping generate the queries, but also in debugging some IOException errors that were the result of mismatches between the structures being generated by the queries and my Java classes.
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.

1 participant