Skip to content
Snippets Groups Projects
Commit ef20b57c authored by dmz39's avatar dmz39
Browse files

Updating groups admin panel to include the number of users in each group

parent 45e015d5
Branches
No related tags found
No related merge requests found
......@@ -79,6 +79,11 @@ public class AdminController {
if (currentUser != null && this.userService.isAllowedAdminPanel(currentUser)) {
List<Group> groups = this.groupService.getGroups();
model.addAttribute("groups", groups);
Map<Long, Integer> groupMap = new HashMap<>();
for (Group group : this.groupService.getGroups()) {
groupMap.put(group.getGroupId(), this.userService.getNumUsersInGroup(group.getGroupId()));
}
model.addAttribute("groupMap", groupMap);
return "admin/groups";
} else {
return "admin/access_denied";
......
......
......@@ -10,4 +10,5 @@ public interface UserRepository extends CrudRepository<UserEntity, Long> {
List<UserEntity> findByLastName(String lastName);
UserEntity findById(long id);
UserEntity findByExternalId(long externalId);
int countByGroupId(long groupId);
}
......@@ -18,6 +18,7 @@ public interface UserService {
void saveUser(UserEntity user, UserEntity newUser);
void removeUser(long id);
int getNumUsersInGroup(long groupId);
boolean isAllowedAdminPanel(UserEntity userEntity);
void changeGroupId(Long userid, Long groupId);
......
......
......@@ -112,6 +112,10 @@ public class UserServiceImpl implements UserService {
}
}
@Override
public int getNumUsersInGroup(long groupId) {
return this.userRepo.countByGroupId(groupId);
}
@Override
public List<Address> getBillingAddresses(OAuth2User principal) {
......
......
......@@ -31,6 +31,7 @@
<th class="th-sm">Group ID</th>
<th class="th-sm">Group Name</th>
<th class="th-sm">Group Type</th>
<th class="th-sm"># Users</th>
<th class="th-sm">Details</th>
<th class="th-sm">Delete</th>
</tr>
......@@ -40,6 +41,7 @@
<td th:text="${group.getGroupId()}"></td>
<td th:text="${group.getGroupName()}"></td>
<td th:text="${group.getGroupType()}"></td>
<td th:text="${groupMap.get(group.getGroupId())}"></td>
<td><button class="btn btn-primary" th:type="button">Details</button></td>
<td><button class="btn btn-primary" th:type="button">&times;</button></td>
</tr>
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment