1

partial fix search: max user anzahl display

Co-authored-by: [Mahgs] <maxoerter@gmx.de>
Co-authored-by: Christoph <tobi@urpost.de>
Co-authored-by: XXNitram <matti.55@hotmail.de>
This commit is contained in:
Christoph
2020-03-25 14:46:02 +01:00
parent 473d58ae3b
commit 22ae8a81dc
5 changed files with 20 additions and 13 deletions

View File

@ -199,10 +199,12 @@ 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> groups = new ArrayList<>(); List<Group> groups = new ArrayList<>();
if (search != null) { if (search != null) {
groups = groupService.findGroupWith(search, account); groups = groupService.findGroupWith(search, account);
} }
model.addAttribute("account", account); model.addAttribute("account", account);
model.addAttribute("gruppen", groups); model.addAttribute("gruppen", groups);
return "search"; return "search";

View File

@ -34,4 +34,10 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("SELECT * FROM event WHERE event_type = :type AND user_id = :userId") @Query("SELECT * FROM event WHERE event_type = :type AND user_id = :userId")
List<EventDTO> findEventsByTypeAndUserId(@Param("type") String type, @Param("userId") String 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);
} }

View File

@ -132,4 +132,8 @@ public class EventService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public boolean userInGroup(UUID groupId, String userId) {
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent")
> eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
}
} }

View File

@ -2,7 +2,6 @@ package mops.gruppen2.service;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility; import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.dto.EventDTO; import mops.gruppen2.domain.dto.EventDTO;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
@ -83,19 +82,13 @@ public class GroupService {
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent"))); groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent"))); groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findEventsByTypeAndUserId("AddUserEvent", userId)));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findEventsByTypeAndUserId("DeleteUserEvent", userId)));
List<Group> visibleGroups = projectEventList(groupEvents); List<Group> visibleGroups = projectEventList(groupEvents);
User currentUserDummy = new User(userId, null, null, null);
return visibleGroups.parallelStream() return visibleGroups.parallelStream()
.filter(group -> group.getType() != null) .filter(group -> group.getType() != null)
.filter(group -> !group.getMembers().contains(currentUserDummy)) .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());
} }
/** /**
@ -128,11 +121,15 @@ 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 ->
group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getTitle().toLowerCase().contains(search.toLowerCase()) ||
group.getDescription().toLowerCase().contains(search.toLowerCase())) group.getDescription().toLowerCase().contains(search.toLowerCase()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -53,7 +53,7 @@
<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>
@ -66,8 +66,6 @@
Beschreibung Beschreibung
</td> </td>
<td th:case="${true}"> <td th:case="${true}">
<a th:text="${gruppe.getMembers().size()}"></a>
<a>/</a>
<a th:text="${gruppe.getUserMaximum()}"></a> <a th:text="${gruppe.getUserMaximum()}"></a>
</td> </td>
<td th:case="${false}">unbegrenzt</td> <td th:case="${false}">unbegrenzt</td>