decreased visibility of group-fields -> adapted tests and GroupService
This commit is contained in:
@ -1,15 +1,23 @@
|
||||
package mops.gruppen2.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public abstract class Aggregate {
|
||||
|
||||
@Getter
|
||||
protected final long id;
|
||||
|
||||
protected Aggregate(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruft die spezifische applyEvent-Methode im entsprechenden Aggregat auf.
|
||||
*
|
||||
* @param event
|
||||
* @param event Einzelne Änderung an dem Aggregat
|
||||
*/
|
||||
public void applyEvent(Event event) {
|
||||
try {
|
||||
|
||||
@ -12,14 +12,13 @@ import java.util.Map;
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@Getter
|
||||
public class Group extends Aggregate {
|
||||
long id;
|
||||
String title;
|
||||
String description;
|
||||
List<User> members;
|
||||
Map<User, Role> roles;
|
||||
private String title;
|
||||
private String description;
|
||||
private List<User> members;
|
||||
private Map<User, Role> roles;
|
||||
|
||||
private void applyEvent(CreateGroupEvent event){
|
||||
this.id = event.getGroup_id();
|
||||
public Group(CreateGroupEvent event) {
|
||||
super(event.getGroup_id());
|
||||
this.title = event.getGroupTitle();
|
||||
this.description = event.getGroupDescription();
|
||||
this.members = new ArrayList<>();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
@ -8,8 +9,15 @@ import java.util.List;
|
||||
@Service
|
||||
public class GroupService {
|
||||
|
||||
Group buildGroupFromEvents(List<Event> eventList){
|
||||
Group newGroup = new Group();
|
||||
/**
|
||||
* Konstruiert eine vollständige Gruppe aus Events, welche dieselbe Gruppe betreffen.
|
||||
*
|
||||
* @param event Initiales CreateGroup-Event
|
||||
* @param eventList Die restlichen Events für diese Gruppe
|
||||
* @return Gruppe auf aktuellem Stand
|
||||
*/
|
||||
Group buildGroupFromEvents(CreateGroupEvent event, List<Event> eventList){
|
||||
Group newGroup = new Group(event);
|
||||
|
||||
eventList.forEach(newGroup::applyEvent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user