-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
686 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
backend/src/main/java/org/example/backend/reservation/controller/ReservationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.example.backend.reservation.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.backend.reservation.domain.ReservationStatus; | ||
import org.example.backend.reservation.domain.dto.ReservationReqDto; | ||
import org.example.backend.reservation.domain.dto.ReservationResDto; | ||
import org.example.backend.reservation.service.ReservationService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/reservations") | ||
public class ReservationController { | ||
private final ReservationService reservationService; | ||
|
||
@PostMapping | ||
public ResponseEntity<ReservationResDto> createReservation(@RequestBody ReservationReqDto reqDto) { | ||
ReservationResDto resDto = reservationService.createReservation(reqDto); | ||
return ResponseEntity.ok(resDto); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<ReservationResDto>> getAllReservations() { | ||
List<ReservationResDto> reservations = reservationService.getAllReservations(); | ||
return ResponseEntity.ok(reservations); | ||
} | ||
|
||
@GetMapping("/{reservationId}") | ||
public ResponseEntity<ReservationResDto> getReservation(@PathVariable(value = "reservationId") Long id) { | ||
ReservationResDto resDto = reservationService.getReservation(id); | ||
return ResponseEntity.ok(resDto); | ||
} | ||
|
||
@PatchMapping("/{reservationId}/status") | ||
public ResponseEntity<ReservationResDto> updateReservationStatus( | ||
@PathVariable(value = "reservationId") Long id, | ||
@RequestParam(value = "status") ReservationStatus status) { | ||
ReservationResDto resDto = reservationService.updateReservationStatus(id, status); | ||
return ResponseEntity.ok(resDto); | ||
} | ||
|
||
@DeleteMapping("/{reservationId}") | ||
public ResponseEntity<Void> deleteReservation(@PathVariable(value = "reservationId") Long id) { | ||
reservationService.deleteReservation(id); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/org/example/backend/reservation/domain/ReservationPurpose.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
package org.example.backend.reservation.domain; | ||
|
||
public enum ReservationPurpose { | ||
SEMINAR("세미나"), | ||
MEETING("회의"), | ||
STUDY("스터디"), | ||
CLASS("수업"), | ||
OTHER("기타"); | ||
|
||
private final String description; | ||
|
||
ReservationPurpose(String description) { | ||
this.description = description; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/org/example/backend/reservation/domain/ReservationStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
package org.example.backend.reservation.domain; | ||
|
||
public enum ReservationStatus { | ||
PENDING("대기중"), | ||
APPROVED("승인됨"), | ||
REJECTED("거절됨"), | ||
CANCELLED("취소됨"); | ||
|
||
private final String description; | ||
|
||
ReservationStatus(String description) { | ||
this.description = description; | ||
|
||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
backend/src/main/java/org/example/backend/reservation/domain/dto/ReservationReqDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.example.backend.reservation.domain.dto; | ||
|
||
|
||
import java.time.LocalDateTime; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.example.backend.reservation.domain.ReservationPurpose; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ReservationReqDto { | ||
private LocalDateTime startTime; | ||
private LocalDateTime endTime; | ||
private ReservationPurpose purpose; | ||
private String etc; | ||
private Long seminarRoomId; | ||
private Long userId; | ||
|
||
@Builder | ||
private ReservationReqDto(LocalDateTime startTime, LocalDateTime endTime, | ||
ReservationPurpose purpose, String etc, Long seminarRoomId, Long userId) { | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.purpose = purpose; | ||
this.etc = etc; | ||
this.seminarRoomId = seminarRoomId; | ||
this.userId = userId; | ||
} | ||
|
||
public static ReservationReqDto of(LocalDateTime startTime, LocalDateTime endTime, | ||
ReservationPurpose purpose, String etc, Long seminarRoomId, Long userId) { | ||
return ReservationReqDto.builder() | ||
.startTime(startTime) | ||
.endTime(endTime) | ||
.purpose(purpose) | ||
.etc(etc) | ||
.seminarRoomId(seminarRoomId) | ||
.userId(userId) | ||
.build(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
backend/src/main/java/org/example/backend/reservation/domain/dto/ReservationResDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.example.backend.reservation.domain.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.example.backend.reservation.domain.Reservation; | ||
import org.example.backend.reservation.domain.ReservationPurpose; | ||
import org.example.backend.reservation.domain.ReservationStatus; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ReservationResDto { | ||
private Long id; | ||
private LocalDateTime startTime; | ||
private LocalDateTime endTime; | ||
private ReservationPurpose purpose; | ||
private String etc; | ||
private ReservationStatus status; | ||
private String seminarRoomName; | ||
private Long userId; | ||
|
||
@Builder | ||
private ReservationResDto(Long id, LocalDateTime startTime, LocalDateTime endTime, | ||
ReservationPurpose purpose, String etc, ReservationStatus status, | ||
String seminarRoomName, Long userId) { | ||
this.id = id; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.purpose = purpose; | ||
this.etc = etc; | ||
this.status = status; | ||
this.seminarRoomName = seminarRoomName; | ||
this.userId = userId; | ||
} | ||
|
||
public static ReservationResDto of(Reservation reservation) { | ||
return ReservationResDto.builder() | ||
.id(reservation.getId()) | ||
.startTime(reservation.getStartTime()) | ||
.endTime(reservation.getEndTime()) | ||
.purpose(reservation.getPurpose()) | ||
.etc(reservation.getEtc()) | ||
.status(reservation.getStatus()) | ||
.seminarRoomName(reservation.getSeminarRoom().getName()) | ||
.userId(reservation.getUserId()) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/org/example/backend/reservation/exception/ReservationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.example.backend.reservation.exception; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.backend.common.exception.BaseException; | ||
import org.example.backend.common.exception.BaseExceptionType; | ||
|
||
@RequiredArgsConstructor | ||
public class ReservationException extends BaseException { | ||
private final ReservationExceptionType exceptionType; | ||
|
||
@Override | ||
public BaseExceptionType exceptionType() { | ||
return exceptionType; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...end/src/main/java/org/example/backend/reservation/exception/ReservationExceptionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.example.backend.reservation.exception; | ||
|
||
import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
import static org.springframework.http.HttpStatus.NOT_FOUND; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.backend.common.exception.BaseExceptionType; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@RequiredArgsConstructor | ||
public enum ReservationExceptionType implements BaseExceptionType { | ||
|
||
NOT_FOUND_RESERVATION(NOT_FOUND, "예약을 찾을 수 없습니다"), | ||
EXIST_ALREADY_RESERVATION(BAD_REQUEST, "해당 시간에 이미 승인된 예약이 존재합니다."), | ||
CONFLICT_TIMETABLE(BAD_REQUEST, "해당 시간에 정기 수업이 있어 예약이 불가능합니다."), | ||
INVALID_TIME_ORDER(BAD_REQUEST, "시작 시간은 종료 시간보다 이후일 수 없습니다."), // 새 예외 | ||
EXCEEDS_MAX_DURATION(BAD_REQUEST, "예약은 최대 2시간까지만 가능합니다."), | ||
PAST_TIME_RESERVATION(BAD_REQUEST, "과거의 시간으로 예약할 수 없습니다."), | ||
; | ||
|
||
private final HttpStatus httpStatus; | ||
private final String errorMessage; | ||
|
||
@Override | ||
public HttpStatus httpStatus() { | ||
return httpStatus; | ||
} | ||
|
||
@Override | ||
public String errorMessage() { | ||
return errorMessage; | ||
} | ||
} |
Oops, something went wrong.