added Creating Groups to frontend and saving them in Database. Also prepared some Methods for Snapshot db
This commit is contained in:
51
src/main/java/mops/gruppen2/service/EventService.java
Normal file
51
src/main/java/mops/gruppen2/service/EventService.java
Normal file
@ -0,0 +1,51 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class EventService {
|
||||
private final SerializationService serializationService;
|
||||
private final EventRepository eventStore;
|
||||
|
||||
public EventService(SerializationService serializationService, EventRepository eventStore) {
|
||||
this.serializationService = serializationService;
|
||||
this.eventStore = eventStore;
|
||||
}
|
||||
|
||||
|
||||
public void saveEvent(Event event){
|
||||
EventDTO eventDTO = getDTO(event);
|
||||
eventStore.save(eventDTO);
|
||||
|
||||
}
|
||||
|
||||
public EventDTO getDTO(Event event){
|
||||
EventDTO eventDTO = new EventDTO();
|
||||
eventDTO.setGroup_id(event.getGroup_id());
|
||||
eventDTO.setUser_id(event.getUser_id());
|
||||
try {
|
||||
eventDTO.setEvent_payload(serializationService.serializeEvent(event));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return eventDTO;
|
||||
}
|
||||
|
||||
public Long checkGroup() {
|
||||
Long tmpId = 1L;
|
||||
Iterable<EventDTO> eventDTOS = eventStore.findAll();
|
||||
for (EventDTO event : eventDTOS) {
|
||||
if (event.getGroup_id() == null) {
|
||||
return tmpId;
|
||||
}
|
||||
if (tmpId <= event.getGroup_id()) {
|
||||
tmpId++;
|
||||
}
|
||||
}
|
||||
return tmpId;
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@ -15,9 +16,17 @@ public class GroupService {
|
||||
* @param eventList Die Events für diese Gruppe
|
||||
* @return Gruppe auf aktuellem Stand
|
||||
*/
|
||||
Group buildGroupFromEvents(List<Event> eventList) {
|
||||
public Group buildGroupFromEvents(List<Event> eventList) {
|
||||
Group newGroup = new Group();
|
||||
newGroup.apply(eventList);
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
public Group buildGroupFromEvent(Event event){
|
||||
Group newGroup = new Group();
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
eventList.add(event);
|
||||
newGroup.apply(eventList);
|
||||
return newGroup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,16 +29,5 @@ public class SerializationService {
|
||||
return json;
|
||||
}
|
||||
|
||||
public void saveEvent(Event event){
|
||||
try {
|
||||
EventDTO eventDTO = new EventDTO();
|
||||
eventDTO.setGroup_id(event.getGroup_id());
|
||||
eventDTO.setUser_id(event.getUser_id());
|
||||
eventDTO.setEvent_payload(serializeEvent(event));
|
||||
eventStore.save(eventDTO);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user