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.EventService;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@ -28,14 +30,16 @@ public class APIController {
private final EventService eventService;
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.groupService = groupService;
this.userService = userService;
}
@GetMapping("/updateGroups/{status}")
//@Secured("ROLE_api_user")
@Secured("ROLE_api_user")
@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 {
List<Event> events = eventService.getNewEvents(status);
@ -44,16 +48,16 @@ public class APIController {
}
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
//@Secured("ROLE_api_user")
@Secured("ROLE_api_user")
@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) {
return eventService.findGroupIdsByUser(teilnehmer).stream()
.map(UUID::toString)
.collect(Collectors.toList());
return userService.getUserGroups(teilnehmer).stream()
.map(group -> group.getId().toString())
.collect(Collectors.toList());
}
@GetMapping("/getGroup/{groupId}")
//@Secured("ROLE_api_user")
@Secured("ROLE_api_user")
@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 {
List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId));

View File

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

View File

@ -12,15 +12,12 @@ import java.util.List;
//TODO Rename Queries + Formatting
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);
@Query("select * from event where group_id =:id")
@Query("SELECT * FROM event WHERE group_id = :id")
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")
List<String> findNewEventSinceStatus(@Param("status") Long status);

View File

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

View File

@ -41,6 +41,10 @@ public class UserService {
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 {
List<UUID> groupIds = new ArrayList<>();
groupIds.add(groupId);

View File

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

View File

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