1

Add feature to link a group to a lecture

This commit is contained in:
XXNitram
2020-03-20 02:36:51 +01:00
parent 479db666a3
commit 820782c2ce
4 changed files with 30 additions and 28 deletions

View File

@ -75,7 +75,9 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@GetMapping("/createOrga") @GetMapping("/createOrga")
public String createOrga(KeycloakAuthenticationToken token, Model model) { public String createOrga(KeycloakAuthenticationToken token, Model model) {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); Account account = keyCloakService.createAccountFromPrincipal(token);
model.addAttribute("account", account);
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
return "createOrga"; return "createOrga";
} }
@ -87,6 +89,7 @@ public class Gruppen2Controller {
@RequestParam(value = "visibility", required = false) Boolean visibility, @RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam(value = "lecture", required = false) Boolean lecture, @RequestParam(value = "lecture", required = false) Boolean lecture,
@RequestParam("userMaximum") Long userMaximum, @RequestParam("userMaximum") Long userMaximum,
@RequestParam(value = "parent", required = false) Long parent,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
@ -99,9 +102,11 @@ public class Gruppen2Controller {
} }
} }
visibility = visibility == null; visibility = visibility == null;
lecture = lecture == null; lecture = lecture != null;
controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, userList); if (lecture) parent = null;
controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, parent, userList);
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@ -109,7 +114,9 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_studentin"}) @RolesAllowed({"ROLE_studentin"})
@GetMapping("/createStudent") @GetMapping("/createStudent")
public String createStudent(KeycloakAuthenticationToken token, Model model) { public String createStudent(KeycloakAuthenticationToken token, Model model) {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); Account account = keyCloakService.createAccountFromPrincipal(token);
model.addAttribute("account", account);
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
return "createStudent"; return "createStudent";
} }
@ -119,11 +126,12 @@ public class Gruppen2Controller {
@RequestParam("title") String title, @RequestParam("title") String title,
@RequestParam("description") String description, @RequestParam("description") String description,
@RequestParam(value = "visibility", required = false) Boolean visibility, @RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam("userMaximum") Long userMaximum) throws EventException { @RequestParam("userMaximum") Long userMaximum,
@RequestParam(value = "parent", required = false) Long parent) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
visibility = visibility == null; visibility = visibility == null;
controllerService.createGroup(account, title, description, visibility, userMaximum); controllerService.createGroup(account, title, description, visibility, userMaximum, parent);
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }

View File

@ -46,7 +46,7 @@ public class ControllerService {
* @param title Gruppentitel * @param title Gruppentitel
* @param description Gruppenbeschreibung * @param description Gruppenbeschreibung
*/ */
public void createGroup(Account account, String title, String description, Boolean visibility, Long userMaximum) throws EventException { public void createGroup(Account account, String title, String description, Boolean visibility, Long userMaximum, Long parent) throws EventException {
Visibility visibility1; Visibility visibility1;
Long groupId = eventService.checkGroup(); Long groupId = eventService.checkGroup();
@ -57,7 +57,7 @@ public class ControllerService {
createInviteLink(groupId); createInviteLink(groupId);
} }
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.SIMPLE, visibility1, userMaximum); CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum);
eventService.saveEvent(createGroupEvent); eventService.saveEvent(createGroupEvent);
addUser(account, groupId); addUser(account, groupId);
@ -66,7 +66,7 @@ public class ControllerService {
updateRole(account.getName(), groupId); updateRole(account.getName(), groupId);
} }
public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Long maximmum, List<User> users) throws EventException { public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Long userMaximum, Long parent, List<User> users) throws EventException {
Visibility visibility1; Visibility visibility1;
Long groupId = eventService.checkGroup(); Long groupId = eventService.checkGroup();
@ -78,12 +78,12 @@ public class ControllerService {
GroupType groupType; GroupType groupType;
if (lecture) { if (lecture) {
groupType = GroupType.SIMPLE;
} else {
groupType = GroupType.LECTURE; groupType = GroupType.LECTURE;
} else {
groupType = GroupType.SIMPLE;
} }
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, groupType, visibility1, maximmum); CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, visibility1, userMaximum);
eventService.saveEvent(createGroupEvent); eventService.saveEvent(createGroupEvent);
addUser(account, groupId); addUser(account, groupId);

View File

@ -67,15 +67,12 @@
type="checkbox"> type="checkbox">
<label class="custom-control-label" for="lecture">Veranstaltung</label> <label class="custom-control-label" for="lecture">Veranstaltung</label>
</div> </div>
<div class="form-group"> <div class="form-group" id="lectureParent">
<label for="sel1"></label> <label for="parent"></label>
<select class="form-control" id="sel1"> <select class="form-control" id="parent" name="parent">
<option disabled selected="true">--Bitte Veranstaltung auswählen-- <option disabled selected="true">--Bitte Veranstaltung auswählen--</option>
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}">
</option> </option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select> </select>
</div> </div>
<div class="form-group pt-4"> <div class="form-group pt-4">

View File

@ -57,15 +57,12 @@
<label class="custom-control-label" for="visibility">Private <label class="custom-control-label" for="visibility">Private
Gruppe</label> Gruppe</label>
</div> </div>
<div class="form-group"> <div class="form-group" id="lectureParent">
<label for="sel1"></label> <label for="parent"></label>
<select class="form-control" id="sel1"> <select class="form-control" id="parent" name="parent">
<option disabled selected="true">--Bitte Veranstaltung auswählen-- <option disabled selected="true">--Bitte Veranstaltung auswählen--</option>
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}">
</option> </option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select> </select>
</div> </div>
<div class="form-group pt-4"> <div class="form-group pt-4">