-
Notifications
You must be signed in to change notification settings - Fork 302
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
[MVC 구현하기 - 3단계] 가비 미션 제출합니다. #609
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
20d1428
feat: JSONView 작성
iamjooon2 16566a6
feat: Legacy MVC 제거
iamjooon2 cd495c4
refactor: 매직넘버 추출
iamjooon2 46bb807
chore: 개행 제거
iamjooon2 aa121fd
refactor: 변수명 변경
iamjooon2 5ffdf14
refactor: API 명세 기존과 맞도록 통일
iamjooon2 afd97cc
refactor: model에 데이터가 하나일 경우 값을 그대로 출력하도록 변경
iamjooon2 da96cb2
refactor: @Controller 내 경로 명세 제거
iamjooon2 3bdb1b2
refactor: logout 내 view 제거
iamjooon2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
app/src/main/java/com/techcourse/ManualHandlerMapping.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/techcourse/controller/HomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.techcourse.controller; | ||
|
||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import web.org.springframework.web.bind.annotation.RequestMapping; | ||
import web.org.springframework.web.bind.annotation.RequestMethod; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
@Controller | ||
public class HomeController { | ||
|
||
@RequestMapping(value = "/index", method = RequestMethod.GET) | ||
public ModelAndView showIndex(HttpServletRequest request, HttpServletResponse response) { | ||
return new ModelAndView(new JspView("index.jsp")); | ||
} | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public ModelAndView show(HttpServletRequest request, HttpServletResponse response) { | ||
return new ModelAndView(new JspView("index.jsp")); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/techcourse/controller/LoginController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.techcourse.controller; | ||
|
||
import com.techcourse.domain.User; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import web.org.springframework.web.bind.annotation.RequestMapping; | ||
import web.org.springframework.web.bind.annotation.RequestMethod; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
@Controller | ||
public class LoginController { | ||
private static final String REDIRECT_HOME = "redirect:/index.jsp"; | ||
private static final String REDIRECT_UNAUTHORIZED = "redirect:/401.jsp"; | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LoginController.class); | ||
|
||
@RequestMapping(value = "/login/view", method = RequestMethod.GET) | ||
public ModelAndView show(HttpServletRequest request, HttpServletResponse response) { | ||
return UserSession.getUserFrom(request.getSession()) | ||
.map(user -> { | ||
log.info("logged in {}", user.getAccount()); | ||
return new ModelAndView(new JspView(REDIRECT_HOME)); | ||
}) | ||
.orElse(new ModelAndView(new JspView("/login.jsp"))); | ||
} | ||
|
||
@RequestMapping(value = "/login", method = RequestMethod.POST) | ||
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) { | ||
if (UserSession.isLoggedIn(request.getSession())) { | ||
return new ModelAndView(new JspView(REDIRECT_HOME)); | ||
} | ||
|
||
return InMemoryUserRepository.findByAccount(request.getParameter("account")) | ||
.map(user -> { | ||
log.info("User : {}", user); | ||
return doLogin(request, user); | ||
}) | ||
.orElse(new ModelAndView(new JspView(REDIRECT_UNAUTHORIZED))); | ||
} | ||
|
||
private ModelAndView doLogin(HttpServletRequest request, User user) { | ||
if (user.checkPassword(request.getParameter("password"))) { | ||
final var session = request.getSession(); | ||
session.setAttribute(UserSession.SESSION_KEY, user); | ||
return new ModelAndView(new JspView(REDIRECT_HOME)); | ||
} else { | ||
return new ModelAndView(new JspView(REDIRECT_UNAUTHORIZED)); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/techcourse/controller/LogoutController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.techcourse.controller; | ||
|
||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import web.org.springframework.web.bind.annotation.RequestMapping; | ||
import web.org.springframework.web.bind.annotation.RequestMethod; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
@Controller | ||
public class LogoutController { | ||
|
||
@RequestMapping(value = "/logout", method = RequestMethod.GET) | ||
public ModelAndView show(HttpServletRequest request, HttpServletResponse response) { | ||
final var session = request.getSession(); | ||
session.removeAttribute(UserSession.SESSION_KEY); | ||
return new ModelAndView(new JspView("redirect:/")); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/techcourse/controller/RegisterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.techcourse.controller; | ||
|
||
import com.techcourse.domain.User; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import web.org.springframework.web.bind.annotation.RequestMapping; | ||
import web.org.springframework.web.bind.annotation.RequestMethod; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
@Controller | ||
public class RegisterController { | ||
|
||
@RequestMapping(value = "/register", method = RequestMethod.POST) | ||
public ModelAndView register(HttpServletRequest req, HttpServletResponse res) { | ||
final var user = new User(2, | ||
req.getParameter("account"), | ||
req.getParameter("password"), | ||
req.getParameter("email")); | ||
InMemoryUserRepository.save(user); | ||
|
||
return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
} | ||
|
||
@RequestMapping(value = "/register/view", method = RequestMethod.GET) | ||
public ModelAndView show(HttpServletRequest req, HttpServletResponse res) { | ||
return new ModelAndView(new JspView("/register.jsp")); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...controller/annotation/TestController.java → ...techcourse/controller/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/techcourse/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.techcourse.controller; | ||
|
||
import com.techcourse.domain.User; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import web.org.springframework.web.bind.annotation.RequestMapping; | ||
import web.org.springframework.web.bind.annotation.RequestMethod; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JsonView; | ||
|
||
|
||
@Controller | ||
public class UserController { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(UserController.class); | ||
|
||
@RequestMapping(value = "/api/user", method = RequestMethod.GET) | ||
public ModelAndView show(HttpServletRequest request, HttpServletResponse response) { | ||
String account = request.getParameter("account"); | ||
log.debug("user id : {}", account); | ||
|
||
ModelAndView modelAndView = new ModelAndView(new JsonView()); | ||
User user = InMemoryUserRepository.findByAccount(account) | ||
.orElseThrow(); | ||
|
||
modelAndView.addObject("user", user); | ||
return modelAndView; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
app/src/main/java/com/techcourse/controller/legacy/LoginController.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
app/src/main/java/com/techcourse/controller/legacy/LoginViewController.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
app/src/main/java/com/techcourse/controller/legacy/LogoutController.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
app/src/main/java/com/techcourse/controller/legacy/RegisterController.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
app/src/main/java/com/techcourse/controller/legacy/RegisterViewController.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...et/mvc/tobe/AnnotationHandlerAdapter.java → ...servlet/mvc/AnnotationHandlerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
여기 @controller 어노테이션이 누락된 것 같습니다!
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.
정말 죄송합니다
마음이 급했습니다