Conversation
alrscent
commented
Mar 26, 2026
- 로그인 인증을 위한 spring security 설정
- 회원가입 백엔드 API 개발
- ErrorCode 개선
| @Profile("local") | ||
| @RestController | ||
| @RequestMapping("/test") | ||
| public class TestController { |
There was a problem hiding this comment.
이 컨트롤러는 사용되지 않으면 삭제하면 어떨까요?
controller test 를 위해서 @WebMvcTest를 이용하여 테스트코드로 작성해보면 어떨까요?
| @RestController | ||
| @RequestMapping("/api") | ||
| public class MemberController { | ||
| private final MemberService memberService; |
There was a problem hiding this comment.
controller test 를 추가해보면 어떨까요?
| } | ||
|
|
||
| @PostMapping("/members") | ||
| public ResponseEntity<Void> addMember(@RequestBody @Valid MemberSignUpRequest request) { |
There was a problem hiding this comment.
MemberSignUpRequest가 valid한지 체크하는 부분도 테스트해볼 수 있을까요?
| @PostMapping("/members") | ||
| public ResponseEntity<Void> addMember(@RequestBody @Valid MemberSignUpRequest request) { | ||
| memberService.addMember(request); | ||
| return ResponseEntity.status(HttpStatus.CREATED).build(); |
There was a problem hiding this comment.
회원가입이 되고 나서 생성된 회원에 대한 정보를 필요로 할 수 있어 보입니다.
그리고 DB에 저장하게 되면 ID도 생성될 것 같고요!
회원 정보를 응답 바디로 내려주면 어떨까요?
| private String loginId; | ||
| String loginId, |
There was a problem hiding this comment.
private을 지우신 이유가 있으실까요?
| if (getMemberByLoginId(request.loginId()) != null) { | ||
| throw new QueueTixException(MemberErrorCode.MEMBER_DUPLICATED_LOGIN_ID); | ||
| } |
There was a problem hiding this comment.
getter를 통해서 데이터를 가져온 후 비교하지 않고 validate 하는 메소드로 바로 분리해보면 어떨까요?
| public Member getMemberByLoginId(String loginId) throws QueueTixException { | ||
| return memberRepository.findByLoginId(loginId) | ||
| .orElse(null); | ||
| } |
There was a problem hiding this comment.
validation을 하기 위해서 사용한 코드라면 .orElse로 null를 리턴해서 null check를 하지 않는 방향으로 수정할 수 있을까요?
| password VARCHAR(255) NOT NULL , | ||
| name VARCHAR(100) NOT NULL, | ||
| email VARCHAR(50) NOT NULL, | ||
| phone VARCHAR(12), | ||
| phone VARCHAR(13), | ||
| address VARCHAR(500) |
There was a problem hiding this comment.
사용하는 RDB에 따라서 VARCHAR 대신 TEXT 타입을 쓰는 것이 편할 수 있습니다. 어떤 RDB를 사용하실 예정이신가요?
| QueueTixException exception = assertThrows(QueueTixException.class, () -> memberService.addMember(request)); | ||
|
|
||
| assertThat(exception.getErrorCode()).isSameAs(MemberErrorCode.MEMBER_DUPLICATED_EMAIL); |
There was a problem hiding this comment.
assertThatThrownBy를 사용해보시면 어떨까요?
| ### QueueTixException 처리 테스트 | ||
| GET http://localhost:8080/test/queue-tix | ||
| Accept: application/json | ||
| ### IllegalArgumentException 처리 테스트 | ||
| GET http://localhost:8080/test/illlegal-argument | ||
| Accept: application/json | ||
| ### serverError 처리 테스트 | ||
| GET http://localhost:8080/test/server-error | ||
| Accept: application/json | ||
| ### validation Error 처리 테스트 | ||
| GET http://localhost:8080/test/validation | ||
| Accept: application/json | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "loginId": "test" | ||
| } No newline at end of file |
There was a problem hiding this comment.
헬스체크는 spring actuator를 사용해보면 어떨까요?