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:
@ -199,10 +199,12 @@ public class WebController {
|
||||
Model model,
|
||||
@RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
List<Group> groups = new ArrayList<>();
|
||||
if (search != null) {
|
||||
groups = groupService.findGroupWith(search, account);
|
||||
}
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", groups);
|
||||
return "search";
|
||||
|
||||
@ -34,4 +34,10 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@ -132,4 +132,8 @@ public class EventService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean userInGroup(UUID groupId, String userId) {
|
||||
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent")
|
||||
> eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
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("UpdateUserMaxEvent")));
|
||||
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findEventsByTypeAndUserId("AddUserEvent", userId)));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findEventsByTypeAndUserId("DeleteUserEvent", userId)));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(groupEvents);
|
||||
|
||||
User currentUserDummy = new User(userId, null, null, null);
|
||||
|
||||
return visibleGroups.parallelStream()
|
||||
.filter(group -> group.getType() != null)
|
||||
.filter(group -> !group.getMembers().contains(currentUserDummy))
|
||||
.filter(group -> !eventService.userInGroup(group.getId(), userId))
|
||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,6 +121,10 @@ public class GroupService {
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||
if (search.isEmpty()) {
|
||||
return getAllGroupWithVisibilityPublic(account.getName());
|
||||
}
|
||||
|
||||
return getAllGroupWithVisibilityPublic(account.getName())
|
||||
.parallelStream()
|
||||
.filter(group ->
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
<tr>
|
||||
<th scope="col">Gruppenname</th>
|
||||
<th scope="col">Beschreibung</th>
|
||||
<th scope="col">Mitgliederanzahl</th>
|
||||
<th scope="col">Max. Mitgliederanzahl</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -66,8 +66,6 @@
|
||||
Beschreibung
|
||||
</td>
|
||||
<td th:case="${true}">
|
||||
<a th:text="${gruppe.getMembers().size()}"></a>
|
||||
<a>/</a>
|
||||
<a th:text="${gruppe.getUserMaximum()}"></a>
|
||||
</td>
|
||||
<td th:case="${false}">unbegrenzt</td>
|
||||
|
||||
Reference in New Issue
Block a user