File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
src/main/java/roomescape/model/reservation Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change 33import org .springframework .jdbc .core .JdbcTemplate ;
44import org .springframework .jdbc .core .RowMapper ;
55import org .springframework .stereotype .Repository ;
6+ import roomescape .model .time .Time ;
67
78import java .sql .ResultSet ;
89import java .sql .SQLException ;
@@ -17,15 +18,35 @@ public ReservationRepository(JdbcTemplate jdbcTemplate) {
1718 }
1819
1920 public List <Reservation > findAll () {
20- String sql = "SELECT * FROM reservation" ;
21+ String sql = """
22+ SELECT
23+ r.id as reservation_id,
24+ r.name,
25+ r.date,
26+ t.id as time_id,
27+ t.time as time_value
28+ FROM reservation as r
29+ INNER JOIN time as t ON r.time_id = t.id
30+ """ ;
31+
2132 return jdbcTemplate .query (sql , new ReservationRowMapper ());
2233 }
2334
2435 private static class ReservationRowMapper implements RowMapper <Reservation > {
2536 @ Override
2637 public Reservation mapRow (ResultSet rs , int rowNum ) throws SQLException {
27- Reservation reservation = new Reservation (rs .getString ("name" ), rs .getString ("date" ), rs .getString ("time" ));
28- reservation .setId (rs .getLong ("id" ));
38+
39+ Long timeId = rs .getLong ("time_id" );
40+ String timeValue = rs .getString ("time_value" );
41+
42+ Time time = new Time (timeValue );
43+
44+ Reservation reservation = new Reservation (
45+ rs .getString ("name" ),
46+ rs .getString ("date" ),
47+ time
48+ );
49+ reservation .setId (rs .getLong ("reservation_id" ));
2950 return reservation ;
3051 }
3152 }
You can’t perform that action at this time.
0 commit comments