8
8
import org .springframework .jdbc .support .KeyHolder ;
9
9
import org .springframework .stereotype .Repository ;
10
10
import roomescape .reservation .domain .Reservation ;
11
+ import roomescape .reservation .presentation .exception .NotFoundReservationException ;
11
12
12
13
import java .sql .PreparedStatement ;
13
14
import java .util .List ;
14
- import java .util .Optional ;
15
15
16
16
@ Repository
17
17
@ RequiredArgsConstructor
@@ -38,14 +38,13 @@ public Reservation save(Reservation reservation) {
38
38
}
39
39
40
40
@ Override
41
- public Optional < Reservation > findById (Long reservationId ) {
41
+ public Reservation findById (Long reservationId ) {
42
42
String sql = "select id, name, date, time from reservation where id = ?" ;
43
43
44
44
try {
45
- Reservation reservation = jdbcTemplate .queryForObject (sql , reservationMapper (), reservationId );
46
- return Optional .of (reservation );
45
+ return jdbcTemplate .queryForObject (sql , reservationMapper (), reservationId );
47
46
} catch (EmptyResultDataAccessException e ) {
48
- return Optional . empty ();
47
+ throw new NotFoundReservationException ();
49
48
}
50
49
}
51
50
@@ -57,16 +56,12 @@ public List<Reservation> findAll() {
57
56
}
58
57
59
58
@ Override
60
- public Optional <Reservation > delete (Long reservationId ) {
61
- Optional <Reservation > reservation = this .findById (reservationId );
62
- if (reservation .isEmpty ()) {
63
- return Optional .empty ();
64
- }
59
+ public void delete (Long reservationId ) {
60
+ Reservation deletedReservation = this .findById (reservationId );
65
61
66
62
String sql = "delete from reservation where id = ?" ;
67
- jdbcTemplate .update (sql , reservationId );
63
+ jdbcTemplate .update (sql , deletedReservation . getId () );
68
64
69
- return reservation ;
70
65
}
71
66
72
67
private RowMapper <Reservation > reservationMapper () {
0 commit comments