diff --git a/src/main/java/ch/wisv/areafiftylan/seats/service/SeatRepository.java b/src/main/java/ch/wisv/areafiftylan/seats/service/SeatRepository.java index 268fae9fb..0be735430 100644 --- a/src/main/java/ch/wisv/areafiftylan/seats/service/SeatRepository.java +++ b/src/main/java/ch/wisv/areafiftylan/seats/service/SeatRepository.java @@ -33,4 +33,6 @@ public interface SeatRepository extends JpaRepository { Optional findBySeatGroupAndSeatNumber(String seatGroup, int seatNumber); Optional findByTicketId(Long ticketId); + + Optional findFirstBySeatGroupOrderBySeatNumberDesc(String seatGroup); } diff --git a/src/main/java/ch/wisv/areafiftylan/seats/service/SeatServiceImpl.java b/src/main/java/ch/wisv/areafiftylan/seats/service/SeatServiceImpl.java index 9794e5dc1..a93dacf5c 100644 --- a/src/main/java/ch/wisv/areafiftylan/seats/service/SeatServiceImpl.java +++ b/src/main/java/ch/wisv/areafiftylan/seats/service/SeatServiceImpl.java @@ -132,9 +132,16 @@ public void clearSeat(String groupName, int seatNumber) { @Override public void addSeats(SeatGroupDTO seatGroupDTO) { + int highestSeat= 0; + + Optional seat = seatRepository.findFirstBySeatGroupOrderBySeatNumberDesc(seatGroupDTO.getSeatGroupName()); + if (seat.isPresent()) { + highestSeat = seat.get().seatNumber; + } + List seatList = new ArrayList<>(seatGroupDTO.getNumberOfSeats()); - for (int i = 1; i <= seatGroupDTO.getNumberOfSeats(); i++) { + for (int i = 1 + highestSeat; i <= seatGroupDTO.getNumberOfSeats() + highestSeat; i++) { seatList.add(new Seat(seatGroupDTO.getSeatGroupName(), i)); } seatRepository.saveAll(seatList); diff --git a/src/test/java/ch/wisv/areafiftylan/integration/SeatRestIntegrationTest.java b/src/test/java/ch/wisv/areafiftylan/integration/SeatRestIntegrationTest.java index 5dbf4d1d0..4edeab259 100644 --- a/src/test/java/ch/wisv/areafiftylan/integration/SeatRestIntegrationTest.java +++ b/src/test/java/ch/wisv/areafiftylan/integration/SeatRestIntegrationTest.java @@ -389,6 +389,29 @@ public void addSeatGroupAsAdmin() { assertTrue(seatGroup.size() == 5); } + @Test + public void addSeatsToExistingGroupAsAdmin() { + User admin = createAdmin(); + SeatGroupDTO seatGroupDTO = new SeatGroupDTO(); + seatGroupDTO.setSeatGroupName(TEMP_SEATGROUP); + seatGroupDTO.setNumberOfSeats(5); + seatService.addSeats(seatGroupDTO); + + //@formatter:off + given(). + header(getXAuthTokenHeaderForUser(admin)). + when(). + body(seatGroupDTO). + contentType(ContentType.JSON). + post(SEAT_ENDPOINT). + then(). + statusCode(HttpStatus.SC_OK); + //@formatter:on + + List seatGroup = seatRepository.findBySeatGroup(TEMP_SEATGROUP); + assertTrue(seatGroup.size() == 10); + } + @Test public void removeSeatGroupAsAnon() { SeatGroupDTO seatGroupDTO = new SeatGroupDTO();