1

fix search

remove your Group from search

Co-Authored-By: andibuls <andibuls@users.noreply.github.com>
This commit is contained in:
tomvahl
2020-03-18 15:09:14 +01:00
parent ecd6154580
commit 522d1369ec
2 changed files with 13 additions and 5 deletions

View File

@ -99,9 +99,10 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/findGroup")
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<>();
if (suchbegriff != null) {
groupse = groupService.findGroupWith(suchbegriff);
groupse = groupService.findGroupWith(suchbegriff,account);
}
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
model.addAttribute("gruppen", groupse);

View File

@ -6,6 +6,7 @@ import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -77,9 +78,15 @@ public class GroupService {
* @return
* @throws EventException
*/
public List<Group> getAllGroupWithVisibilityPublic() throws EventException {
// Namensänderung fixen und die Forschleife auslagern
public List<Group> getAllGroupWithVisibilityPublic(String user_id) throws EventException {
List<Long> group_ids = eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE);
List<Long> group_ids_user = eventRepository.findGroup_idsWhereUser_id(user_id);
for (Long group_id: group_ids_user) {
if(group_ids.contains(group_id)){
group_ids.remove(group_id);
}
}
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids);
List<Event> events = eventService.translateEventDTOs(eventDTOS);
List<Group> groups = projectEventList(events);
@ -94,9 +101,9 @@ public class GroupService {
* @return
* @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<>();
for (Group group: getAllGroupWithVisibilityPublic()) {
for (Group group: getAllGroupWithVisibilityPublic(account.getName())) {
if (group.getTitle().contains(search)|| group.getDescription().contains(search)){
groups.add(group);
}