-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yelmorabit
committed
Jul 26, 2020
1 parent
2187c71
commit 624be0c
Showing
21 changed files
with
528 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/elmorabit/battlebrain/service/BookingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.elmorabit.battlebrain.service; | ||
|
||
import com.elmorabit.battlebrain.service.dto.BookingDTO; | ||
import com.elmorabit.battlebrain.service.dto.SeatDTO; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Service Interface for managing {@link com.elmorabit.battlebrain.domain.Reservation}. | ||
*/ | ||
public interface BookingService { | ||
|
||
/** | ||
* Get all the reservations. | ||
* | ||
* @return the list of entities. | ||
*/ | ||
List<SeatDTO> getAllAvailableSeats(BookingDTO bookingDTO); | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/elmorabit/battlebrain/service/dto/BookingDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.elmorabit.battlebrain.service.dto; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.io.Serializable; | ||
import java.time.Instant; | ||
|
||
/** | ||
* A DTO for the {@link com.elmorabit.battlebrain.domain.Reservation} entity. | ||
*/ | ||
public class BookingDTO implements Serializable { | ||
|
||
private Long id; | ||
|
||
@NotNull | ||
private Instant startDate; | ||
|
||
@NotNull | ||
private Instant endDate; | ||
|
||
|
||
private Long areaId; | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Instant getStartDate() { | ||
return startDate; | ||
} | ||
|
||
public void setStartDate(Instant startDate) { | ||
this.startDate = startDate; | ||
} | ||
|
||
public Instant getEndDate() { | ||
return endDate; | ||
} | ||
|
||
public void setEndDate(Instant endDate) { | ||
this.endDate = endDate; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof BookingDTO)) { | ||
return false; | ||
} | ||
|
||
return id != null && id.equals(((BookingDTO) o).id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31; | ||
} | ||
|
||
// prettier-ignore | ||
@Override | ||
public String toString() { | ||
return "ReservationDTO{" + | ||
"id=" + getId() + | ||
", startDate='" + getStartDate() + "'" + | ||
", endDate='" + getEndDate() + "'" + | ||
"}"; | ||
} | ||
|
||
public Long getAreaId() { | ||
return areaId; | ||
} | ||
|
||
public void setAreaId(final Long areaId) { | ||
this.areaId = areaId; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/elmorabit/battlebrain/service/impl/BookingServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.elmorabit.battlebrain.service.impl; | ||
|
||
import com.elmorabit.battlebrain.domain.Reservation; | ||
import com.elmorabit.battlebrain.domain.Seat; | ||
import com.elmorabit.battlebrain.repository.ReservationRepository; | ||
import com.elmorabit.battlebrain.repository.SeatRepository; | ||
import com.elmorabit.battlebrain.service.BookingService; | ||
import com.elmorabit.battlebrain.service.dto.BookingDTO; | ||
import com.elmorabit.battlebrain.service.dto.SeatDTO; | ||
import com.elmorabit.battlebrain.service.mapper.ReservationMapper; | ||
import com.elmorabit.battlebrain.service.mapper.SeatMapper; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Service Implementation for managing {@link Reservation}. | ||
*/ | ||
@Service | ||
@Transactional | ||
public class BookingServiceImpl implements BookingService { | ||
|
||
private final Logger log = LoggerFactory.getLogger(BookingServiceImpl.class); | ||
|
||
private final ReservationRepository reservationRepository; | ||
|
||
private final ReservationMapper reservationMapper; | ||
|
||
private final SeatRepository seatRepository; | ||
|
||
private final SeatMapper seatMapper; | ||
|
||
|
||
public BookingServiceImpl(ReservationRepository reservationRepository, ReservationMapper reservationMapper, final SeatRepository seatRepository, final SeatMapper seatMapper) { | ||
this.reservationRepository = reservationRepository; | ||
this.reservationMapper = reservationMapper; | ||
this.seatRepository = seatRepository; | ||
this.seatMapper = seatMapper; | ||
} | ||
|
||
@Override | ||
public List<SeatDTO> getAllAvailableSeats(final BookingDTO bookingDTO) { | ||
|
||
|
||
List<Seat> seatList; | ||
|
||
if (Objects.nonNull(bookingDTO.getAreaId())) { | ||
seatList = seatRepository.findAllByAreaId(bookingDTO.getAreaId()); | ||
} else { | ||
seatList = seatRepository.findAll(); | ||
} | ||
|
||
return seatList.stream().map(seatMapper::toDto).collect(Collectors.toList()); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/elmorabit/battlebrain/web/rest/BookingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.elmorabit.battlebrain.web.rest; | ||
|
||
import com.elmorabit.battlebrain.service.BookingService; | ||
import com.elmorabit.battlebrain.service.dto.BookingDTO; | ||
import com.elmorabit.battlebrain.service.dto.SeatDTO; | ||
|
||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.ValidationException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* REST controller for managing {@link com.elmorabit.battlebrain.domain.Reservation}. | ||
*/ | ||
@RestController | ||
@RequestMapping("/api") | ||
public class BookingController { | ||
|
||
private final Logger log = LoggerFactory.getLogger(BookingController.class); | ||
|
||
private static final String ENTITY_NAME = "reservation"; | ||
|
||
@Value("${jhipster.clientApp.name}") | ||
private String applicationName; | ||
|
||
private final BookingService bookingService; | ||
|
||
public BookingController(BookingService bookingService) { | ||
this.bookingService = bookingService; | ||
} | ||
|
||
/** | ||
* {@code POST /reservations} : Create a new reservation. | ||
* | ||
* @param bookingDTO the bookingDTO to create. | ||
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new bookingDTO, or with status {@code 400 (Bad Request)} if the reservation has already an ID. | ||
* @throws URISyntaxException if the Location URI syntax is incorrect. | ||
*/ | ||
@PostMapping("/booking") | ||
public ResponseEntity<List<SeatDTO>> createReservation(@Valid @RequestBody BookingDTO bookingDTO) throws URISyntaxException { | ||
log.debug("REST request to save Reservation : {}", bookingDTO); | ||
final Instant startDate = bookingDTO.getStartDate(); | ||
final Instant endDate = bookingDTO.getEndDate(); | ||
if (Objects.isNull(startDate) || Objects.isNull(endDate) || startDate.compareTo(Instant.now()) <= 0 || startDate.compareTo(endDate) >= 0) { | ||
throw new ValidationException("invalid data"); | ||
} | ||
List<SeatDTO> result = bookingService.getAllAvailableSeats(bookingDTO); | ||
return ResponseEntity.ok(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
id;name | ||
1;Sale Newton | ||
2;Sale Enshtien | ||
2;Sale Einstein | ||
3;Sale Rabat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
id ;right_seat_id ; left_seat_id;front_seat_id | ||
1 ;null;null;null | ||
2 ;null;null;null | ||
3 ;null;null;null | ||
4 ;null;null;null | ||
5 ;null;null;null | ||
6 ;null;null;null | ||
7 ;null;null;null | ||
8 ;null;null;null | ||
9 ;null;null;null | ||
10 ;null;null;null | ||
11 ;null;null;null | ||
12 ;null;null;null | ||
13 ;null;null;null | ||
14 ;null;null;null | ||
21 ;null;null;null | ||
22 ;null;null;null | ||
23 ;null;null;null | ||
24 ;null;null;null | ||
25 ;null;null;null | ||
26 ;null;null;null | ||
27 ;null;null;null | ||
28 ;null;null;null | ||
29 ;null;null;null | ||
210 ;null;null;null | ||
211 ;null;null;null | ||
212 ;null;null;null | ||
111 ;112 ;null;114 | ||
112 ;113 ;111 ;115 | ||
113 ;null;112 ;116 | ||
114 ;115 ;null;111 | ||
115 ;116 ;114 ;112 | ||
116 ;null;115 ;113 | ||
117 ;118 ;null;119 | ||
118 ;117 ;null;1110 | ||
119 ;null;1110;117 | ||
1110;119 ;null;118 | ||
1111;null;1112;1113 | ||
1112;1111;null;1114 | ||
1113;1114;null;1111 | ||
1114;null;1113;1112 | ||
1115;null;1116;1118 | ||
1116;1115;1117;1119 | ||
1117;1116;null;1120 | ||
1118;1119;null;1115 | ||
1119;1120;1118;1116 | ||
1120;null;1119;1117 | ||
|
Oops, something went wrong.