Skip to content
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

[후_Hwi] 웹서버 4단계 - 쿠키를 이용한 로그인 구현 #75

Open
wants to merge 14 commits into
base: hooi
Choose a base branch
from

Conversation

hwicode
Copy link

@hwicode hwicode commented Apr 1, 2022

안녕하세요~ 후 앤 Hwi입니다.
3단계 요구사항 구현 완료하여 PR 보냅니다.
저희 코드를 보시고 리뷰 남겨주시는 분들께 감사드립니다.
자세한 내용은 README를 참고해주세요!
행복한 하루 되세요!😄

- 디미터의 법칙에 맞게 User가 패스워드를 판별하게 만듦
- RequestHandler의 setRequestBody 메소드에서 if else 문을 삼항연산자로 변경
- RequestHandler에서 Request에 관한 자료들을 관리하는 클래스 분할
- RequestHandler에서 Reponse에 관한 자료들을 관리하는 클래스 분할
- Controller는 인터페이스로 분리함
- DefaultController 클래스
- LogInController 클래스
- LogOutController 클래스
- SignUpController 클래스
- 기능들을 실행하는 클래스로 수정함
@hwicode hwicode added the review-BE Improvements or additions to documentation label Apr 1, 2022
@wheejuni wheejuni self-requested a review April 3, 2022 06:33
@wheejuni wheejuni self-assigned this Apr 3, 2022
Copy link

@wheejuni wheejuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고 많으셨습니다. 💯
코멘트 참고 부탁드려요~

public Response run(Request request) {
String userId = request.findBodyByFieldName("userId");
String password = request.findBodyByFieldName("password");
Optional<User> user = DataBase.findUserById(userId);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래쪽 로직을 보니 .get() 을 호출하고 있던데 옵셔널 객체를 강제 언래핑하는 것은 피해 주시고요.
User 가 이 로직 안에서 Optional 상태로 존재할 이유가 있나요? 저라면 여기서 .orElseThrow() 와 같은 편의 메소드를 사용할 것 같아요.

}

@Override
public Response run(Request request) throws IOException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭔가 로그아웃을 위한 로직은 없는 것 같습니다?


@Override
public Response run(Request request) {
byte[] body = "".getBytes();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어떤 의미인지요?

Comment on lines +44 to +49
private Runnable redirectSignUpSuccess(Request request, Map<String, String> responseHeader) {
return () -> {
createUser(request);
responseHeader.put("Location", "/index.html");
};
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runnable 은 여기서 꼭 필요한 걸까요?

Comment on lines +46 to +48
httpMethod = requestInfo[METHOD];
requestUrl = requestInfo[URL];
httpVersion = requestInfo[HTTP_VERSION];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굉장히 굉장히 사이드 이펙이 발생하기 쉬운 구조로 보이고요...
HttpRequestInfo 라는 클래스가 설계되어서, 메서드 간에는 객체의 형태로 넘나들어야 하지 않나 생각합니다.

그러니까 HttpRequestUtils.getRequestInfo() 의 리턴 타입으로 쓸만한 클래스 한 개,
적합한 파라메터를 넘겨받는 다른 private 메서드 n개가 설계돼야 할 것 같군요.


private void setRequestHeader(BufferedReader input) throws IOException {
String line;
while (!"".equals(line = URLDecoder.decode(input.readLine(), StandardCharsets.UTF_8))) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.isEmpty(), .isBlank() 와 같은 메서드들이 이미 String 에 있습니다.

@@ -0,0 +1,55 @@
package util;

public class Pair {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

데이터를 보관하는 꽤 중요한 클래스를 설계하셨는데 테스트가 한 줄도 보이지 않는군요.

Comment on lines +4 to +5
String key;
String value;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

접근제어자 누락입니다. 이런 클래스일수록 캡슐화와 은닉에 집중해야 합니다.

Comment on lines +8 to +9
this.key = key.trim();
this.value = value.trim();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 트림하는지요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-BE Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants