-
Notifications
You must be signed in to change notification settings - Fork 134
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
[Spring MVC] 김나윤 미션 제출합니다. #298
base: bbggr1209
Are you sure you want to change the base?
Conversation
열심히 한 거 같아용, 저보다 잘해서 리뷰하기 살짝 부끄럽네요🫣 간단하게 코멘트 남겼어요, 남은 미션도 파이팅!! |
@Controller | ||
public class HomeController { | ||
|
||
@GetMapping("/") | ||
public String home() { | ||
return "home"; | ||
} | ||
} |
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.
목적에 따라 컨트롤러 분리한 거 좋아보여요 굿👍
@GetMapping(value = "/reservations", produces = "application/json") | ||
@ResponseBody |
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.
GetMapping
의 produces
가 무슨 역할을 하는지 궁금해용🤓
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.
produces
는 무슨 역할을 하고 왜 썼는지 저도 궁금합니다 🧐
public class ApiResponseTemplate<T> { | ||
|
||
private final String status; | ||
private final T data; | ||
|
||
public ApiResponseTemplate(String status, T data) { | ||
this.status = status; | ||
this.data = data; | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
} |
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.
이런 식으로 API 응답에서 상태 코드와 실질적인 데이터를 분리할 수 있군요 굿👍
@DeleteMapping("/reservations/{id}") | ||
@ResponseBody | ||
public ResponseEntity<ApiResponseTemplate<String>> deleteReservation(@PathVariable Long id) { | ||
ensureReservationExists(id); | ||
removeReservation(id); | ||
return createSuccessDeleteResponse(); | ||
} |
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.
메소드 분리를 잘한 거 같아요🙂
@PostMapping("/reservations/reset") | ||
@ResponseBody | ||
public ResponseEntity<Void> resetReservations() { | ||
index.set(1); | ||
reservations.clear(); | ||
return new ResponseEntity<>(HttpStatus.NO_CONTENT); | ||
} |
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.
모든 예약 삭제 API도 구현한 건가요? 열정적인 모습👍
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) |
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.
@SpringBootTest
와 @DirtiesContext
를 알고 계셨나요?
추가적으로 공부해서 알려주세용!🤓 (LBP 전체적인 숙제였읍니당,,,)
@Test | ||
void 이단계() { |
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.
@DisplayName
을 이용해서 테스트 메소드의 목적을 명시해볼까요?
한 문장으로 표현되지 않는다면 테스트 메소드를 분리해봅시당
public class BadRequestException extends IllegalArgumentException { | ||
public BadRequestException(String message) { | ||
super(message); | ||
} |
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.
커스텀 예외 👍
커스텀 예외처리의 장점을 알려주세용👀
|
||
@PostMapping("/reservations") | ||
@ResponseBody | ||
public ResponseEntity<ApiResponseTemplate<ReservationResDto>> addReservation(@RequestBody ReservationReqDto reservationReqDto) { |
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.
ApiResponseTemplate
로 따로 더 감싸서 응답하는 이유는 뭔가용?
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import roomescape.template.ApiResponseTemplate; | ||
|
||
@ControllerAdvice |
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.
@ControllerAdvice
어노테이션은 무슨 역할을 하나요?
@GetMapping(value = "/reservations", produces = "application/json") | ||
@ResponseBody |
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.
produces
는 무슨 역할을 하고 왜 썼는지 저도 궁금합니다 🧐
@@ -0,0 +1,20 @@ | |||
package roomescape.template; | |||
|
|||
public class ApiResponseTemplate<T> { |
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.
클래스 ApiResponseTemplate<T>
에 대해서 설명해주실 수 있나요?
class MissionStepTest { | ||
|
||
@BeforeEach | ||
void 초기화() { |
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.
초기화를 통해 테스트 환경을 일관되게 제공하려고 한 점 좋은 것 같습니다 굿
No description provided.