-
Notifications
You must be signed in to change notification settings - Fork 47
[Dion & Solar] Step1 완료했습니다. #47
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
Conversation
추출한 url에서 parameter값을 User 클래스에 담음
form의 데이터 전송방식을 GET에서 POST로 변경 Request Body로 넘어온 데이터를 파싱하여 User객체를 생성하도록 구현 Request Body를 가져올 때에는 Content-Length Request Header를 읽어서 가져오도록 구현
302 Response Status Code로 응답
findUserById를 옵셔널로 변경 요청 URL에 따라서 다른 동작을 할 수 있도록 수정 Refactoring 필요함
메소드 분리 Http Method에 대한 ENUM 클래스 생성 중복 코드 추출
setCookie 데이터 타입 변경 : String -> boolean 로그인 시 response를 302로 변경
로그인 상태가 아닐 경우, 로그인 페이지로 이동
StringBuilder를 이용해서 동적인 html을 생성하고, 이를 byte 배열로 바꿔서 body에 replace하는 코드 작성 User를 저장할 때, 인코딩이 되지않고 데이터가 들어가는 문제가 있어서 수정
RequestHandler에서 http Method를 직접 만들지 않고, HttpRequest 클래스에서 만들 수 있도록 수정 허용하지 않은 http Method가 들어오면 405 Method Not Allowed 로 로깅하도록 설정
Response Header에 Content Type을 text/css로 전달
#16 Issue resolve.
#10 Issue Resolved
Fixed #14 issue
RequestHandler에서 HttpRequest 관련 정보를 Http Request Class로 분리 Fixed #12 Issue
Fixed #11 Issue 너무 메소드가 길어서 별도의 메소드로 분리 재밌는 이름을 지어주고 싶어서 handleBar 짝퉁 hardBar로 네이밍함
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.
생소한 과제였을텐데 잘 접근해가고 있는 듯합니다.
앞으로도 기대되네요. 힘내세요!
@@ -0,0 +1,20 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project version="4"> |
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.
앗... 버전관리 되고 있는 파일 전부를 조사해보겠습니다!
@@ -0,0 +1,5 @@ | |||
package constants; | |||
|
|||
public class ContentTypeConstants { |
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.
앞으로도 계속 지원해야 할 컨텐트 타입은 늘어가겠죠.
그때를 대비해서 미리 enum
으로 만들어두는 것도 좋을 것 같네요.
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.
네!! Enum으로 추출 가능한 타입들을 추려보도록 하겠습니다.
} | ||
|
||
private void loginRequestHandler(OutputStream out, HttpRequest httpRequest) { | ||
User loginUser = DataBase.findUserById(httpRequest.getParams().get(USER_ID)).orElse(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.
헐~~
orElse(null)
이면 .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.
앗 원래는 Custom 예외를 Throw하려고 내버려 둔 부분인데, null
보다는 orElseGet
으로 어떤 객체를 생성시키는 게 더 맞았을 것 같네요.
감사합니다!
byte[] body = Files.readAllBytes(new File("./webapp" + url).toPath()); | ||
log.trace("body : {}", new String(body, UTF_8)); | ||
DataOutputStream dos = new DataOutputStream(out); | ||
if (url.endsWith(".css")) { |
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.
앞으로 우리가 내려줄 파일이 CSS뿐은 아니겠죠,
알려진 MIME Type 리스트를 잘 찾아보고, 미리 확장자와 매핑해두는 것도 좋을 겁니다. Enum을 잘 활용해볼 기회겠네요.
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.
MIME Type을 정리해서 Enum으로 만들어봐야겠네요!
} | ||
|
||
private void showUserList(OutputStream out, HttpRequest httpRequest) throws IOException { | ||
boolean isLogined; |
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.
별건 아니구요...
isLoggedIn
이 맞는 표현입니다.
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.
고치겠습니다!
.append("</td> <td>").append(user.getName()) | ||
.append("</td> <td>").append(user.getEmail()) | ||
.append("</td><td><a href=\"#\" class=\"btn btn-success\" role=\"button\">수정</a></td>").append("</tr>"); | ||
i++; |
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.
인덱스가 필요한 상황이라면 굳이 enhanced for loop을 사용하지 말고요, 전통적인 방식의 순환을 하는 것이 좋습니다. for(int i=0....
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.
아 Collection
으로 받아오니까 for loop
를 사용할 수가 없더라구요! (.get()
메소드를 제공해주지 않아서...)
그래서 enhanced for loop를 사용했습니다.
.iterator()
만 제공하길래 이렇게 사용했는데, 아예 반환 타입을 알 수 있는 Collection
객체를 사용하는게 더 낫지 않았나 생각이듭니다!
### 동적인 html 생성 | ||
|
||
* 사용자목록을 tbody로 만든 후, list.html에서 사용자 목록 부분을 어떻게 대치할까 고민 | ||
* Spring 프로젝트를 진행했을 때 아이디어를 가져와서 list.html에 동적으로 받아와서 넣어줄 부분을 `{{users}}`라는 문자열을 넣어두고, 컨트롤러에서 `{{users}}`부분을 replace해서 넣어주도록 구현함 |
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.
정말 좋은 접근 방법입니다.
나중에 우리 프로젝트가 발전해나가다보면,
핸들바즈 같은 템플릿 엔진을 만들어낼 수도 있을 겁니다.
수고하셨어요! 공부에 도움이 되었으면 좋겠네요. |
일단 요구사항을 충족시키는 것에 초점을 두고 만들어서 내일 리팩토링을 하기로 하였습니다.
HttpRequest와 HttpResponse를 만들려고 했으나, 리팩토링 단계에 포함이 되어있어 보류하였습니다.
호눅스에게 말씀드렸던 내용이지만, 서버의 Session을 구현하는 것은 2단계에서 진행해 볼 생각입니다.
객체지향이나, 테스트는 전혀 적용하지 못해서 리팩토링 과정에서 얼마나 힘든지 체감해보고자 합니다.