add error handling (frontend) + exception changes
Co-authored-by: Christoph <tobi@urpost.de> Co-authored-by: Mahgs <maxoerter@gmx.de>
This commit is contained in:
@ -1,10 +1,13 @@
|
||||
package mops.gruppen2.domain.Exceptions;
|
||||
|
||||
public class EventException extends Exception {
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
public class EventException extends ResponseStatusException {
|
||||
private String msg;
|
||||
|
||||
public EventException(String msg) {
|
||||
this.msg = msg;
|
||||
public EventException(String msg, HttpStatus status) {
|
||||
super(status, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
package mops.gruppen2.domain.Exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class GroupIdMismatchException extends EventException {
|
||||
public GroupIdMismatchException(String msg) {
|
||||
super("Falsche Gruppe für Event." + " (" + msg + ")", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
public GroupIdMismatchException() {
|
||||
super("", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package mops.gruppen2.domain.Exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class GroupNotFoundException extends EventException {
|
||||
public GroupNotFoundException(String msg) {
|
||||
super(msg, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
public GroupNotFoundException() {
|
||||
super("Gruppe nicht gefunden.", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,13 @@
|
||||
package mops.gruppen2.domain.Exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class UserAlreadyExistsException extends EventException {
|
||||
public UserAlreadyExistsException(String msg){
|
||||
super(msg);
|
||||
public UserAlreadyExistsException(String msg) {
|
||||
super(msg, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
public UserAlreadyExistsException() {
|
||||
super("Der User existiert bereits.", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
package mops.gruppen2.domain.Exceptions;
|
||||
|
||||
public class UserNotFoundException extends EventException{
|
||||
public UserNotFoundException(String msg){
|
||||
super(msg);
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class UserNotFoundException extends EventException {
|
||||
public UserNotFoundException(String msg) {
|
||||
super(msg, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
public UserNotFoundException() {
|
||||
super("Der User wurde nicht gefunden.", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
package mops.gruppen2.domain;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
// @ApiModelProperty
|
||||
@Value
|
||||
public class ProductSwaggerExample {
|
||||
|
||||
// @ApiModelProperty
|
||||
String name;
|
||||
String description;
|
||||
}
|
||||
@ -27,11 +27,12 @@ public class AddUserEvent extends Event {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public void apply(Group group) throws EventException{
|
||||
@Override
|
||||
public void applyEvent(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");
|
||||
if (group.getMembers().contains(user)) {
|
||||
throw new UserAlreadyExistsException();
|
||||
}
|
||||
|
||||
group.getMembers().add(user);
|
||||
|
||||
@ -15,8 +15,6 @@ public class CreateGroupEvent extends Event {
|
||||
private Long groupParent;
|
||||
private GroupType groupType;
|
||||
|
||||
|
||||
|
||||
public CreateGroupEvent(Long group_id, String user_id, Long parent, GroupType type, Visibility visibility) {
|
||||
super(group_id, user_id);
|
||||
this.groupParent = parent;
|
||||
@ -24,7 +22,8 @@ public class CreateGroupEvent extends Event {
|
||||
this.groupVisibility = visibility;
|
||||
}
|
||||
|
||||
public void apply(Group group) {
|
||||
@Override
|
||||
public void applyEvent(Group group) {
|
||||
group.setId(this.group_id);
|
||||
group.setParent(this.groupParent);
|
||||
group.setType(this.groupType);
|
||||
|
||||
@ -13,7 +13,7 @@ public class DeleteGroupEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Group group) {
|
||||
public void applyEvent(Group group) {
|
||||
group.getRoles().clear();
|
||||
group.getMembers().clear();
|
||||
group.setTitle(null);
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Entfernt ein einzelnes Mitglied einer Gruppe.
|
||||
@ -17,7 +17,8 @@ public class DeleteUserEvent extends Event {
|
||||
super(group_id, user_id);
|
||||
}
|
||||
|
||||
public void apply(Group group) throws EventException {
|
||||
@Override
|
||||
public void applyEvent(Group group) throws EventException {
|
||||
for (User user : group.getMembers()) {
|
||||
if (user.getUser_id().equals(this.user_id)) {
|
||||
group.getMembers().remove(user);
|
||||
|
||||
@ -31,7 +31,22 @@ public class Event {
|
||||
Long group_id;
|
||||
String user_id;
|
||||
|
||||
|
||||
public void apply(Group group) throws EventException {
|
||||
checkGroupIdMatch(group.getId());
|
||||
applyEvent(group);
|
||||
}
|
||||
|
||||
protected void applyEvent(Group group) throws EventException {
|
||||
|
||||
}
|
||||
|
||||
private void checkGroupIdMatch(Long group_id) {
|
||||
if (this.group_id.equals(group_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//throw new GroupIdMismatchException(this.getClass().toString());
|
||||
System.out.println(group_id);
|
||||
System.out.println(this.group_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,8 @@ public class UpdateGroupDescriptionEvent extends Event {
|
||||
this.newGroupDescription = newGroupDescription;
|
||||
}
|
||||
|
||||
public void apply(Group group) {
|
||||
@Override
|
||||
public void applyEvent(Group group) {
|
||||
group.setDescription(this.newGroupDescription);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,8 @@ public class UpdateGroupTitleEvent extends Event {
|
||||
this.newGroupTitle = newGroupTitle;
|
||||
}
|
||||
|
||||
public void apply(Group group) {
|
||||
@Override
|
||||
public void applyEvent(Group group) {
|
||||
group.setTitle(this.newGroupTitle);
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.*;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Aktualisiert die Gruppenrolle eines Teilnehmers.
|
||||
@ -18,15 +16,16 @@ import java.util.Optional;
|
||||
public class UpdateRoleEvent extends Event {
|
||||
|
||||
Role newRole;
|
||||
|
||||
|
||||
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
|
||||
super(group_id, user_id);
|
||||
this.newRole = newRole;
|
||||
}
|
||||
|
||||
public void apply(Group group) throws UserNotFoundException{
|
||||
if (!group.getRoles().containsKey(user_id)){
|
||||
throw new UserNotFoundException("Der User wurde nicht gefunden");
|
||||
@Override
|
||||
public void applyEvent(Group group) throws UserNotFoundException {
|
||||
if (!group.getRoles().containsKey(user_id)) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
group.getRoles().put(this.user_id, this.newRole);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user