-
Notifications
You must be signed in to change notification settings - Fork 305
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단계] 몰리(김지민) 미션 제출합니다. #826
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
59f49c6
refactor(JsonView): JSON으로 응답할 수 있도록 JsonView 클래스 구현
jminkkk 526aa44
refactor(LoginController): Annotation 기반으로 변경
jminkkk 3c7e2f6
refactor(LogoutController): Annotation 기반으로 변경
jminkkk cc4bf46
refactor(IndexController): Annotation 기반으로 변경
jminkkk 9fc5a5e
refactor(/asis): controller 인터페이스 기반 레거시 @Deprecated 처
jminkkk 295f360
refactor(/): 패키지 구조 개편
jminkkk 8036b93
refactor(DispatcherServlet): 애플리케이션 기본 패키지를 외부에서 주입
jminkkk eb72ebb
refactor(UserController): 요구사항에 주어진 컨트롤러 클래스 구현
jminkkk dd7e2f6
refactor(JsonView): 데이터가 1개일 경우 로직 변경
jminkkk 121c474
refactor(DIContainer): 필드 주입 로직 구현
jminkkk 7e310c0
refactor(ClassPathScanner): 패키지 경로로부터 해당하는 클래스를 반환하는 스캐너 구현
jminkkk ea54e80
refactor(DIContainer): @Service, @Repository Component 빈 등록 및 @Inject…
jminkkk d14dd84
refactor(DispatcherServletInitializer): DispatcherServletInitializer …
jminkkk a4d55f7
refactor(DIContainer): 에러 메시지 오타 수정
jminkkk b7add77
refactor(DIContainer): 빈을 찾을 수 없는 경우 IllegalArgumentException 발생
jminkkk af782c8
refactor(ClassPathScanner): 가변 인자 메서드만 남기고 제거
jminkkk d89ecb7
refactor(ClassPathScanner): 사용하지 않는 메서드 제거
jminkkk 16c2c7b
refactor(JsonView): 데이터가 없는 경우 예외가 아닌 null을 반환하도록 변경
jminkkk e3407a2
test(JsonView): 데이터가 없다면 null 반환하는 테스트 추가
jminkkk 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
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
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
package com.techcourse.controller; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
import com.interface21.context.stereotype.Controller; | ||
import com.interface21.web.bind.annotation.RequestMapping; | ||
import com.interface21.web.bind.annotation.RequestMethod; | ||
import com.interface21.webmvc.servlet.ModelAndView; | ||
import com.interface21.webmvc.servlet.view.JspView; | ||
|
||
@Controller | ||
public class IndexController { | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public ModelAndView getIndexPage(final HttpServletRequest req, final HttpServletResponse res) { | ||
return new ModelAndView(new JspView("/index.jsp")); | ||
} | ||
} |
39 changes: 28 additions & 11 deletions
39
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 |
---|---|---|
@@ -1,37 +1,54 @@ | ||
package com.techcourse.controller; | ||
|
||
import com.techcourse.domain.User; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import com.interface21.webmvc.servlet.mvc.asis.Controller; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class LoginController implements Controller { | ||
import com.interface21.context.stereotype.Controller; | ||
import com.interface21.web.bind.annotation.RequestMapping; | ||
import com.interface21.web.bind.annotation.RequestMethod; | ||
import com.interface21.webmvc.servlet.ModelAndView; | ||
import com.interface21.webmvc.servlet.view.JspView; | ||
import com.techcourse.domain.User; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
|
||
@Controller | ||
public class LoginController { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LoginController.class); | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { | ||
@RequestMapping(value = "/login", method = RequestMethod.GET) | ||
public ModelAndView getLoginPage(final HttpServletRequest req, final HttpServletResponse res) { | ||
return UserSession.getUserFrom(req.getSession()) | ||
.map(user -> { | ||
log.info("logged in {}", user.getAccount()); | ||
return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
}) | ||
.orElse(new ModelAndView(new JspView("/login.jsp"))); | ||
} | ||
|
||
@RequestMapping(value = "/login", method = RequestMethod.POST) | ||
public ModelAndView postLogin(final HttpServletRequest req, final HttpServletResponse res) { | ||
if (UserSession.isLoggedIn(req.getSession())) { | ||
return "redirect:/index.jsp"; | ||
return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
} | ||
|
||
return InMemoryUserRepository.findByAccount(req.getParameter("account")) | ||
.map(user -> { | ||
log.info("User : {}", user); | ||
return login(req, user); | ||
}) | ||
.orElse("redirect:/401.jsp"); | ||
.orElse(new ModelAndView(new JspView("redirect:/401.jsp"))); | ||
} | ||
|
||
private String login(final HttpServletRequest request, final User user) { | ||
private ModelAndView login(final HttpServletRequest request, final User user) { | ||
if (user.checkPassword(request.getParameter("password"))) { | ||
final var session = request.getSession(); | ||
session.setAttribute(UserSession.SESSION_KEY, user); | ||
return "redirect:/index.jsp"; | ||
return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
} | ||
return "redirect:/401.jsp"; | ||
return new ModelAndView(new JspView("redirect:/401.jsp")); | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
app/src/main/java/com/techcourse/controller/LoginViewController.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
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 jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.interface21.context.stereotype.Controller; | ||
import com.interface21.web.bind.annotation.RequestMapping; | ||
import com.interface21.web.bind.annotation.RequestMethod; | ||
import com.interface21.webmvc.servlet.ModelAndView; | ||
import com.interface21.webmvc.servlet.view.JsonView; | ||
import com.techcourse.domain.User; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
|
||
@Controller | ||
public class UserController { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(UserController.class); | ||
|
||
@RequestMapping(value = "/api/user", method = RequestMethod.GET) | ||
public ModelAndView show(final HttpServletRequest request, final HttpServletResponse response) { | ||
final String account = request.getParameter("account"); | ||
log.debug("user id : {}", account); | ||
|
||
final ModelAndView modelAndView = new ModelAndView(new JsonView()); | ||
final User user = InMemoryUserRepository.findByAccount(account) | ||
.orElseThrow(() -> new IllegalArgumentException("해당 사용자가 존재하지 않습니다. 다시 로그인 해주세요.")); | ||
|
||
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
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
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
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
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
4 changes: 1 addition & 3 deletions
4
...21/webmvc/servlet/mvc/HandlerAdapter.java → ...face21/webmvc/servlet/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
...21/webmvc/servlet/mvc/HandlerMapping.java → ...face21/webmvc/servlet/HandlerMapping.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
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
...c/servlet/mvc/tobe/ClassInstantiator.java → ...webmvc/servlet/mvc/ClassInstantiator.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
...c/servlet/mvc/tobe/ControllerScanner.java → ...webmvc/servlet/mvc/ControllerScanner.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
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
...vc/servlet/mvc/tobe/HandlerExecution.java → .../webmvc/servlet/mvc/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
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
...1/webmvc/servlet/mvc/tobe/HandlerKey.java → ...face21/webmvc/servlet/mvc/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
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
.../servlet/mvc/tobe/RequestMappingInfo.java → ...ebmvc/servlet/mvc/RequestMappingInfo.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.
@Deprecated
활용 저는 생각도 못했는데 괜찮네요..