1

changed checkGroup Method to a Query

This commit is contained in:
[Mahgs]
2020-03-18 14:09:30 +01:00
parent 523d7d2ad9
commit b236e3bb9d
2 changed files with 9 additions and 11 deletions

View File

@ -30,4 +30,7 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("SELECT MAX(event_id) FROM event") @Query("SELECT MAX(event_id) FROM event")
public Long getHighesEvent_ID(); public Long getHighesEvent_ID();
@Query("SELECT MAX(group_id) FROM event")
public Long getMaxGroupID();
} }

View File

@ -59,22 +59,17 @@ public class EventService {
} }
/** /**
* Sorgt dafür die Group_id immer um 1 zu erhöhen * Gibt die nächst höhere groupID zurück die belegt werden kann.
* Gibt 1 zurück, falls keine Gruppe vorhanden ist.
* *
* @return Gibt Long zurück * @return Gibt Long zurück
*/ */
public Long checkGroup() { public Long checkGroup() {
Long tmpId = 1L; Long maxGroupID = eventStore.getMaxGroupID();
Iterable<EventDTO> eventDTOS = eventStore.findAll(); if (maxGroupID == null) {
for (EventDTO event : eventDTOS) { return 1L;
if (event.getGroup_id() == null) {
return tmpId;
} }
if (tmpId <= event.getGroup_id()) { return maxGroupID + 1;
tmpId++;
}
}
return tmpId;
} }
/** /**