Skip to content

Commit

Permalink
Feature add seats (#513)
Browse files Browse the repository at this point in the history
* Add functionality for adding seats to existing row

* Tests for adding seats to an existing group

* Add JPA query to remove for loop
  • Loading branch information
bramvankooten authored Feb 13, 2020
1 parent c1e4e05 commit 461d821
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public interface SeatRepository extends JpaRepository<Seat, Long> {
Optional<Seat> findBySeatGroupAndSeatNumber(String seatGroup, int seatNumber);

Optional<Seat> findByTicketId(Long ticketId);

Optional<Seat> findFirstBySeatGroupOrderBySeatNumberDesc(String seatGroup);
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,16 @@ public void clearSeat(String groupName, int seatNumber) {

@Override
public void addSeats(SeatGroupDTO seatGroupDTO) {
int highestSeat= 0;

Optional<Seat> seat = seatRepository.findFirstBySeatGroupOrderBySeatNumberDesc(seatGroupDTO.getSeatGroupName());
if (seat.isPresent()) {
highestSeat = seat.get().seatNumber;
}

List<Seat> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Seat> seatGroup = seatRepository.findBySeatGroup(TEMP_SEATGROUP);
assertTrue(seatGroup.size() == 10);
}

@Test
public void removeSeatGroupAsAnon() {
SeatGroupDTO seatGroupDTO = new SeatGroupDTO();
Expand Down

0 comments on commit 461d821

Please sign in to comment.