Skip to content

Commit

Permalink
feat: 회의실 예약 상태도 같이 응답하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Nov 28, 2023
1 parent 8a23616 commit bb433e4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface ReservationRepository extends JpaRepository<Reservation, Long>
@Query("""
FROM Reservation r
WHERE DATE_FORMAT (r.startTime, '%Y-%m-%d') = :date
AND r.status != 'CANCELED'
""")
List<Reservation> findAllByStartTimeDate(@Param("date") LocalDate date);

Expand All @@ -24,13 +25,14 @@ SELECT EXISTS (
FROM Reservation r
WHERE NOT (r.endTime <= :startTime OR r.startTime >= :endTime)
AND r.roomId = :roomId
AND r.status != 'CANCELED'
)
""")
boolean existDuplicatedTime(@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime,
@Param("roomId") Long roomId);

Optional<Reservation> findByIdAndReservationEmail(Long id, String email);
Optional<Reservation> findByIdAndReservationEmailAndStatusIsNot(Long id, String email, Status status);

List<Reservation> findAllByReservationEmail(String reservationEmail, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.busan.member.domain.MemberRepository;
import com.example.busan.reservation.domain.Reservation;
import com.example.busan.reservation.domain.ReservationRepository;
import com.example.busan.reservation.domain.Status;
import com.example.busan.reservation.dto.CancelReservationRequest;
import com.example.busan.reservation.dto.CreateReservationRequest;
import com.example.busan.reservation.dto.ReservationResponse;
Expand Down Expand Up @@ -53,7 +54,7 @@ private void validateDuplicated(final LocalDateTime startTime, final LocalDateTi

@Transactional
public void deleteById(final Long id, final String currentMemberEmail, final CancelReservationRequest request) {
final Reservation reservation = reservationRepository.findByIdAndReservationEmail(id, currentMemberEmail)
final Reservation reservation = reservationRepository.findByIdAndReservationEmailAndStatusIsNot(id, currentMemberEmail, Status.CANCELED)
.orElseThrow(() -> new IllegalArgumentException("자신이 예약한 회의실만 취소할 수 있습니다."));

reservation.cancel(request.reason());
Expand All @@ -62,7 +63,7 @@ public void deleteById(final Long id, final String currentMemberEmail, final Can
@Transactional
public void update(final Long id, final String currentMemberEmail, final UpdateReservationRequest request) {
validateDuplicated(request.startTime(), request.endTime(), request.roomId());
final Reservation reservation = reservationRepository.findByIdAndReservationEmail(id, currentMemberEmail)
final Reservation reservation = reservationRepository.findByIdAndReservationEmailAndStatusIsNot(id, currentMemberEmail, Status.CANCELED)
.orElseThrow(() -> new IllegalArgumentException("자신이 예약한 회의실만 수정할 수 있습니다."));

reservation.update(request.roomId(), request.startTime(), request.endTime());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.example.busan.room.dto;

import com.example.busan.reservation.domain.Reservation;
import com.example.busan.reservation.domain.Status;

import java.time.LocalTime;

public record ReservationResponse(Long reservationId, LocalTime startTime, LocalTime endTime, boolean isMine) {
public record ReservationResponse(Long reservationId, LocalTime startTime, LocalTime endTime, boolean isMine,
Status status) {

public static ReservationResponse of(final Reservation reservation, final String currentMemberEmail) {
return new ReservationResponse(
reservation.getId(),
reservation.getStartTime().toLocalTime(),
reservation.getEndTime().toLocalTime(),
reservation.getReservationEmail().equals(currentMemberEmail));
reservation.getReservationEmail().equals(currentMemberEmail),
reservation.getStatus());
}
}
26 changes: 15 additions & 11 deletions src/main/resources/static/api/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ paths:
현재 유저 정보 조회하기:
value: "{\"name\":\"연어\",\"phone\":\"01012341234\",\"email\":\"\
[email protected]\",\"role\":\"USER\",\"company\":\"우형\",\"region\"\
:\"BUSAN\",\"createdAt\":\"2023-11-27T15:23:52.095109\"}"
:\"BUSAN\",\"createdAt\":\"2023-11-29T02:23:02.327603\"}"
post:
tags:
- members
Expand Down Expand Up @@ -279,13 +279,13 @@ paths:
examples:
자신의 회의실 예약 목록 최신 순으로 보기:
value: "[{\"id\":1,\"status\":\"RESERVED\",\"cancelReason\":null,\"\
startTime\":\"2023-11-27T15:23:53.632779\",\"endTime\":\"2023-11-27T17:23:53.632784\"\
startTime\":\"2023-11-29T02:23:03.983094\",\"endTime\":\"2023-11-29T04:23:03.983099\"\
,\"name\":\"황재현\",\"phone\":\"01012341234\",\"reservedAt\":\"\
2023-11-27T15:23:53.632794\",\"roomId\":1,\"roomName\":\"대회의실\"\
2023-11-29T02:23:03.98311\",\"roomId\":1,\"roomName\":\"대회의실\"\
},{\"id\":2,\"status\":\"CANCELED\",\"cancelReason\":\"쓰기 싫어졌어\
요..\",\"startTime\":\"2023-11-27T15:23:53.632803\",\"endTime\"\
:\"2023-11-27T17:23:53.632804\",\"name\":\"황재현\",\"phone\":\"\
01012341234\",\"reservedAt\":\"2023-11-27T15:23:53.632807\",\"\
요..\",\"startTime\":\"2023-11-29T02:23:03.98312\",\"endTime\"\
:\"2023-11-29T04:23:03.983122\",\"name\":\"황재현\",\"phone\":\"\
01012341234\",\"reservedAt\":\"2023-11-29T02:23:03.983124\",\"\
roomId\":1,\"roomName\":\"대회의실\"}]"
post:
tags:
Expand Down Expand Up @@ -367,14 +367,15 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/rooms-1484123881'
$ref: '#/components/schemas/rooms397796584'
examples:
회의실 전체 조회하기:
value: "[{\"roomId\":1,\"name\":\"대회의실\",\"image\":\"image.com\"\
,\"maxPeopleCount\":10,\"reservations\":[{\"reservationId\":1,\"\
startTime\":\"13:00:00\",\"endTime\":\"16:00:00\",\"isMine\":true},{\"\
reservationId\":2,\"startTime\":\"16:00:00\",\"endTime\":\"17:00:00\"\
,\"isMine\":false}]}]"
startTime\":\"13:00:00\",\"endTime\":\"16:00:00\",\"isMine\":true,\"\
status\":\"CANCELED\"},{\"reservationId\":2,\"startTime\":\"16:00:00\"\
,\"endTime\":\"17:00:00\",\"isMine\":false,\"status\":\"RESERVED\"\
}]}]"
components:
schemas:
reservations-740649445:
Expand Down Expand Up @@ -538,7 +539,7 @@ components:
reason:
type: string
description: 취소 사유
rooms-1484123881:
rooms397796584:
type: array
items:
type: object
Expand All @@ -563,6 +564,9 @@ components:
endTime:
type: string
description: 예약 종료 시각
status:
type: string
description: 취소 여부
maxPeopleCount:
type: number
description: 최대 수용 인원 수
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/com/example/busan/room/RoomControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.busan.room;

import com.example.busan.ApiTest;
import com.example.busan.reservation.domain.Status;
import com.example.busan.room.dto.ReservationResponse;
import com.example.busan.room.dto.RoomResponse;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -34,8 +35,8 @@ class RoomControllerTest extends ApiTest {
@DisplayName("회의실 전체 조회하기")
void findAll() throws Exception {
//given
final ReservationResponse reservation1 = new ReservationResponse(1L, LocalTime.of(13, 0), LocalTime.of(16, 0), true);
final ReservationResponse reservation2 = new ReservationResponse(2L, LocalTime.of(16, 0), LocalTime.of(17, 0), false);
final ReservationResponse reservation1 = new ReservationResponse(1L, LocalTime.of(13, 0), LocalTime.of(16, 0), true, Status.CANCELED);
final ReservationResponse reservation2 = new ReservationResponse(2L, LocalTime.of(16, 0), LocalTime.of(17, 0), false, Status.RESERVED);
final RoomResponse roomResponse = new RoomResponse(1L, "대회의실", "image.com", 10, List.of(reservation1, reservation2));
given(roomService.findAllAtDate(any(), any()))
.willReturn(List.of(roomResponse));
Expand All @@ -54,7 +55,8 @@ void findAll() throws Exception {
fieldWithPath("[].reservations.[].reservationId").description("예약 ID"),
fieldWithPath("[].reservations.[].startTime").description("예약 시작 시각"),
fieldWithPath("[].reservations.[].endTime").description("예약 종료 시각"),
fieldWithPath("[].reservations.[].isMine").description("현재 로그인한 사람의 것인지 여부"))))
fieldWithPath("[].reservations.[].isMine").description("현재 로그인한 사람의 것인지 여부"),
fieldWithPath("[].reservations.[].status").description("취소 여부"))))
.andReturn()
.getResponse();

Expand Down

0 comments on commit bb433e4

Please sign in to comment.