Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Mar 31, 2021

안녕하세요 시온, 제인입니다🙂

아직 리팩토링 진행 중이지만, HTTP 웹 서버 2단계(리팩토링) 요구사항 만족 후 중간 PR드립니다.

변경된 부분

  • RequestHandler의 책임을 HttpRequest와 HttpResponse로 분리
  • Controller 패키지를 추가하여 중복코드 및 요청 URL에 대한 분기 처리를 제거
  • session id를 UUID로 생성하여 Map의 key로 사용하고 value는 User로 하여 db에 저장
  • 테스트 코드 레거시 제거 및 softAssertions 적용
@ExtendWith(SoftAssertionsExtension.class)
class HttpRequestUtilsTest {

    @InjectSoftAssertions
    SoftAssertions softly;

assertJ 3.18.0부터 SoftAssertionsExtension을 사용할 수 있어서 버전업 후 적용해보았습니다. 😀

소중한 시간을 내어 리뷰해주셔서 감사합니다! 😊

Shion and others added 20 commits March 27, 2021 15:16
2단계 리팩토링 가이드 추가
- Controller 인터페이스 추가
- AbstractController 추상 클래스 추가
- AbstractController를 상속하는 CreateUserController, ListUserController, LoginController 클래스 추가
- URL과 Controller를 Map에 저장해서 if문 제거
- response200Header 메서드에 contentType 파라미터를 추가하여 리팩토링
HTTP 웹 서버 2단계 - 리팩토링 요구사항 1,2번 구현
HttpRequest, HttpResponse 리팩토링
- 단일책임원칙을 적용하는 방향으로 리팩토링
3단계 리팩토링 리뷰 부탁드립니다.
- assertj v.3.18.0으로 변경
- HttpRequestTest, HttpRequestUtilsTest에 SoftAssertions 적용
refactor: SoftAssertionsExtension을 활용하여 테스트 코드 리팩토링
refactor: 쓰레드풀을 사용하도록 리팩토링
wheejuni pushed a commit that referenced this pull request Apr 3, 2021
@ksundong ksundong self-requested a review April 3, 2021 10:57
@ksundong ksundong self-assigned this Apr 3, 2021
Copy link
Member

@ksundong ksundong left a comment

Choose a reason for hiding this comment

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

안녕하세요! Shion & Jane! 리뷰어 Dion입니다!
리뷰어를 등록하고 보니 저는 작년에 이 단계를 진행하지 않았더라고요!!
그래서 제가 만약에 리팩토링 한다면 어떻게 했을까? 더 개선할 포인트는 없을까? 하는 관점으로 리뷰를 해보았습니다.

테스트 코드 작성해주시는 부분 인상깊었고, AssertJ의 새로운 Feature를 시도해보는 점도 좋았습니다.
다만, 우리가 스프링에서 배웠던 내용들을 조금은 놓치고 계신것 같았어요.
그리고 자바 프로그래밍에 있어서 놓치기 쉬운 부분들 (예외 처리, Null 처리 등)이 눈에 조금 띄었습니다.

작년의 저보다 다들 잘하시는것 같아서 정말 대단하시다고 생각됩니다.
저는 작년에 User 목록을 출력해줄 때, hardBars라는 ㅋㅋㅋㅋ handleBar 짝퉁을 시도했었는데요.
한 번 도전해보시는 것도 나쁘지 않을 것 같다는 생각이 듭니다.

그리고 설계는 정답이 없기 때문에 최선을 찾아나가는 과정에서 분명히 배우시는 점이 많았을거라는 생각이 듭니다.
2단계 까지 수행해주시느라 정말 고생많으셨고, 앞으로의 미션에서 더욱더 성장하셨으면 좋겠습니다.

이번 PR은 아직 개선 포인트가 많이 보여서, Request Changes로 두겠습니다.
팀프로젝트 하시다가 심심하실 때, 수정해보세요!

Comment on lines +20 to +26
public void doPost(HttpRequest request, HttpResponse response) {

}

public void doGet(HttpRequest request, HttpResponse response) {

}
Copy link
Member

Choose a reason for hiding this comment

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

아직 리팩토링 중이어서 구현체가 없는걸까요?

Copy link
Member

Choose a reason for hiding this comment

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

만약에 오버라이딩 하기 위함이라면
abstract가 더 적절하지 않았을까 싶네요~

import http.HttpRequest;
import http.HttpResponse;

public interface Controller {
Copy link
Member

Choose a reason for hiding this comment

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

인터페이스를 사용해주셨네요 👍

Comment on lines +13 to +17
if (method.isPost()) {
doPost(request, response);
} else {
doGet(request, response);
}
Copy link
Member

Choose a reason for hiding this comment

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

if else를 제거할 수 있는 방법은 없을까요?

public void doPost(HttpRequest request, HttpResponse response) {
User user = getUserFrom(request);
DataBase.addUser(user);
response.sendRedirect("/index.html");
Copy link
Member

Choose a reason for hiding this comment

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

상수로 적절히 추출해봅시다!

Comment on lines +21 to +27
private User getUserFrom(HttpRequest request) {
String userId = request.getParameter("userId");
String password = request.getParameter("password");
String name = request.getParameter("name");
String email = request.getParameter("email");
return new User(userId, password, name, email);
}
Copy link
Member

Choose a reason for hiding this comment

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

스프링은 어떻게 이걸 처리해줄까요? 한 번 공부해봅시다.


@Test
public void parseQueryString() {
void parseQueryString() {
Copy link
Member

Choose a reason for hiding this comment

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

저는 Test에 DisplayName을 사용해 명시적인 이름을 주는걸 선호하는 편이에요~

SoftAssertions softly;

@Test
public void request_GET() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

여기 public은 빼줄 수 있겠죠?
테스트 코드의 작성은 좋습니다.


@Test
public void responseCookies() throws Exception {
// Http_Cookie.txt 결과는 응답 header에 Set-Cookie 값으로 logined=true 값이 포함되어 있어야 한다.
Copy link
Member

Choose a reason for hiding this comment

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

DisplayName으로 대신할 수 있겠죠?

import java.io.FileOutputStream;
import java.io.OutputStream;

public class HttpResponseTest {
Copy link
Member

Choose a reason for hiding this comment

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

public은 뺼 수 있습니다~

@@ -0,0 +1,4 @@
GET /user/create?userId=javajigi&password=password&name=JaeSung HTTP/1.1
Copy link
Member

Choose a reason for hiding this comment

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

궁금한게 왜 확장자는 txt인가요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants