Added DeleteGroupEvent and GroupDoesNotExistException
This commit is contained in:
@ -29,7 +29,8 @@ public class Gruppen2Controller {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
/**Zeigt die index.html an.
|
||||
/**
|
||||
* Zeigt die index.html an.
|
||||
*
|
||||
* @param token toller token
|
||||
* @param model tolles model
|
||||
|
||||
@ -30,8 +30,7 @@ public abstract class Aggregate {
|
||||
Method method = this.getClass().getDeclaredMethod("applyEvent", event.getClass());
|
||||
method.setAccessible(true);
|
||||
method.invoke(this, event);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
package mops.gruppen2.domain.Exceptions;
|
||||
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
|
||||
public class GroupDoesNotExistException extends EventException {
|
||||
public GroupDoesNotExistException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@ -68,8 +68,8 @@ public class Group extends Aggregate {
|
||||
this.description = event.getNewGroupDescription();
|
||||
}
|
||||
|
||||
private void applyEvent(DeleteUserEvent event) throws UserNotFoundException{
|
||||
User user = new User(event.getUser_id(), "","","");
|
||||
private void applyEvent(DeleteUserEvent event) throws UserNotFoundException {
|
||||
User user = new User(event.getUser_id(), "", "", "");
|
||||
|
||||
if (this.members.contains(user)) {
|
||||
this.members.remove(user);
|
||||
@ -77,4 +77,8 @@ public class Group extends Aggregate {
|
||||
throw new UserNotFoundException("Nutzer wurde nicht gefunden!");
|
||||
}
|
||||
}
|
||||
|
||||
private void applyEvent(DeleteGroupEvent event) {
|
||||
this.id = this.id * -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Value
|
||||
public class DeleteGroupEvent extends Event {
|
||||
|
||||
public DeleteGroupEvent(long event_id, long group_id, String user_id) {
|
||||
super(event_id, group_id, user_id);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.event.AddUserEvent;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -18,17 +18,32 @@ public class GroupService {
|
||||
* @param eventList Die restlichen Events für diese Gruppe
|
||||
* @return Gruppe auf aktuellem Stand
|
||||
*/
|
||||
Group buildGroupFromEvents(List<Event> eventList) {
|
||||
Group buildGroupFromEvents(List<Event> eventList) throws EventException {
|
||||
Group newGroup = new Group();
|
||||
|
||||
try {
|
||||
if (!(eventList.get(0) instanceof CreateGroupEvent)) {
|
||||
throw new GroupDoesNotExistException("Die Gruppe existiert nicht");
|
||||
} else {
|
||||
newGroup.applyEvent(eventList.get(0));
|
||||
eventList.remove(0);
|
||||
}
|
||||
for (Event event : eventList) {
|
||||
if (!(newGroup.getId() > 0)) {
|
||||
throw new GroupDoesNotExistException("Die Gruppe existiert nicht");
|
||||
}
|
||||
newGroup.applyEvent(event);
|
||||
}
|
||||
}catch (EventException e){
|
||||
} catch (EventException e) {
|
||||
if (e instanceof GroupDoesNotExistException) {
|
||||
throw e;
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (newGroup.getId() < 0) {
|
||||
return null;
|
||||
}
|
||||
return newGroup;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user