-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#2 ] Controller, Dto 생성, 테스트코드 작성 #2
Conversation
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.
수고하셨어요! 코멘트 남겼습니다.
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/") |
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.
@RequestMapping("/api/v1/") | |
@RequestMapping("/api/v1/auth") |
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Controller |
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.
@Controller | |
@RestController |
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.
이 파일 로직은 추후에 다른 곳으로 옮기는 게 좋을 것 같네요. 😀
|
||
public record FlightDto( | ||
String flightId, // 항공편명 | ||
BigDecimal price, // 항공권 가격 |
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.
데이터 타입을 이걸로 하신 이유가 있을까요?
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.
넵
항공편명은 주로 숫자+알파벳으로 이루어져 있어서 String으로 선언하였고,
price는 원화 이외에 달러 등 소수점을 포함한 외화 가격으로도 다뤄질 것으로 예상되어 BigDecimal로 선언하였습니다.
@AutoConfigureMockMvc | ||
class BookingControllerTest { | ||
|
||
@Autowired |
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를 사용했는데 @MockMvc를 사용한 이유는 무엇인가요?
- 이 테스트를 텅해서 테스트하고 싶었던 것은 구체적으로 어떤 것일까요?
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.
@TestRestTemplate
.param("name", name) | ||
.param("birthDate", birthDate)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$[0].bookingId").value("BK001")) |
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.
들어가야하는 필드 말고, 들어가면 안되는 필드가 들어갔는지 안 들어갔는지 검증하고 싶을때는 어떻게 하나요?
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 | ||
public ResponseEntity<String> createBooking(@RequestBody BookingRequestDto bookingRequestInfo) { | ||
if (bookingRequestInfo.paymentId() == null || bookingRequestInfo.paymentId().isBlank()) { |
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.
Validation 로직은? 추후에는 없앨 예정
} | ||
|
||
|
||
@GetMapping("/my") |
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의 역할은 다시 한번 생각해보시면 좋을 것 같습니다.
.toList()); | ||
} | ||
|
||
@GetMapping("/search") |
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.
검색 결과를 보여줄 수 있는 필터들을 처리해야할 것 같습니다.
|
||
@RequestMapping(value = "/confirm") | ||
public ResponseEntity<Map<String, Object>> confirmPayment(@RequestBody String jsonBody) throws Exception { | ||
ObjectMapper objectMapper = new ObjectMapper(); |
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.
ObjectMapper는 Injection으로 받는 것이 좋을 것 같아요.
package org.onewayticket.dto; | ||
|
||
public record BookingDto( | ||
String bookingId, // 예약 ID |
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.
불변성을 지켜야하는 이유는?
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.
넵
데이터의 불변성을 지키면 데이터 무결성을 보장하는데 도움이 된다고 생각합니다.
이는 시스템의 신뢰성과 안정성 확보에 필요한 것 같습니다.
변경사항ControllerBooking ControllergetBookingDetails로 내 예약 정보 확인 메서드 통합 Flight ControllersearchFlights에 sort 매개변수 추가, 그에 따른 정렬 로직 추가 Testmockmvc 사용 테스트 -> TestRestTemplate 사용 통합테스트로 변경 |
주요 변경 사항
API 스펙에 의거한 Controller 생성
Dto 생성
BookingRequestDto
BookingDto
BookingDetailsDto
FlightDto
SpringBootTest 사용 통합 테스트 코드 작성