-
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단계] 아벨(신준혁) 미션 제출합니다. #608
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b59d375
:sparkles: feat : JspView 구현
tjdtls690 fad3786
:sparkles: feat : JsonView 구현
tjdtls690 7b16e9b
:sparkles: feat : JsonView 구현
tjdtls690 a74c45c
:sparkles: feat : 어노테이션 Controller로 전부 개선하기
tjdtls690 2c17a09
:art: refactor : LoginController 코드 가독성 개선
tjdtls690 bbba183
:art: refactor : LoginViewController 코드 가독성 개선
tjdtls690 ac04411
:fix: bug: View가 렌더링되지 않았던 버그 픽스
tjdtls690 aff7c83
:bug: fix : 테스트 코드 버그 픽스
tjdtls690 48d58de
:art: refactor : 모델의 상태에 따라 상태 코드를 구분해서 보내는 것으로 개선
tjdtls690 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
42 changes: 0 additions & 42 deletions
42
app/src/main/java/com/techcourse/ManualHandlerAdapter.java
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
app/src/main/java/com/techcourse/ManualHandlerMapping.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/techcourse/controller/ForwardController.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,16 @@ | ||
package com.techcourse.controller; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import web.org.springframework.web.bind.annotation.GetMapping; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
@context.org.springframework.stereotype.Controller | ||
public class ForwardController { | ||
|
||
@GetMapping("/") | ||
public ModelAndView execute(final HttpServletRequest request, final 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
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
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
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.GetMapping; | ||
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); | ||
|
||
@GetMapping(value = "/api/user") | ||
public ModelAndView show(HttpServletRequest request, 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(); | ||
|
||
modelAndView.addObject("user", user); | ||
return modelAndView; | ||
} | ||
Comment on lines
+19
to
+30
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. 가독성을 개선해주셨군요 👍👍 |
||
} |
50 changes: 0 additions & 50 deletions
50
app/src/test/java/com/techcourse/ManualHandlerMappingTest.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
app/src/test/java/com/techcourse/controller/UserControllerTest.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,49 @@ | ||
package com.techcourse.controller; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.techcourse.domain.User; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.AnnotationHandlerMapping; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.HandlerExecution; | ||
|
||
class UserControllerTest { | ||
private AnnotationHandlerMapping handlerMapping; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
handlerMapping = new AnnotationHandlerMapping("com.techcourse", "samples"); | ||
handlerMapping.initialize(); | ||
} | ||
|
||
@Test | ||
void show() throws Exception { | ||
final var request = mock(HttpServletRequest.class); | ||
final var response = mock(HttpServletResponse.class); | ||
|
||
final String account = "gugu"; | ||
final String password = "password"; | ||
|
||
when(request.getParameter("account")).thenReturn(account); | ||
when(request.getRequestURI()).thenReturn("/api/user"); | ||
when(request.getMethod()).thenReturn("GET"); | ||
|
||
final var handlerExecution = (HandlerExecution) handlerMapping.getHandler(request); | ||
final var modelAndView = (ModelAndView) handlerExecution.handle(request, response); | ||
final User user = (User) modelAndView.getObject("user"); | ||
|
||
assertAll( | ||
() -> assertThat(user.getAccount()).isEqualTo(account), | ||
() -> assertThat(user.checkPassword(password)).isTrue() | ||
); | ||
} | ||
} |
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.
이제 하나의 컨트롤러에서 동일한 URI에 Http 메서드로 api를 구분할 수 있게 되어서
RegisterController에서
@GetMapping("/register")
로 매핑하는 방법도 있지만,레가시 코드이기 때문에 기존에 이미 사용되고 있는 API의 명세를 바꾸지 않는 방향으로 적용해주신 것 같군요. 👍 맞나요?!?
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.
맞습니다. 일단 jsp 파일은 그대로 둔다고 가정하고 진행했기 때문에 호환성을 위해서라도 api명세를 일단 유지하는 것을 택했습니다.
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.
너무 좋은 접근 방법이라고 생각합니다!! 배워갑니당 ㅎㅎ