Merge pull request #134 from hhu-propra2/fix-group-search-number-of-users
Fix group search number of users
This commit is contained in:
@ -199,12 +199,14 @@ public class WebController {
|
|||||||
Model model,
|
Model model,
|
||||||
@RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
|
@RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
List<Group> groupse = new ArrayList<>();
|
|
||||||
|
List<Group> groups = new ArrayList<>();
|
||||||
if (search != null) {
|
if (search != null) {
|
||||||
groupse = groupService.findGroupWith(search, account);
|
groups = groupService.findGroupWith(search, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("gruppen", groupse);
|
model.addAttribute("gruppen", groups);
|
||||||
return "search";
|
return "search";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,4 +31,13 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
|||||||
|
|
||||||
@Query("SELECT * FROM event WHERE event_type = :type")
|
@Query("SELECT * FROM event WHERE event_type = :type")
|
||||||
List<EventDTO> findAllEventsByType(@Param("type") String type);
|
List<EventDTO> findAllEventsByType(@Param("type") String type);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM event WHERE event_type = :type AND user_id = :userId")
|
||||||
|
List<EventDTO> findEventsByTypeAndUserId(@Param("type") String type, @Param("userId") String userId);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(*) FROM event WHERE event_type = :type AND group_id = :groupId")
|
||||||
|
Long countEventsByTypeAndGroupId(@Param("type") String type, @Param("groupId") String groupId);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(*) FROM event WHERE group_id = :groupId AND user_id = :userId AND event_type = :type")
|
||||||
|
Long countEventsByGroupIdAndUserIdAndEventType(@Param("groupId") String groupId, @Param("userId") String userId, @Param("type") String type);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,13 +127,13 @@ public class EventService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> findGroupIdsByUser(String userId) {
|
public List<UUID> findGroupIdsByUser(String userId) {
|
||||||
List<String> groupIDs = eventStore.findGroup_idsWhereUser_id(userId);
|
return eventStore.findGroup_idsWhereUser_id(userId).stream()
|
||||||
|
.map(UUID::fromString)
|
||||||
System.out.println(groupIDs);
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
return groupIDs.stream()
|
|
||||||
.map(UUID::fromString)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean userInGroup(UUID groupId, String userId) {
|
||||||
|
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent")
|
||||||
|
> eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,31 +69,37 @@ public class GroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sucht alle Zeilen in der DB mit visibility=true.
|
* Wird verwendet bei der Suche nach Gruppen: Titel, Beschreibung werden benötigt.
|
||||||
* Erstellt eine Liste aus öffentlichen Gruppen (ohen bereits beigetretenen Gruppen).
|
* Außerdem wird beachtet, ob der eingeloggte User bereits in entsprechenden Gruppen mitglied ist.
|
||||||
*
|
*
|
||||||
* @return Liste von projizierten Gruppen
|
* @return Liste von projizierten Gruppen
|
||||||
* @throws EventException Projektionsfehler
|
* @throws EventException Projektionsfehler
|
||||||
*/
|
*/
|
||||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||||
List<Group> visibleGroups = projectEventList(createEvents);
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
|
||||||
|
|
||||||
List<UUID> userGroupIds = eventService.findGroupIdsByUser(userId);
|
List<Group> visibleGroups = projectEventList(groupEvents);
|
||||||
|
|
||||||
return visibleGroups.parallelStream()
|
return visibleGroups.parallelStream()
|
||||||
.filter(group -> group.getType() != null)
|
.filter(group -> group.getType() != null)
|
||||||
.filter(group -> !userGroupIds.contains(group.getId()))
|
.filter(group -> !eventService.userInGroup(group.getId(), userId))
|
||||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wird verwendet beim Gruppe erstellen bei der Parent-Auswahl: nur Titel benötigt.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws EventException
|
||||||
|
*/
|
||||||
public List<Group> getAllLecturesWithVisibilityPublic() throws EventException {
|
public List<Group> getAllLecturesWithVisibilityPublic() throws EventException {
|
||||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||||
|
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||||
|
|
||||||
List<Group> visibleGroups = projectEventList(createEvents);
|
List<Group> visibleGroups = projectEventList(createEvents);
|
||||||
@ -115,6 +121,10 @@ public class GroupService {
|
|||||||
* @throws EventException Projektionsfehler
|
* @throws EventException Projektionsfehler
|
||||||
*/
|
*/
|
||||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||||
|
if (search.isEmpty()) {
|
||||||
|
return getAllGroupWithVisibilityPublic(account.getName());
|
||||||
|
}
|
||||||
|
|
||||||
return getAllGroupWithVisibilityPublic(account.getName())
|
return getAllGroupWithVisibilityPublic(account.getName())
|
||||||
.parallelStream()
|
.parallelStream()
|
||||||
.filter(group ->
|
.filter(group ->
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
<header>
|
<header>
|
||||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
|
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="active">
|
<li>
|
||||||
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||||
</li>
|
</li>
|
||||||
<li th:case="${true}">
|
<li th:case="${true}">
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<li th:case="${false}">
|
<li th:case="${false}">
|
||||||
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li class="active">
|
||||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -53,8 +53,8 @@
|
|||||||
<form method="post" action="/gruppen2/detailsBeitreten">
|
<form method="post" action="/gruppen2/detailsBeitreten">
|
||||||
<button class="btn btn-primary"
|
<button class="btn btn-primary"
|
||||||
style="background: #52a1eb; border-style: none;"
|
style="background: #52a1eb; border-style: none;"
|
||||||
th:href="@{/gruppen2/detailsBeitreten(id=${group.getId()})}"
|
th:href="@{/gruppen2/detailsBeitreten}"
|
||||||
th:name="id" th:value="${group.id}"
|
th:name="id" th:value="${group.getId()}"
|
||||||
type="submit">Gruppe beitreten
|
type="submit">Gruppe beitreten
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -49,23 +49,26 @@
|
|||||||
<br>
|
<br>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<!-- Erscheint dann, wenn man "Suchen" Button klickt und Ergebnisse angezeigt werden, aber so solls aussehen -->
|
<!-- Erscheint dann, wenn man "Suchen" Button klickt und Ergebnisse angezeigt werden, aber so solls aussehen -->
|
||||||
<thead th:if="${!gruppen.isEmpty()}">
|
<thead th:if='${!gruppen.isEmpty()}'>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Gruppenname</th>
|
<th scope="col">Gruppenname</th>
|
||||||
<th scope="col">Beschreibung</th>
|
<th scope="col">Beschreibung</th>
|
||||||
<th scope="col">Mitgliederanzahl</th>
|
<th scope="col">Max. Mitgliederanzahl</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr th:each="gruppe : ${gruppen}">
|
<tr th:each="gruppe : ${gruppen}" th:switch="${gruppe.getUserMaximum() != 100000}">
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}"
|
<a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}"
|
||||||
th:text="${gruppe.title}">Gruppenname</a>
|
th:text="${gruppe.getTitle()}">Gruppenname</a>
|
||||||
</th>
|
</th>
|
||||||
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">
|
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">
|
||||||
Beschreibung
|
Beschreibung
|
||||||
</td>
|
</td>
|
||||||
<td th:text="${gruppe.getMembers().size()}">Mitgliederanzahl</td>
|
<td th:case="${true}">
|
||||||
|
<a th:text="${gruppe.getUserMaximum()}"></a>
|
||||||
|
</td>
|
||||||
|
<td th:case="${false}">unbegrenzt</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user