Skip to content

Commit

Permalink
refactor(ReservationService): timeId를 통해 time과 맵핑하는 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
developowl committed Nov 27, 2024
1 parent fbed97d commit c9737cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public Reservation addReservation(ReservationRequest reservationRequest) {
throw new InvalidReservationParameterException("예약 내용에 누락된 부분이 있습니다.");
}

Time time = reservationRequest.getTime();
Long timeId = reservationRequest.getTime();
Time time = findTimeById(timeId);

Reservation reservation = new Reservation(
reservationRequest.getName(),
Expand All @@ -60,6 +61,14 @@ public Reservation addReservation(ReservationRequest reservationRequest) {
return reservation;
}

private Time findTimeById(Long timeId) {
String sql = "SELECT id, time FROM time WHERE id = ?";
return jdbcTemplate.queryForObject(sql, (rs, rowNum) -> new Time(
rs.getLong("id"),
rs.getString("time")
), timeId);
}

public void deleteReservation(Long id) {
int rowAffected = reservationRepository.deleteById(id);
if (rowAffected == 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/roomescape/model/time/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public Time(@JsonProperty("time") String time) {
this.time = time;
}

public Time(Long id, String time) {
this.id = id;
this.time = time;
}

public Long getId() {
return id;
}
Expand Down

0 comments on commit c9737cd

Please sign in to comment.