-
Notifications
You must be signed in to change notification settings - Fork 1
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
feature: 방 만들기 기능 구현 완료 #5
Conversation
Body의 방 설정 정보(RoomSettings)를 참고하여 새로운 방을 생성합니다.
각 IP는 최대 1개의 방을 hosting 할 수 있습니다.
새로운 방 생성에 성공하면 room code를 반환합니다.
RoomStorage → RedisStorage
요청 데이터에서 오류가 발생한 경우에 대한 예제를 추가합니다. (BindException.class)
요청 데이터에서 오류가 발생한 경우에 대한 예제를 추가합니다. (BindException.class)
세션 쿠키를 갖고 있다는 것은 이미 방에 참가 중임을 암시합니다. 따라서 새로운 방을 생성할 수 없습니다.
세션 쿠키를 갖고 있다는 것은 이미 방에 참가 중임을 암시합니다. 따라서 새로운 방을 생성할 수 없습니다.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Test Coverage Report
|
WebDataBinderFactory binderFactory) throws Exception { | ||
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); | ||
|
||
assert request != null; |
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.
assert 를 사용하면 얻는 효과가 뭔가요?
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.
초기 단계에서 객체를 확인을 하여 나중에 더 모호한 NullPointerException으로 실패하는 것을 방지합니다.
위 코드는 IDE에서 제안하는 사항 중 하나입니다.
좀 더 개선된 응답을 제공하고자 한다면, 다음과 같이 작성할 수 있습니다.
assert request != null; | |
if (request == null) { | |
throw new IllegalArgumentException("HttpServletRequest는 null일 수 없습니다"); | |
} |
@Range(min = 2, max = 10) | ||
private int capacity; | ||
|
||
@Pattern(regexp = "^[0-9a-zA-Z]{5,10}$") |
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.
기본 설정값으로 응답합니다.
더 자세한 응답 메시지를 원하신다면 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.
현재 응답 예시입니다.
{
"code": 400,
"status": "Bad Request",
"result": "예외가 발생했습니다",
"data": [
{
"type": "password",
"message": "must match \"^[0-9a-zA-Z]{5,10}$\""
},
{
"type": "title",
"message": "must not be blank"
},
{
"type": "capacity",
"message": "must be between 2 and 10"
}
]
}
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.
다음과 같이 메시지를 추가했습니다.
{
"code": 400,
"status": "Bad Request",
"result": "예외가 발생했습니다",
"data": [
{
"type": "password",
"message": "비밀번호는 5자 이상 10자 이하의 영문 또는 숫자로 입력해 주세요"
},
{
"type": "title",
"message": "공백이 아닌 문자를 1개 이상 입력해 주세요"
},
{
"type": "capacity",
"message": "정원은 2명 이상 10명 이하로 입력해 주세요"
}
]
}
{
"code": 400,
"status": "Bad Request",
"result": "예외가 발생했습니다",
"data": [
{
"type": "password",
"message": "비밀번호는 5자 이상 10자 이하의 영문 또는 숫자로 입력해 주세요"
},
{
"type": "title",
"message": "제목은 1자 이상 30자 이하로 입력해 주세요"
},
{
"type": "capacity",
"message": "정원은 2명 이상 10명 이하로 입력해 주세요"
}
]
}
"GoldenGlider", "CrimsonFalcon", "EchoingWhisper", "EmberPhoenix", "RadiantRebel" | ||
); | ||
|
||
int randomIndex = ThreadLocalRandom.current().nextInt(samples.size()); |
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.
ThreadLocalRandom은 난수를 생성하는 클래스입니다.
각 스레드마다 고유한 난수 생성기를 사용하기 때문에 서로 간섭받지 않고 독립적인 수를 생성할 수 있습니다.
또한 동기화를 사용하지 않기 때문에 Random 클래스보다 성능적인 이점이 있습니다.
.current()
는 현재 스레드에서 사용할 ThreadLocalRandom 인스턴스를 반환합니다..nextInt(int bound)
는 bound 내의 난수를 생성합니다. (이때, bound 값을 포함하지 않습니다.)
|
||
// then | ||
Room room = roomStorage.findById(roomCode.getRoomCode()).orElseThrow(); | ||
User user = userStorage.findById(sessionCode).orElseThrow(); |
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.
ㅋㅋㅋㅋ optional 억지로 가져오고 싶으면 그냥 .get 사용해도 될거같아요
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.
ㅋㅋㅋㅋ 굿
잘봤습니다~!!! 역시 yeonise.. |
Test Coverage Report
|
1. 구현 내용 관련
getRemoteAddr()
getRemoteAddr()
을 통해 사용자 IP를 가져옵니다.블로그 글을 참고하여 위 설정을 추가했습니다.
Session Cookie
세션 쿠키와 관련된 로직은 컨트롤러 단에서 처리하고자 했습니다.
@CookieValue
를 사용하여 세션 쿠키가 존재하는지 확인하고, 존재한다면 이미 다른 방에 참가하고 있다고 판단했습니다.2. 테스트 및 API 문서 관련
RestDocsSupport : Controller test + REST Docs 문서 생성
@Import(PropertiesConfig.class)
를 추가하여application-test.yml
에서 설정한 cookieProperties를 가져오도록 했습니다.andExpect()
를 적극적으로 사용하여 보다 꼼꼼하게 검증하고자 했습니다.IntegrationTestSupport : 통합 환경에서의 테스트
Asciidoc 문서 형식 커스터마이징
test-report.yml workflow 변경