-
Notifications
You must be signed in to change notification settings - Fork 23
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
3주차 미션 / 서버 4조 최재현 #8
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package Controller; | ||
|
||
import HttpRequest.HttpRequest; | ||
import HttpResponse.HttpResponse; | ||
|
||
public interface Controller { | ||
|
||
public abstract void execute(HttpRequest httpRequest, HttpResponse httpResponse); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package Controller; | ||
|
||
import HttpRequest.HttpRequest; | ||
import HttpResponse.HttpResponse; | ||
|
||
public class ForwardController implements Controller{ | ||
public ForwardController() { | ||
} | ||
|
||
@Override | ||
public void execute(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
System.out.println("ForwardController"); | ||
System.out.println("webapp" + httpRequest.getUrl()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 실무에서는 System.out을 사용하지 않아요! 지금부터라도 log 사용에 익숙해 지시는건 어떨까요? |
||
httpResponse.forward("webapp" + httpRequest.getUrl()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package Controller; | ||
|
||
import HttpRequest.HttpRequest; | ||
import HttpResponse.HttpResponse; | ||
import static Enum.Url.HOME_HTML; | ||
|
||
public class HomeController implements Controller{ | ||
|
||
public HomeController() { | ||
|
||
} | ||
|
||
@Override | ||
public void execute(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
httpResponse.forward(HOME_HTML.getUrl()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package Controller; | ||
|
||
import HttpRequest.HttpRequest; | ||
import HttpResponse.HttpResponse; | ||
|
||
import static Enum.Url.LIST_HTML; | ||
import static Enum.Url.LOGIN_FORM; | ||
|
||
public class ListController implements Controller{ | ||
public ListController() { | ||
} | ||
|
||
@Override | ||
public void execute(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
boolean logined = httpRequest.isLogined(); | ||
if (logined) { | ||
httpResponse.forward(LIST_HTML.getUrl()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. early return 을 사용했다면 아래 조건문이 생략 가능했을 것 같네요. |
||
} | ||
if (!logined) { | ||
httpResponse.redirect(LOGIN_FORM.getUrl()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package Controller; | ||
|
||
import HttpRequest.HttpRequest; | ||
import HttpResponse.HttpResponse; | ||
import db.MemoryUserRepository; | ||
import db.Repository; | ||
import http.util.HttpRequestUtils; | ||
import model.User; | ||
|
||
import java.util.Map; | ||
|
||
import static Enum.Url.HOME; | ||
import static Enum.Url.LOGIN_FAILED; | ||
import static Enum.UserQueryKey.PASSWORD; | ||
import static Enum.UserQueryKey.USER_ID; | ||
|
||
public class LoginController implements Controller{ | ||
|
||
public LoginController() { | ||
} | ||
@Override | ||
public void execute(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
String queryString = httpRequest.getBody(); | ||
Map<String, String> queryMap = HttpRequestUtils.parseQueryParameter(queryString); | ||
|
||
String inputUserId = queryMap.get(USER_ID.getUserQueryKey()); | ||
String inputPassword = queryMap.get(PASSWORD.getUserQueryKey()); | ||
|
||
Repository repository = MemoryUserRepository.getInstance(); | ||
User user = repository.findUserById(inputUserId); | ||
if (user != null) { | ||
if (inputPassword.equals(user.getPassword())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 두 조건식은 한 조건문 안에서 서술해도 좋을 것 같습니다! |
||
httpResponse.redirect(HOME.getUrl(), "logined=true"); | ||
return; | ||
} | ||
} | ||
httpResponse.redirect(LOGIN_FAILED.getUrl()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package Controller; | ||
|
||
import HttpRequest.HttpRequest; | ||
import HttpResponse.HttpResponse; | ||
import db.MemoryUserRepository; | ||
import db.Repository; | ||
import http.util.HttpRequestUtils; | ||
import model.User; | ||
|
||
import java.util.Map; | ||
|
||
import static Enum.Url.HOME; | ||
import static Enum.UserQueryKey.*; | ||
|
||
public class SignUpController implements Controller{ | ||
|
||
public SignUpController() { | ||
} | ||
|
||
@Override | ||
public void execute(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
//post 방식으로 회원가입하기 | ||
String queryString = httpRequest.getBody(); | ||
Map<String, String> queryMap = HttpRequestUtils.parseQueryParameter(queryString); | ||
|
||
httpResponse.redirect(HOME.getUrl()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아래 회원가입에 대한 비지니스 로직까지 완료된 이후에 리다이렉트를 응답하는게 좋을 것 같네요. 회원가입 로직에서 오류가 발생한다면 클라이언트에게 해당 오류를 전달하기 어렵지 않을까요? |
||
|
||
Repository repository = MemoryUserRepository.getInstance(); | ||
repository.addUser(new User(queryMap.get(USER_ID.getUserQueryKey()), | ||
queryMap.get(PASSWORD.getUserQueryKey()), | ||
queryMap.get(NAME.getUserQueryKey()), | ||
queryMap.get(EMAIL.getUserQueryKey()))); | ||
|
||
// //get 방식으로 회원가입하기 | ||
// if (url.equals(SIGNUP_FORM.getUrl())) { | ||
// httpResponse.forward(SIGNUP_FORM_HTML.getUrl()); | ||
// } | ||
// | ||
// if (url.startsWith(SIGNUP.getUrl()) && method.equals(GET.getMethod())) { | ||
// String queryString = url.split("\\?")[1]; | ||
// Map<String, String> queryMap = HttpRequestUtils.parseQueryParameter(queryString); | ||
// | ||
// httpResponse.redirect(HOME.getUrl()); | ||
// | ||
// repository.addUser(new User(queryMap.get(USER_ID.getUserQueryKey()), | ||
// queryMap.get(PASSWORD.getUserQueryKey()), | ||
// queryMap.get(NAME.getUserQueryKey()), | ||
// queryMap.get(EMAIL.getUserQueryKey()))); | ||
// } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package Enum; | ||
|
||
public enum HttpHeaderField { | ||
|
||
CONTENT_LENGTH("Content-Length: "), | ||
COOKIE("Cookie: "), | ||
LOCATION("Location: "), | ||
SET_COOKIE("Set-Cookie: "), | ||
CONTENT_TYPE("Content-Type: "), | ||
; | ||
|
||
|
||
private final String httpHeader; | ||
|
||
HttpHeaderField(String httpHeader) { | ||
this.httpHeader = httpHeader; | ||
} | ||
|
||
public String getHttpHeader() { | ||
return httpHeader; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package Enum; | ||
|
||
public enum Method { | ||
GET("GET"), | ||
POST("POST"); | ||
|
||
private final String method; | ||
|
||
Method(String method) { | ||
this.method = method; | ||
} | ||
|
||
public String getMethod() { | ||
return method; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package Enum; | ||
|
||
public enum StatusCode { | ||
|
||
OK("HTTP/1.1 200 OK "), | ||
FOUND("HTTP/1.1 302 Found ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. status code가 아니라 http response statusLine 에 대한 값이네요. 사용에 혼란이 있을 것 같습니다! |
||
; | ||
|
||
private final String statusCode; | ||
|
||
StatusCode(String statusCode) { | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public String getStatusCode() { | ||
return statusCode; | ||
} | ||
} |
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.
기본 생성자는 커스텀 생성자가 없을 경우 컴파일러가 자동으로 생성해주기 때문에 굳이 명시적으로 생성해주지 않아도 됩니다!