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

3주차 미션 / 서버 3조 김상균 #2

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/main/java/constant/HttpHeaderTitle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package constant;

public enum HttpHeaderTitle {

CONTENT_TYPE("Content-Type"),
CONTENT_LENGTH("Content-Length"),
LOCATION("Location"),
SET_COOKIE("Set-Cookie"),
COOKIE("Cookie");

String headerTitle;

private HttpHeaderTitle(String headerTitle) {
this.headerTitle = headerTitle;
}

public String getHeaderTitle() {
return headerTitle;
}
}
17 changes: 17 additions & 0 deletions src/main/java/constant/HttpMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package constant;

public enum HttpMethod {

GET("GET"),
POST("POST");

final String method;

private HttpMethod(String method) {
this.method = method;
}

public String getMethod() {
return method;
}
}
19 changes: 19 additions & 0 deletions src/main/java/constant/QueryKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package constant;

public enum QueryKey {

USERID("userId"),
PASSWORD("password"),
NAME("name"),
EMAIL("email");

String key;

private QueryKey(String key){
this.key = key;
}

public String getKey(){
return key;
}
}
29 changes: 29 additions & 0 deletions src/main/java/constant/StatusCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package constant;

public enum StatusCode {

OK("200", "OK"),
Found("302", "Found");


final String code;
final String message;

private StatusCode(String code, String message) {
this.code = code;
this.message = message;
}

public String getStatusCode() {
return code;
}

public String getMessage() {
return message;
}

@Override
public String toString() {
return code + " " + message;
}
}
27 changes: 27 additions & 0 deletions src/main/java/constant/Url.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package constant;

public enum Url {

WEBAPP("webapp"),
ROOT("/"),
INDEX_HTML("/index.html"),
USER_FORM_HTML("/user/form.html"),
USER_SIGNUP("/user/signup"),
USER_LOGIN("/user/login"),
USER_LOGIN_HTML("/user/login.html"),
USER_LOGIN_FAILED_HTML("/user/login_failed.html"),
USER_USERLIST("/user/userList"),
USER_LIST_HTML("/user/list.html"),
CSS_EXTENSION(".css"),
HTML_EXTENSION(".html");

final String url;

private Url(String url){
this.url = url;
}

public String getUrl() {
return url;
}
}
11 changes: 11 additions & 0 deletions src/main/java/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package controller;

import http.request.HttpRequest;
import http.response.HttpResponse;

import java.io.IOException;

public interface Controller {

void execute(HttpRequest request, HttpResponse response) throws IOException;
}
34 changes: 34 additions & 0 deletions src/main/java/controller/ForwardController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package controller;


import http.request.HttpRequest;
import http.response.HttpResponse;

import java.io.IOException;

import static constant.Url.*;

public class ForwardController implements Controller {

@Override
public void execute(HttpRequest request, HttpResponse response) throws IOException {

// form.html, login.html, login_failed.html 에서는 list.html 에 forward 방식으로 바로 접근한다. 따라서 검증 로직을
// 이 위치에도 한 번 더 적용해주었다.
if (request.getUrl().equals(USER_LIST_HTML.getUrl())) {
boolean login = request.checkLogin();
Copy link
Member

Choose a reason for hiding this comment

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

로그인 여부를 확인하는게 HttpRequest의 역할일까요?? 😅


if (login) {
response.forward(USER_LIST_HTML.getUrl());
return;
}

response.redirect(USER_LOGIN_HTML.getUrl());
return;

}

response.forward(request.getUrl());
}

}
16 changes: 16 additions & 0 deletions src/main/java/controller/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package controller;

import http.request.HttpRequest;
import http.response.HttpResponse;

import java.io.IOException;

import static constant.Url.INDEX_HTML;

public class HomeController implements Controller{

@Override
public void execute(HttpRequest request, HttpResponse response) throws IOException {
response.forward(INDEX_HTML.getUrl());
}
}
24 changes: 24 additions & 0 deletions src/main/java/controller/ListController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package controller;

import http.request.HttpRequest;
import http.response.HttpResponse;

import java.io.IOException;

import static constant.Url.USER_LIST_HTML;
import static constant.Url.USER_LOGIN_HTML;

public class ListController implements Controller {
@Override
public void execute(HttpRequest request, HttpResponse response) throws IOException {
boolean login = request.checkLogin();

if (login) {
response.redirect(USER_LIST_HTML.getUrl());
return;
}

response.redirect(USER_LOGIN_HTML.getUrl());

}
}
Loading