diff --git a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java index fa3354d..24137d6 100644 --- a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java +++ b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java @@ -70,19 +70,20 @@ public class Gruppen2Controller { } @RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) - @GetMapping("/createLecture") - public String createLecture(KeycloakAuthenticationToken token, Model model) { + @GetMapping("/createOrga") + public String createOrga(KeycloakAuthenticationToken token, Model model) { model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); - return "createLecture"; + return "createOrga"; } @RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) - @PostMapping("/createLecture") - public String pCreateLecture(KeycloakAuthenticationToken token, - @RequestParam("title") String title, - @RequestParam("beschreibung") String beschreibung, - @RequestParam(value = "visibility", required = false) Boolean visibility, - @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { + @PostMapping("/createOrga") + public String pCreateOrga(KeycloakAuthenticationToken token, + @RequestParam("title") String title, + @RequestParam("beschreibung") String beschreibung, + @RequestParam(value = "visibility", required = false) Boolean visibility, + @RequestParam(value = "lecture", required = false) Boolean lecture, + @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { Account account = keyCloakService.createAccountFromPrincipal(token); List userList = new ArrayList<>(); @@ -90,7 +91,30 @@ public class Gruppen2Controller { userList = CsvService.read(file.getInputStream()); } visibility = visibility == null; - controllerService.createLecture(account, title, beschreibung, visibility, userList); + lecture = lecture == null; + + controllerService.createOrga(account, title, beschreibung, visibility, lecture, userList); + + return "redirect:/gruppen2/"; + } + + @RolesAllowed({"ROLE_studentin"}) + @GetMapping("/createStudent") + public String createStudent(KeycloakAuthenticationToken token, Model model) { + model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); + return "createStudent"; + } + + @RolesAllowed({"ROLE_studentin"}) + @PostMapping("/createStudent") + public String pCreateStudent(KeycloakAuthenticationToken token, + @RequestParam("title") String title, + @RequestParam("beschreibung") String beschreibung, + @RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException { + + Account account = keyCloakService.createAccountFromPrincipal(token); + visibility = visibility == null; + controllerService.createGroup(account, title, beschreibung, visibility); return "redirect:/gruppen2/"; } @@ -107,13 +131,6 @@ public class Gruppen2Controller { return "redirect:/gruppen2/details/members/" + groupId; } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) - @GetMapping("/createGroup") - public String createGroup(KeycloakAuthenticationToken token, Model model) { - model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); - return "create"; - } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @GetMapping("/findGroup") public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String search) throws EventException { @@ -127,20 +144,6 @@ public class Gruppen2Controller { return "search"; } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) - @PostMapping("/createGroup") - public String pCreateGroup(KeycloakAuthenticationToken token, - @RequestParam("title") String title, - @RequestParam("beschreibung") String beschreibung, - @RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException { - - Account account = keyCloakService.createAccountFromPrincipal(token); - visibility = visibility == null; - controllerService.createGroup(account, title, beschreibung, visibility); - - return "redirect:/gruppen2/"; - } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @GetMapping("/details/{id}") public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) throws EventException { diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index cd27a39..18fcd0f 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -63,6 +63,32 @@ public class ControllerService { updateRole(account.getName(), groupId); } + public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, List users) throws EventException { + Visibility visibility1; + Long groupId = eventService.checkGroup(); + + if (visibility) { + visibility1 = Visibility.PUBLIC; + } else { + visibility1 = Visibility.PRIVATE; + } + + GroupType groupType; + if (lecture) { + groupType = GroupType.SIMPLE; + } else { + groupType = GroupType.LECTURE; + } + CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, groupType, visibility1); + eventService.saveEvent(createGroupEvent); + + addUser(account, groupId); + updateTitle(account, groupId, title); + updateDescription(account, groupId, description); + updateRole(account.getName(), groupId); + addUserList(users, groupId); + } + private void createInviteLink(Long groupId) { inviteLinkRepositoryService.saveInvite(groupId, UUID.randomUUID()); } @@ -134,23 +160,4 @@ public class ControllerService { eventService.saveEvent(deleteGroupEvent); } - public void createLecture(Account account, String title, String description, Boolean visibility, List users) throws EventException { - Visibility visibility1; - Long groupId = eventService.checkGroup(); - - if (visibility) { - visibility1 = Visibility.PUBLIC; - } else { - visibility1 = Visibility.PRIVATE; - } - - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1); - eventService.saveEvent(createGroupEvent); - - addUser(account, groupId); - updateTitle(account, groupId, title); - updateDescription(account, groupId, description); - updateRole(account.getName(), groupId); - addUserList(users, groupId); - } } diff --git a/src/main/resources/templates/createLecture.html b/src/main/resources/templates/createOrga.html similarity index 69% rename from src/main/resources/templates/createLecture.html rename to src/main/resources/templates/createOrga.html index 04be706..a65a224 100644 --- a/src/main/resources/templates/createLecture.html +++ b/src/main/resources/templates/createOrga.html @@ -16,20 +16,20 @@
-
@@ -37,11 +37,10 @@
-

Veranstaltung erstellen

-
-
+

Gruppenerstellung

+ +
Private Gruppe
+
+ + +
+
+ + +
@@ -76,8 +91,8 @@ type="submit">Erstellen
- -
+
+
@@ -90,4 +105,4 @@ - + \ No newline at end of file diff --git a/src/main/resources/templates/create.html b/src/main/resources/templates/createStudent.html similarity index 87% rename from src/main/resources/templates/create.html rename to src/main/resources/templates/createStudent.html index 2b93f80..43b4abd 100644 --- a/src/main/resources/templates/create.html +++ b/src/main/resources/templates/createStudent.html @@ -11,20 +11,20 @@
-
@@ -33,7 +33,7 @@

Gruppenerstellung

-
+
diff --git a/src/main/resources/templates/detailsMember.html b/src/main/resources/templates/detailsMember.html index 03436d8..012ae60 100644 --- a/src/main/resources/templates/detailsMember.html +++ b/src/main/resources/templates/detailsMember.html @@ -11,20 +11,20 @@
-
diff --git a/src/main/resources/templates/detailsNoMember.html b/src/main/resources/templates/detailsNoMember.html index 5d5684a..20d4f74 100644 --- a/src/main/resources/templates/detailsNoMember.html +++ b/src/main/resources/templates/detailsNoMember.html @@ -10,20 +10,20 @@
-
diff --git a/src/main/resources/templates/editMembers.html b/src/main/resources/templates/editMembers.html index edca787..68a452e 100644 --- a/src/main/resources/templates/editMembers.html +++ b/src/main/resources/templates/editMembers.html @@ -15,20 +15,20 @@
-
@@ -37,7 +37,6 @@
-
-
diff --git a/src/main/resources/templates/search.html b/src/main/resources/templates/search.html index 0d41f05..74dfe2b 100644 --- a/src/main/resources/templates/search.html +++ b/src/main/resources/templates/search.html @@ -10,20 +10,20 @@
-