-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MVC 구현 3단계] 헙크(정현승) 미션 제출합니다. (#550)
* 패키지 위치 변경 및 코드 정리 * 서블릿 학습 테스트 코드 개선 * [MVC 구현하기 - 1단계] 헙크(정현승) 미션 제출합니다. (#384) * 패키지 위치 변경 및 코드 정리 * 서블릿 학습 테스트 코드 개선 * feat: 학습 테스트 구현 * test: Reflections 테스트 작성 * feat: AnnotationHandlerMapping 초안 * refactor: AnnotationHandlerMapping 수정 * test: Servlet 테스트 작성 --------- Co-authored-by: kang-hyungu <[email protected]> * [MVC 2단계] 헙크 미션 제출합니다 (#449) * 패키지 위치 변경 및 코드 정리 * 서블릿 학습 테스트 코드 개선 * [MVC 구현하기 - 1단계] 헙크(정현승) 미션 제출합니다. (#384) * 패키지 위치 변경 및 코드 정리 * 서블릿 학습 테스트 코드 개선 * feat: 학습 테스트 구현 * test: Reflections 테스트 작성 * feat: AnnotationHandlerMapping 초안 * refactor: AnnotationHandlerMapping 수정 * test: Servlet 테스트 작성 --------- Co-authored-by: kang-hyungu <[email protected]> * feat: HandlerMapping 구현 * feat: HandlerMappings와 Adapter 구현 * feat: DispatcherServlet에 HandlerMappings, HandlerAdapters 적용 * feat: JspView 구현 * fix: HandlerExecution 수정 * refactor: 패키지 구조 수정 * refactor: 패키지 구조 수정 * fix: DispatcherServlet 클래스의 ModelAndView의 model 반환 로직 수정 * refactor: HandlerMappings 패키지 위치 수정 --------- Co-authored-by: kang-hyungu <[email protected]> * feat: JsonView 구현 * feat: 어노테이션 기반 MVC로 수정 및 DispatcherServlet 패키지 위치 이동 * refactor: JsonView에 try-with-resources 구문 적용 * refactor: tobe 패키지 구조화 * feat: Stage3, DiContainer 구현 * feat: Stage4, DiContainer 구현 * fix: JsonView의 model 사이즈에 따른 응답값 구성 로직 수정 * refactor: RegisterController의 중복 핸들러 제거 및 예외 처리 수정 --------- Co-authored-by: kang-hyungu <[email protected]>
- Loading branch information
1 parent
e3ae1b7
commit cc78e76
Showing
27 changed files
with
255 additions
and
171 deletions.
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
47 changes: 0 additions & 47 deletions
47
app/src/main/java/com/techcourse/ManualHandlerMapping.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/techcourse/controller/IndexController.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,18 @@ | ||
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 IndexController { | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) { | ||
return new ModelAndView(new JspView("index.jsp")); | ||
} | ||
} |
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
22 changes: 0 additions & 22 deletions
22
app/src/main/java/com/techcourse/controller/LoginViewController.java
This file was deleted.
Oops, something went wrong.
17 changes: 11 additions & 6 deletions
17
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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
package com.techcourse.controller; | ||
|
||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import webmvc.org.springframework.web.servlet.mvc.asis.Controller; | ||
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; | ||
|
||
public class LogoutController implements Controller { | ||
@Controller | ||
public class LogoutController { | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { | ||
final var session = req.getSession(); | ||
@RequestMapping(value = "/logout", method = RequestMethod.GET) | ||
public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) { | ||
final var session = request.getSession(); | ||
session.removeAttribute(UserSession.SESSION_KEY); | ||
return "redirect:/"; | ||
return new ModelAndView(new JspView("redirect:/")); | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
app/src/main/java/com/techcourse/controller/RegisterAnnotationController.java
This file was deleted.
Oops, something went wrong.
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
13 changes: 0 additions & 13 deletions
13
app/src/main/java/com/techcourse/controller/RegisterViewController.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
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) { | ||
final String account = request.getParameter("account"); | ||
log.info("user id : {}", account); | ||
|
||
final ModelAndView modelAndView = new ModelAndView(new JsonView()); | ||
final User user = InMemoryUserRepository.findByAccount(account) | ||
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 사용자입니다.")); | ||
|
||
modelAndView.addObject("user1", user); | ||
// modelAndView.addObject("user2", user); | ||
// modelAndView.addObject("user3", "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
3 changes: 2 additions & 1 deletion
3
...et/mvc/tobe/AnnotationHandlerAdapter.java → ...dleradapter/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
2 changes: 1 addition & 1 deletion
2
.../web/servlet/mvc/tobe/HandlerAdapter.java → ...c/tobe/handleradapter/HandlerAdapter.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
2 changes: 1 addition & 1 deletion
2
...web/servlet/mvc/tobe/HandlerAdapters.java → .../tobe/handleradapter/HandlerAdapters.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
2 changes: 1 addition & 1 deletion
2
...ervlet/mvc/tobe/ManualHandlerAdapter.java → .../handleradapter/ManualHandlerAdapter.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
2 changes: 1 addition & 1 deletion
2
...et/mvc/tobe/AnnotationHandlerMapping.java → ...dlermapping/AnnotationHandlerMapping.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
2 changes: 1 addition & 1 deletion
2
...eb/servlet/mvc/tobe/HandlerExecution.java → ...tobe/handlermapping/HandlerExecution.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
2 changes: 1 addition & 1 deletion
2
...work/web/servlet/mvc/tobe/HandlerKey.java → ...t/mvc/tobe/handlermapping/HandlerKey.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.