8
8
import org .springframework .web .bind .annotation .PostMapping ;
9
9
import org .springframework .web .bind .annotation .RequestBody ;
10
10
import org .springframework .web .bind .annotation .ResponseBody ;
11
- import roomescape .dto .Reservation ;
12
- import roomescape .exception .InvalidValueException ;
13
- import roomescape .exception .NotFoundReservationException ;
14
- import roomescape .repository .ReservationRepository ;
11
+ import roomescape .dto .ReservationRequestDto ;
12
+ import roomescape .dto .ReservationResponseDto ;
13
+ import roomescape .service .ReservationService ;
15
14
16
15
import java .net .URI ;
17
- import java .util .ArrayList ;
18
16
import java .util .List ;
19
- import java .util .concurrent .atomic .AtomicLong ;
20
17
21
18
@ Controller
22
19
public class ReservationController {
23
20
24
- private final ReservationRepository reservationRepository ;
21
+ private final ReservationService reservationService ;
25
22
26
- public ReservationController (ReservationRepository repository ) {
27
- this .reservationRepository = repository ;
23
+ public ReservationController (ReservationService reservationService ) {
24
+ this .reservationService = reservationService ;
28
25
}
29
26
30
27
// 홈화면
@@ -36,21 +33,17 @@ public String reservationPage() {
36
33
//예약 조회
37
34
@ ResponseBody
38
35
@ GetMapping ("/reservations" )
39
- public List <Reservation > list () {
40
- return reservationRepository .findAll ();
36
+ public ResponseEntity <List <ReservationResponseDto >> list () {
37
+ List <ReservationResponseDto > reservations = reservationService .getAllReservations ();
38
+ return ResponseEntity .ok (reservations );
41
39
}
42
40
43
41
//예약 추가
44
42
@ ResponseBody
45
43
@ PostMapping ("/reservations" )
46
- public ResponseEntity <Reservation > create (@ RequestBody Reservation newReservation ) {
47
- if (newReservation .getName () == null || newReservation .getName ().isEmpty () ||
48
- newReservation .getDate () == null || newReservation .getDate ().isEmpty () ||
49
- newReservation .getTime () == null || newReservation .getTime ().isEmpty ()) {
50
- throw new InvalidValueException ("예약 추가에 필요한 인자값이 비어있습니다." );
51
- }
44
+ public ResponseEntity <ReservationResponseDto > create (@ RequestBody ReservationRequestDto newReservationDto ) {
52
45
53
- Reservation reservation = reservationRepository . insert ( newReservation );
46
+ ReservationResponseDto reservation = reservationService . createReservation ( newReservationDto );
54
47
55
48
return ResponseEntity .created (URI .create ("/reservations/" + reservation .getId ()))
56
49
.body (reservation );
@@ -59,10 +52,7 @@ public ResponseEntity<Reservation> create(@RequestBody Reservation newReservatio
59
52
//예약 삭제
60
53
@ DeleteMapping ("/reservations/{id}" )
61
54
public ResponseEntity <Void > delete (@ PathVariable Long id ) {
62
- // 수정예정 Reservation reservation = reservationRepository.fin
63
- // .orElseThrow(() -> new NotFoundReservationException("예약을 찾을 수 없습니다."));
64
-
65
- reservationRepository .delete (id );
55
+ reservationService .deleteReservation (id );
66
56
return ResponseEntity .noContent ().build ();
67
57
}
68
58
}
0 commit comments