Merge remote-tracking branch 'origin/master' into feature-orga-csv
# Conflicts: # src/main/java/mops/gruppen2/controller/Gruppen2Controller.java
This commit is contained in:
@ -36,7 +36,7 @@ public class APIController {
|
|||||||
@GetMapping("/updateGroups/{status}")
|
@GetMapping("/updateGroups/{status}")
|
||||||
@Secured("ROLE_api_user")
|
@Secured("ROLE_api_user")
|
||||||
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
||||||
public UpdatedGroupRequestMapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
public UpdatedGroupRequestMapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||||
List<Event> events = eventService.getNewEvents(status);
|
List<Event> events = eventService.getNewEvents(status);
|
||||||
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
|
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
|
||||||
|
|
||||||
@ -46,14 +46,14 @@ public class APIController {
|
|||||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||||
@Secured("ROLE_api_user")
|
@Secured("ROLE_api_user")
|
||||||
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
||||||
public List<Long> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) throws EventException {
|
public List<Long> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) throws EventException {
|
||||||
return eventService.getGroupsOfUser(teilnehmer);
|
return eventService.getGroupsOfUser(teilnehmer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getGroup/{groupId}")
|
@GetMapping("/getGroup/{groupId}")
|
||||||
@Secured("ROLE_api_user")
|
@Secured("ROLE_api_user")
|
||||||
@ApiOperation(value = "Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
@ApiOperation(value = "Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
||||||
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException{
|
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException {
|
||||||
List<Event> eventList = eventService.getEventsOfGroup(groupId);
|
List<Event> eventList = eventService.getEventsOfGroup(groupId);
|
||||||
|
|
||||||
List<Group> groups = groupService.projectEventList(eventList);
|
List<Group> groups = groupService.projectEventList(eventList);
|
||||||
|
|||||||
@ -55,17 +55,18 @@ public class Gruppen2Controller {
|
|||||||
* @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 {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
model.addAttribute("gruppen", userService.getUserGroups(user));
|
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||||
model.addAttribute("user",user);
|
model.addAttribute("user", user);
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||||
@GetMapping("/createLecture")
|
@GetMapping("/createLecture")
|
||||||
public String createLecture(KeycloakAuthenticationToken token, Model model) {
|
public String createLecture(KeycloakAuthenticationToken token, Model model) {
|
||||||
@ -96,7 +97,7 @@ public class Gruppen2Controller {
|
|||||||
return "create";
|
return "create";
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 {
|
||||||
List<Group> groupse = new ArrayList<>();
|
List<Group> groupse = new ArrayList<>();
|
||||||
@ -108,6 +109,7 @@ public class Gruppen2Controller {
|
|||||||
return "search";
|
return "search";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@PostMapping("/createGroup")
|
@PostMapping("/createGroup")
|
||||||
public String pCreateGroup(KeycloakAuthenticationToken token,
|
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||||
@RequestParam(value = "title") String title,
|
@RequestParam(value = "title") String title,
|
||||||
@ -121,7 +123,7 @@ public class Gruppen2Controller {
|
|||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@GetMapping("/details")
|
@GetMapping("/details")
|
||||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException, ResponseStatusException {
|
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException, ResponseStatusException {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
@ -136,16 +138,16 @@ public class Gruppen2Controller {
|
|||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@PostMapping("/detailsBeitreten")
|
@PostMapping("/detailsBeitreten")
|
||||||
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
Account account = keyCloakService.createAccountFromPrincipal (token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
controllerService.addUser(account,id);
|
controllerService.addUser(account, id);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@GetMapping("/detailsSearch")
|
@GetMapping("/detailsSearch")
|
||||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
@ -157,7 +159,7 @@ public class Gruppen2Controller {
|
|||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@GetMapping("/acceptinvite/{link}")
|
@GetMapping("/acceptinvite/{link}")
|
||||||
public String acceptInvite(KeycloakAuthenticationToken token, Model model, @PathVariable String link) throws EventException {
|
public String acceptInvite(KeycloakAuthenticationToken token, Model model, @PathVariable String link) throws EventException {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
@ -168,11 +170,17 @@ public class Gruppen2Controller {
|
|||||||
}
|
}
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
}
|
}
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@PostMapping("/leaveGroup")
|
@PostMapping("/leaveGroup")
|
||||||
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) {
|
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam(value = "group_id") Long id) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
controllerService.deleteUser(account, id);
|
controllerService.deleteUser(account, id);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("*")
|
||||||
|
public String defaultLink() {
|
||||||
|
return "errorRenameLater";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
public class MopsController {
|
public class MopsController {
|
||||||
|
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public String redirect(){
|
public String redirect() {
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,4 +30,7 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
|||||||
|
|
||||||
@Query("SELECT MAX(event_id) FROM event")
|
@Query("SELECT MAX(event_id) FROM event")
|
||||||
public Long getHighesEvent_ID();
|
public Long getHighesEvent_ID();
|
||||||
|
|
||||||
|
@Query("SELECT MAX(group_id) FROM event")
|
||||||
|
public Long getMaxGroupID();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,22 +59,17 @@ public class EventService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorgt dafür die Group_id immer um 1 zu erhöhen
|
* Gibt die nächst höhere groupID zurück die belegt werden kann.
|
||||||
|
* Gibt 1 zurück, falls keine Gruppe vorhanden ist.
|
||||||
*
|
*
|
||||||
* @return Gibt Long zurück
|
* @return Gibt Long zurück
|
||||||
*/
|
*/
|
||||||
public Long checkGroup() {
|
public Long checkGroup() {
|
||||||
Long tmpId = 1L;
|
Long maxGroupID = eventStore.getMaxGroupID();
|
||||||
Iterable<EventDTO> eventDTOS = eventStore.findAll();
|
if (maxGroupID == null) {
|
||||||
for (EventDTO event : eventDTOS) {
|
return 1L;
|
||||||
if (event.getGroup_id() == null) {
|
|
||||||
return tmpId;
|
|
||||||
}
|
|
||||||
if (tmpId <= event.getGroup_id()) {
|
|
||||||
tmpId++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return tmpId;
|
return maxGroupID + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -28,21 +28,6 @@ class EventServiceTest {
|
|||||||
eventService = new EventService(mock(SerializationService.class), eventRepositoryMock);
|
eventService = new EventService(mock(SerializationService.class), eventRepositoryMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkGroupTest() {
|
|
||||||
EventDTO eventDTO = new EventDTO();
|
|
||||||
EventDTO eventDTO1 = new EventDTO();
|
|
||||||
eventDTO1.setGroup_id(1L);
|
|
||||||
eventDTO.setUser_id("realer");
|
|
||||||
eventDTO.setUser_id("faker");
|
|
||||||
eventDTO.setGroup_id(0L);
|
|
||||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
|
||||||
eventDTOS.add(eventDTO);
|
|
||||||
eventDTOS.add(eventDTO1);
|
|
||||||
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
|
|
||||||
assertEquals(eventDTO1.getGroup_id() + 1, eventService.checkGroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getMaxID() {
|
void getMaxID() {
|
||||||
when(eventRepositoryMock.getHighesEvent_ID()).thenReturn(42L);
|
when(eventRepositoryMock.getHighesEvent_ID()).thenReturn(42L);
|
||||||
@ -52,14 +37,7 @@ class EventServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void checkGroupReturnNextValue() {
|
void checkGroupReturnNextValue() {
|
||||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
when(eventRepositoryMock.getMaxGroupID()).thenReturn(2L);
|
||||||
EventDTO eventDTO1 = new EventDTO();
|
|
||||||
EventDTO eventDTO2 = new EventDTO();
|
|
||||||
eventDTO1.setGroup_id(1L);
|
|
||||||
eventDTO2.setGroup_id(2L);
|
|
||||||
eventDTOS.add(eventDTO1);
|
|
||||||
eventDTOS.add(eventDTO2);
|
|
||||||
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
|
|
||||||
|
|
||||||
assertEquals(eventService.checkGroup(), 3L);
|
assertEquals(eventService.checkGroup(), 3L);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user