@ -99,9 +99,10 @@ public class Gruppen2Controller {
|
|||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@GetMapping("/findGroup")
|
@GetMapping("/findGroup")
|
||||||
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String suchbegriff) throws EventException {
|
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String suchbegriff) throws EventException {
|
||||||
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
List<Group> groupse = new ArrayList<>();
|
List<Group> groupse = new ArrayList<>();
|
||||||
if (suchbegriff != null) {
|
if (suchbegriff != null) {
|
||||||
groupse = groupService.findGroupWith(suchbegriff);
|
groupse = groupService.findGroupWith(suchbegriff,account);
|
||||||
}
|
}
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
model.addAttribute("gruppen", groupse);
|
model.addAttribute("gruppen", groupse);
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import mops.gruppen2.domain.Group;
|
|||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -71,15 +72,21 @@ public class GroupService {
|
|||||||
return groups.get(group_id);
|
return groups.get(group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Long> removeUserGroups(List<Long> group_ids, List<Long> user_groups) {
|
||||||
|
for (Long group_id: user_groups) {
|
||||||
|
group_ids.remove(group_id);
|
||||||
|
}
|
||||||
|
return group_ids;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sucht alle Zeilen in der DB wo die Visibility gleich true ist und wandelt diese in
|
* sucht alle Zeilen in der DB wo die Visibility true ist und entfernt alle Gruppen des Users.
|
||||||
* eine Liste von Gruppen
|
* Erstellt eine Liste aus Gruppen.
|
||||||
* @return
|
* @return
|
||||||
* @throws EventException
|
* @throws EventException
|
||||||
*/
|
*/
|
||||||
|
public List<Group> getAllGroupWithVisibilityPublic(String user_id) throws EventException {
|
||||||
public List<Group> getAllGroupWithVisibilityPublic() throws EventException {
|
List<Long> group_ids = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(user_id));
|
||||||
List<Long> group_ids = eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE);
|
|
||||||
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids);
|
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids);
|
||||||
List<Event> events = eventService.translateEventDTOs(eventDTOS);
|
List<Event> events = eventService.translateEventDTOs(eventDTOS);
|
||||||
List<Group> groups = projectEventList(events);
|
List<Group> groups = projectEventList(events);
|
||||||
@ -94,10 +101,10 @@ public class GroupService {
|
|||||||
* @return
|
* @return
|
||||||
* @throws EventException
|
* @throws EventException
|
||||||
*/
|
*/
|
||||||
public List<Group> findGroupWith(String search) throws EventException {
|
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||||
List<Group> groups = new ArrayList<>();
|
List<Group> groups = new ArrayList<>();
|
||||||
for (Group group: getAllGroupWithVisibilityPublic()) {
|
for (Group group: getAllGroupWithVisibilityPublic(account.getName())) {
|
||||||
if (group.getTitle().contains(search)|| group.getDescription().contains(search)){
|
if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())){
|
||||||
groups.add(group);
|
groups.add(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user