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")
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
*/
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++;
}
Long maxGroupID = eventStore.getMaxGroupID();
if (maxGroupID == null) {
return 1L;
}
return tmpId;
return maxGroupID + 1;
}
/**