-
Notifications
You must be signed in to change notification settings - Fork 170
[그리디] 허석준 Spring MVC 3,4단계 제출합니다 #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
5277a36
feat: Spring Web, Thymeleaf 의존성 추가
gjtjrl303 3ae6863
docs: README 작성
gjtjrl303 6e05245
feat: 2단계 테스트 코드 작성
gjtjrl303 363baa0
feat: homeController 구현
gjtjrl303 0a84565
feat: Reservation 객체 구현
gjtjrl303 0c7afc6
feat: Reservation dto 객체 구현
gjtjrl303 2f99f81
feat: ReservationController 구현
gjtjrl303 4ceb2a8
refactor: @RequestMapping → @GetMapping으로 변경 (/ 경로)변경
gjtjrl303 698ae7e
feat: MemoryReservationRepository 구현
gjtjrl303 e09efa9
refactor: Reservation 클래스의 필드 final 제거하여 유연한 값 변경 가능하게 수정
gjtjrl303 e597d1b
refactor: controller에 있던 예약 저장 로직을 repository로 이동
gjtjrl303 d11c3a4
refactor: ReservationResponse DTO를 class에서 record로 변경
gjtjrl303 6f40799
feat: ReservationService 구현
gjtjrl303 16b13ed
feat: ReservationRequestValidator 구현
gjtjrl303 9203e52
refactor: API 전용 컨트롤러와 페이지 컨트롤러 분리
gjtjrl303 34444aa
feat: NotFoundReservationException 구현
gjtjrl303 a0685fd
feat: test코드 구현
gjtjrl303 a10ee63
docs: README 작성
gjtjrl303 f5d9211
feat: ErrorResult 객체 구현
gjtjrl303 c670ca7
refactor: Reservation 기본 생성자 삭제
gjtjrl303 958dd27
delete: ReservationController 삭제
gjtjrl303 ca8c4f1
feat: ReservationExceptionHandler 구현
gjtjrl303 6f5afca
feat: ReservationRequest dto 구현
gjtjrl303 984c1fa
feat: 충돌 해결
gjtjrl303 b98bf11
feat: 충돌 해결
gjtjrl303 99190e7
refactor: 사용하지 않는 코드 제거
gjtjrl303 6dd45ef
docs: 도메인 특화 용어 제거
gjtjrl303 809e2db
refactor: ErrorResult class에서 record로 변경
gjtjrl303 a3d38dd
feat: GlobalExceptionHandler를 통해 전역 및 예상치 못한 예외 처리 추가
gjtjrl303 8e49f4e
refactor: 테스트 코드에서 과거 날짜 → 현재 이후 날짜로 수정
gjtjrl303 5a9fc02
feat: Reservation 관련 커스텀 예외 구현
gjtjrl303 6e028d7
refactor: dto 패키지 위치 controller로 이동
gjtjrl303 ef07788
refactor: ExceptionHandler GlobalExceptionHandler로 통합
gjtjrl303 967b876
refactor: Reservation 검증 로직 entity내부로 이동
gjtjrl303 ac439b1
feat: ReservationDTO 변환을 위한 mapper 구현
gjtjrl303 7af7815
refactor: mapper를 통해 DTO 변환하도록 변경
gjtjrl303 05e844e
feat: 서비스 Reservation 반환 DTO 구현
gjtjrl303 fa64bd3
refactor: 존재하는 id 추가할때 커스텀 예외를 던지도록 변경
gjtjrl303 e5e2d78
feat: 서비스 save메서드를 위한 dto 구현
gjtjrl303 d0f88e9
delete: ReservationMapper 삭제
gjtjrl303 7001478
feat: Reservation 엔티티에 필드 검증 로직 추가
gjtjrl303 cd2ce20
refactor: ReservationRequest의 검증 로직을 메서드로 분리
gjtjrl303 660d181
refactor: DTO 변환을 Mapper에서 객체 내부 메서드로 이동
gjtjrl303 59454c7
refactor: 일관된 예외 메시지 대신 e.getMessage()로 상세 원인 제공
gjtjrl303 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
45 changes: 45 additions & 0 deletions
45
src/main/java/roomescape/controller/ReservationApiController.java
This file contains hidden or 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,45 @@ | ||
| package roomescape.controller; | ||
|
|
||
| import org.springframework.http.MediaType; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import roomescape.controller.dto.ReservationRequest; | ||
| import roomescape.controller.dto.ReservationResponse; | ||
| import roomescape.service.ReservationService; | ||
| import roomescape.service.dto.ReservationResult; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| public class ReservationApiController { | ||
|
|
||
| private final ReservationService reservationService; | ||
|
|
||
| public ReservationApiController(ReservationService reservationService) { | ||
| this.reservationService = reservationService; | ||
| } | ||
|
|
||
| @GetMapping("/reservations") | ||
| public ResponseEntity<List<ReservationResponse>> findAll() { | ||
| List<ReservationResult> all = reservationService.findAll(); | ||
| List<ReservationResponse> reservationResponses = all.stream() | ||
| .map(ReservationResponse::from) | ||
| .toList(); | ||
| return ResponseEntity.ok(reservationResponses); | ||
| } | ||
|
|
||
| @PostMapping("/reservations") | ||
| public ResponseEntity<ReservationResponse> save(@RequestBody ReservationRequest reservationRequest) { | ||
| ReservationResult result = reservationService.save(reservationRequest.toCommand()); | ||
| return ResponseEntity.created(URI.create("/reservations/" + result.id())) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .body(ReservationResponse.from(result)); | ||
| } | ||
|
|
||
| @DeleteMapping("/reservations/{id}") | ||
| public ResponseEntity<Void> delete(@PathVariable Long id) { | ||
| reservationService.delete(id); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } |
43 changes: 0 additions & 43 deletions
43
src/main/java/roomescape/controller/ReservationController.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
src/main/java/roomescape/controller/dto/ReservationRequest.java
This file contains hidden or 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,48 @@ | ||||||
| package roomescape.controller.dto; | ||||||
|
|
||||||
| import roomescape.service.dto.SaveReservationCommand; | ||||||
|
|
||||||
| import java.time.LocalDate; | ||||||
| import java.time.LocalTime; | ||||||
|
|
||||||
| public class ReservationRequest { | ||||||
| private final String name; | ||||||
| private final LocalDate date; | ||||||
| private final LocalTime time; | ||||||
|
|
||||||
| public ReservationRequest(String name, LocalDate date, LocalTime time) { | ||||||
| validate(name, date, time); | ||||||
| this.name = name; | ||||||
| this.date = date; | ||||||
| this.time = time; | ||||||
| } | ||||||
|
|
||||||
| public SaveReservationCommand toCommand() { | ||||||
| return new SaveReservationCommand(name, date, time); | ||||||
| } | ||||||
|
|
||||||
| public String getName() { | ||||||
| return name; | ||||||
| } | ||||||
|
|
||||||
| public LocalDate getDate() { | ||||||
| return date; | ||||||
| } | ||||||
|
|
||||||
| public LocalTime getTime() { | ||||||
| return time; | ||||||
| } | ||||||
|
|
||||||
| private static void validate(String name, LocalDate date, LocalTime time) { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static일 필요는 없겠어요!
Suggested change
|
||||||
| if (name == null || name.isBlank()) { | ||||||
| throw new IllegalArgumentException("이름은 필수입니다."); | ||||||
| } | ||||||
| if (date == null) { | ||||||
| throw new IllegalArgumentException("날짜는 필수입니다."); | ||||||
| } | ||||||
| if (time == null) { | ||||||
| throw new IllegalArgumentException("시간은 필수입니다."); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
22 changes: 22 additions & 0 deletions
22
src/main/java/roomescape/controller/dto/ReservationResponse.java
This file contains hidden or 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,22 @@ | ||
| package roomescape.controller.dto; | ||
|
|
||
| import roomescape.service.dto.ReservationResult; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
|
|
||
| public record ReservationResponse( | ||
| Long id, | ||
| String name, | ||
| LocalDate date, | ||
| LocalTime time | ||
| ) { | ||
|
|
||
| public static ReservationResponse from(ReservationResult result) { | ||
| return new ReservationResponse( | ||
| result.id(), | ||
| result.name(), | ||
| result.date(), | ||
| result.time() | ||
| ); | ||
| }} |
This file contains hidden or 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 hidden or 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,6 @@ | ||
| package roomescape.exception; | ||
|
|
||
| public record ErrorResult( | ||
| String code, | ||
| String message | ||
| ) {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정적 페이지를 제공하는 역할에 맞는 더 적합한 네이밍이네요.
섬세하시군요!👍