added deserialization tests
This commit is contained in:
@ -6,6 +6,8 @@ import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class EventService {
|
||||
private final SerializationService serializationService;
|
||||
@ -48,4 +50,18 @@ public class EventService {
|
||||
}
|
||||
return tmpId;
|
||||
}
|
||||
|
||||
public List<EventDTO> findAllEvents() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Event getEvent(EventDTO eventDTO) {
|
||||
try {
|
||||
return serializationService.deserializeEvent(eventDTO.getEvent_payload());
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,11 +7,19 @@ import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class GroupService {
|
||||
|
||||
private final EventService eventService;
|
||||
|
||||
public GroupService(EventService eventService) {
|
||||
this.eventService = eventService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Konstruiert eine vollständige Gruppe aus Events, welche dieselbe Gruppe betreffen.
|
||||
*
|
||||
@ -46,4 +54,27 @@ public class GroupService {
|
||||
}
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
public List<Group> projectEventList(Map<Long, Group> groupMap, List<Event> events) {
|
||||
for (Event event : events) {
|
||||
if (event instanceof CreateGroupEvent) {
|
||||
groupMap.put(event.getGroup_id(), new Group());
|
||||
}
|
||||
|
||||
try {
|
||||
Group group = groupMap.get(event.getGroup_id());
|
||||
|
||||
if (group == null) {
|
||||
throw new GroupDoesNotExistException("Gruppe " + event.getGroup_id() + " existiert nicht");
|
||||
}
|
||||
|
||||
group.applyEvent(event);
|
||||
} catch (EventException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new ArrayList<>(groupMap.values());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user