Merge remote-tracking branch 'origin/master' into edit-User
This commit is contained in:
@ -117,6 +117,15 @@ public class Gruppen2Controller {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@PostMapping("/detailsBeitreten")
|
||||
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Account account = keyCloakService.createAccountFromPrincipal (token);
|
||||
controllerService.addUser(account,id);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/detailsSearch")
|
||||
public String showGroupDetailsNoMember (KeycloakAuthenticationToken token, Model model, @RequestParam (value="id") Long id) throws EventException {
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
package mops.gruppen2.domain.Exceptions;
|
||||
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
|
||||
public class GroupDoesNotExistException extends EventException {
|
||||
public GroupDoesNotExistException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,10 @@ package mops.gruppen2.domain.event;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
|
||||
/**
|
||||
@ -24,8 +27,14 @@ public class AddUserEvent extends Event {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public void apply(Group group) {
|
||||
public void apply(Group group) throws EventException{
|
||||
User user = new User(this.user_id, this.givenname, this.familyname, this.email);
|
||||
|
||||
if (group.getMembers().contains(user)){
|
||||
throw new UserAlreadyExistsException("Der User existiert bereits");
|
||||
}
|
||||
|
||||
group.getMembers().add(user);
|
||||
group.getRoles().put(user_id, Role.MEMBER);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.*;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Group;
|
||||
@ -15,7 +17,7 @@ public class DeleteUserEvent extends Event {
|
||||
super(group_id, user_id);
|
||||
}
|
||||
|
||||
public void apply(Group group) {
|
||||
public void apply(Group group) throws EventException {
|
||||
for (User user : group.getMembers()) {
|
||||
if (user.getUser_id().equals(this.user_id)) {
|
||||
group.getMembers().remove(user);
|
||||
@ -23,5 +25,6 @@ public class DeleteUserEvent extends Event {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new UserNotFoundException("Der User existiert nicht");
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
|
||||
|
||||
@ -31,5 +32,6 @@ public class Event {
|
||||
String user_id;
|
||||
|
||||
|
||||
public void apply(Group group){}
|
||||
public void apply(Group group) throws EventException {
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,10 @@ public class UpdateRoleEvent extends Event {
|
||||
this.newRole = newRole;
|
||||
}
|
||||
|
||||
public void apply(Group group) {
|
||||
public void apply(Group group) throws UserNotFoundException{
|
||||
if (!group.getRoles().containsKey(user_id)){
|
||||
throw new UserNotFoundException("Der User wurde nicht gefunden");
|
||||
}
|
||||
group.getRoles().put(this.user_id, this.newRole);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user