1

Merge remote-tracking branch 'origin/master' into updateGroupsAPI

# Conflicts:
#	src/main/java/mops/gruppen2/repository/EventRepository.java
This commit is contained in:
LukasEttel
2020-03-12 16:31:23 +01:00
11 changed files with 139 additions and 29 deletions

View File

@ -1,14 +1,16 @@
package mops.gruppen2.controller;
import mops.gruppen2.config.Gruppen2Config;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.AddUserEvent;
import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
import mops.gruppen2.security.Account;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.KeyCloakService;
import mops.gruppen2.service.*;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -27,11 +29,15 @@ public class Gruppen2Controller {
private final KeyCloakService keyCloakService;
private final EventService eventService;
private final GroupService groupService;
private final UserService userService;
private final ControllerService controllerService;
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService) {
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService) {
this.keyCloakService = keyCloakService;
this.eventService = eventService;
this.groupService = groupService;
this.userService = userService;
this.controllerService = controllerService;
}
/**
@ -43,8 +49,12 @@ public class Gruppen2Controller {
*/
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("")
public String index(KeycloakAuthenticationToken token, Model model) {
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
model.addAttribute("gruppen", userService.getUserGroups(user.getUser_id()));
return "index";
}
@ -67,15 +77,10 @@ public class Gruppen2Controller {
@RequestParam(value = "title") String title,
@RequestParam(value = "beschreibung") String beschreibung) {
//Refoctor
Account account = keyCloakService.createAccountFromPrincipal(token);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), account.getName(), null ,GroupType.LECTURE, Visibility.PUBLIC);
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
eventService.saveEvent(createGroupEvent);
eventService.saveEvent(addUserEvent);
controllerService.createGroup(account, title, beschreibung);
return "redirect:/";
return "redirect:/gruppen2";
}
}