Created first Api implementation
This commit is contained in:
@ -1,14 +1,18 @@
|
||||
package mops.gruppen2.repository;
|
||||
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import org.springframework.data.jdbc.repository.query.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
|
||||
@Query("SELECT * FROM event WHERE event_id > @status")
|
||||
public Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
||||
|
||||
@Query("SELECT * FROM event WHERE group_id IN @groupIds ")
|
||||
public Iterable<EventDTO> findAllEventsOfGroups(@Param("groupIds") List<Long> groupIds);
|
||||
}
|
||||
|
||||
@ -55,9 +55,11 @@ public class EventService {
|
||||
|
||||
|
||||
public List<Event> getNewEvents(Long status){
|
||||
Iterable<EventDTO> eventDTOS = eventStore.findNewEventSinceStatus(status);
|
||||
Iterable<EventDTO> newEventDTOS = eventStore.findNewEventSinceStatus(status);
|
||||
List<Long> groupIdsThatChanged = this.getAllGroupIds(newEventDTOS);
|
||||
|
||||
return translateEventDTOs(eventDTOS);
|
||||
Iterable<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
|
||||
return translateEventDTOs(groupEventDTOS);
|
||||
}
|
||||
|
||||
private List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS){
|
||||
@ -74,4 +76,15 @@ public class EventService {
|
||||
return events;
|
||||
}
|
||||
|
||||
private List<Long> getAllGroupIds(Iterable<EventDTO> eventDTOS){
|
||||
List<Long> idsOfChangedGroups = new ArrayList<>();
|
||||
for (EventDTO eventDTO : eventDTOS){
|
||||
if (!idsOfChangedGroups.contains(eventDTO.getGroup_id())) {
|
||||
idsOfChangedGroups.add(eventDTO.getGroup_id());
|
||||
|
||||
}
|
||||
}
|
||||
return idsOfChangedGroups;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user