1
Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-26 21:19:59 +01:00
parent b37f2349aa
commit 02e7bcbcc4
7 changed files with 17 additions and 16 deletions

View File

@ -10,6 +10,8 @@ import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.service.APIFormatterService; import mops.gruppen2.service.APIFormatterService;
import mops.gruppen2.service.EventService; import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService; import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.UserService;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -28,14 +30,16 @@ public class APIController {
private final EventService eventService; private final EventService eventService;
private final GroupService groupService; private final GroupService groupService;
private final UserService userService;
public APIController(EventService eventService, GroupService groupService) { public APIController(EventService eventService, GroupService groupService, UserService userService) {
this.eventService = eventService; this.eventService = eventService;
this.groupService = groupService; this.groupService = groupService;
this.userService = userService;
} }
@GetMapping("/updateGroups/{status}") @GetMapping("/updateGroups/{status}")
//@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation("Gibt alle Gruppen zurück in denen sich etwas geändert hat") @ApiOperation("Gibt alle Gruppen zurück in denen sich etwas geändert hat")
public GroupRequestWrapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException { public GroupRequestWrapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
List<Event> events = eventService.getNewEvents(status); List<Event> events = eventService.getNewEvents(status);
@ -44,16 +48,16 @@ public class APIController {
} }
@GetMapping("/getGroupIdsOfUser/{teilnehmer}") @GetMapping("/getGroupIdsOfUser/{teilnehmer}")
//@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation("Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet") @ApiOperation("Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
public List<String> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) { public List<String> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
return eventService.findGroupIdsByUser(teilnehmer).stream() return userService.getUserGroups(teilnehmer).stream()
.map(UUID::toString) .map(group -> group.getId().toString())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@GetMapping("/getGroup/{groupId}") @GetMapping("/getGroup/{groupId}")
//@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück") @ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException { public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException {
List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId)); List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId));

View File

@ -58,7 +58,6 @@ public class WebController {
* @param model tolles model * @param model tolles model
* @return index.html * @return index.html
*/ */
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("") @GetMapping("")
public String index(KeycloakAuthenticationToken token, Model model) throws EventException { public String index(KeycloakAuthenticationToken token, Model model) throws EventException {

View File

@ -12,15 +12,12 @@ import java.util.List;
//TODO Rename Queries + Formatting //TODO Rename Queries + Formatting
public interface EventRepository extends CrudRepository<EventDTO, Long> { public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("select distinct group_id from event where user_id =:id") @Query("SELECT DISTINCT group_id FROM event WHERE user_id = :id")
List<String> findGroup_idsWhereUser_id(@Param("id") String userId); List<String> findGroup_idsWhereUser_id(@Param("id") String userId);
@Query("select * from event where group_id =:id") @Query("SELECT * FROM event WHERE group_id = :id")
List<EventDTO> findEventDTOByGroup_id(@Param("id") String groupId); List<EventDTO> findEventDTOByGroup_id(@Param("id") String groupId);
//@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
//Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status") @Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
List<String> findNewEventSinceStatus(@Param("status") Long status); List<String> findNewEventSinceStatus(@Param("status") Long status);

View File

@ -115,7 +115,6 @@ public class EventService {
return translateEventDTOs(eventDTOList); return translateEventDTOs(eventDTOList);
} }
//TODO: Nur AddUserEvents betrachten
public List<UUID> findGroupIdsByUser(String userId) { public List<UUID> findGroupIdsByUser(String userId) {
return eventStore.findGroup_idsWhereUser_id(userId).stream() return eventStore.findGroup_idsWhereUser_id(userId).stream()
.map(UUID::fromString) .map(UUID::fromString)

View File

@ -41,6 +41,10 @@ public class UserService {
return newGroups; return newGroups;
} }
public List<Group> getUserGroups(String userId) throws EventException {
return getUserGroups(new User(userId, null, null, null));
}
public Group getGroupById(UUID groupId) throws EventException { public Group getGroupById(UUID groupId) throws EventException {
List<UUID> groupIds = new ArrayList<>(); List<UUID> groupIds = new ArrayList<>();
groupIds.add(groupId); groupIds.add(groupId);

View File

@ -40,7 +40,6 @@ class EventServiceTest {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
eventService = new EventService(jsonService, eventRepository); eventService = new EventService(jsonService, eventRepository);
eventRepository.deleteAll();
} }
@Test @Test

View File

@ -48,7 +48,6 @@ class GroupServiceTest {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
groupService = new GroupService(eventService, eventRepository); groupService = new GroupService(eventService, eventRepository);
eventRepository.deleteAll();
} }
//TODO: Wofür ist dieser Test? //TODO: Wofür ist dieser Test?