1

added deserialization tests

This commit is contained in:
Christoph
2020-03-10 15:59:09 +01:00
parent c508c900d1
commit 66a6b9a137
2 changed files with 47 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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());
}
}