-
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단계] 블랙캣(송우석) 미션 제출합니다. #591
Changes from 10 commits
7113253
93ddef7
8bdb8ea
46ad624
8b124d0
b6c9987
5db2967
c567d07
a3cfc77
bce877a
8e54dea
b65c405
cfc9f90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.techcourse.controller; | ||
|
||
import context.org.springframework.stereotype.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; | ||
|
||
@Controller | ||
public class IndexController { | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public ModelAndView index() { | ||
return new ModelAndView(new JspView("/index.jsp")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
package com.techcourse.controller; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpSession; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
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 LoginViewController implements Controller { | ||
@Controller | ||
public class LoginViewController { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LoginViewController.class); | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { | ||
return UserSession.getUserFrom(req.getSession()) | ||
@RequestMapping(value = "/login/view", method = RequestMethod.GET) | ||
public ModelAndView loginView(final HttpSession session) { | ||
return UserSession.getUserFrom(session) | ||
.map(user -> { | ||
log.info("logged in {}", user.getAccount()); | ||
return "redirect:/index.jsp"; | ||
}) | ||
.orElse("/login.jsp"); | ||
.map(it -> new ModelAndView(new JspView(it))) | ||
.orElse(new ModelAndView(new JspView("/login.jsp"))); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
package com.techcourse.controller; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import webmvc.org.springframework.web.servlet.mvc.asis.Controller; | ||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpSession; | ||
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(final HttpSession session) { | ||
session.removeAttribute(UserSession.SESSION_KEY); | ||
return "redirect:/"; | ||
return new ModelAndView(new JspView("redirect:/")); | ||
} | ||
} |
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.dto.UserRequest; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
import context.org.springframework.stereotype.Controller; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import web.org.springframework.web.bind.annotation.RequestBody; | ||
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(@RequestBody final UserRequest request) { | ||
final String account = request.getAccount(); | ||
log.debug("user id : {}", account); | ||
|
||
final ModelAndView modelAndView = new ModelAndView(new JsonView()); | ||
final User user = InMemoryUserRepository.findByAccount(account) | ||
.orElseThrow(); | ||
|
||
modelAndView.addObject("user", user); | ||
return modelAndView; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.techcourse.dto; | ||
|
||
public class RegisterRequest { | ||
|
||
private String account; | ||
private String password; | ||
private String email; | ||
|
||
public RegisterRequest() { | ||
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. dto패키지 내부에 있는 클래스들에 대해서는 public생성자를 명시해주셨네요. 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.
참고로 스프링에서는 기본적으로 추가적으로 |
||
} | ||
|
||
public RegisterRequest(final String account, final String password, final String email) { | ||
this.account = account; | ||
this.password = password; | ||
this.email = email; | ||
} | ||
|
||
public String getAccount() { | ||
return account; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
} |
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.
LoginController는 view에 대한 클래스가 분리되어있는 것으로 확인이 됩니다.
사소하지만 둘 중 하나로 통일성있게 변경해보는 것은 어떨까요?
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.
미쳐 확인하지 못했네요!
회원가입 컨트롤러와 같이 하나의 컨트롤러로 통합하였습니다!