-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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.
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.
// Look for a (sub)element with the company name | ||
.contains(companyName) | ||
// Return the containing company card element | ||
.parents('.company-card'); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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(); | ||
}); |
There was a problem hiding this comment.
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
.
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.
This adds a new
usersByCompany
endpoint which returns the users (just ID and name) grouped by company. It supports two modifiers:sortBy
andsortOrder
.sortBy
can be eithercompany
orcount
, andsortOrder
can be eitherasc
ordesc
.I had to create two new Java classes to capture the structure of these results.
UserGroupResult
(which should be renamed) holds the company (_id
), thecount
(how many users work for that company), andusers
(a list ofUserIdName
objects). TheUserIdName
objects just contain the_id
andname
of aUser
.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.