-
Notifications
You must be signed in to change notification settings - Fork 379
[JDBC 라이브러리 구현하기 - 1, 2단계] 현구막(최현구) 미션 제출합니다. #34
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
Merged
Merged
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
22072d5
test: 학습 테스트 완성
Hyeon9mak d9cfaa1
refactor: User 클래스 멤버 변수 설정 리팩토링
Hyeon9mak 6d62613
refactor: UserDao.insert시 id(primary key)를 포함한 User를 반환하도록 변경
Hyeon9mak 80140bd
feat: UserDao.update 구현
Hyeon9mak c158788
feat: UserDao.findAll, UserDao.deleteAll 구현
Hyeon9mak 2d3fb19
feat: UserDao.findById, UserDao.findByAccount 구현
Hyeon9mak 91695f5
refactor: UserDao.deleteAll, UserDao.update 책임 분리
Hyeon9mak acf57da
refactor: JdbcTemplate 생성 및 데이터베이스 작업 수행 책임 분리
Hyeon9mak d9225b1
refactor: queryForObject, query 구현 및 JdbcTemplate 패키지 위치 변경
Hyeon9mak 54898b1
docs: Todo 리스트 업데이트
Hyeon9mak 8fab7ae
feat: 커스텀 예외처리 적용
Hyeon9mak 4e4415a
feat: SimpleJdbcInsert 구현
Hyeon9mak 4b17405
refactor: SimpleJdbcInsert 커스텀 예외 추가 및 변수명 리팩토링
Hyeon9mak 308315d
refactor: DatabasePopulatorUtils 메서드 분리
Hyeon9mak dbf9765
refactor: mvc 모듈 리팩토링
Hyeon9mak 1f0c15d
refactor: jdbcTemplate 에서 Optional을 반환하도록 변경
Hyeon9mak 37087bf
refactor: 사용되지 않는 import 제거
Hyeon9mak 832fb74
refactor: app 모듈 리팩토링
Hyeon9mak e85d4d8
refactor: App 컴포넌트 초기화 단계에서 Datasource 설정을 초기화 한 후 사용하도록 변경
Hyeon9mak 85c9ffa
refactor: Handler URL 메소드 변경, Conflict 핸들링 페이지 추가
Hyeon9mak a6111c0
chore: jacoco 테스트 설정 추가
Hyeon9mak f1b96c1
refactor: ComponentContainer 초기화시 필요한 DataSource 모킹
Hyeon9mak e0e3b96
refactor: JdbcTemplate에서 커스텀 예외를 사용하도록 변경
Hyeon9mak 86eb046
refactor: JdbcTemplate for문 기준 변수를 미리 추출해서 사용하도록 변경
Hyeon9mak 9cb151c
refactor: JdbcTemplate 에서 단일 오브젝트 조회 결과가 1개를 초과할 때 예외 추가
Hyeon9mak a7fa076
refactor: Optional을 사용할 때 isPresent 대신 ifPresent를 사용하도록 변경
Hyeon9mak 7defbd9
refactor: VO 불변 유지를 위한 원시값 포장
Hyeon9mak 92a2d11
refactor: 커스텀 예외에 메세지를 포함하도록 수정
Hyeon9mak ced9630
refactor: JsonView 에서 복수/단수 데이터 조회시 예외 상황 변경
Hyeon9mak 4d36e3e
refactor: ComponentContainer 중복 메서드 제거
Hyeon9mak 5d1022d
refactor: Autowired 어노테이션을 이용한 Component 초기화 변경
Hyeon9mak 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 hidden or 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 +1,10 @@ | ||
| # jwp-dashboard-jdbc | ||
|
|
||
| - [x] Connection 생성 자동으로 해주기 | ||
| - [x] PreparedStatement 자동으로 준비 및 실행 해주기 | ||
| - [x] ResultSet 만들어주기 | ||
| - [x] JdbcTemplate 사용자가 쿼리와 rowMapper 만 전달해서 매핑 자동화 | ||
| - [x] 예외처리 (커스텀 익셉션) | ||
| - [ ] 트랜잭션 관리 (...??) | ||
| - [x] Connection, Statement, ResultSet close (try-with-resource 사용) | ||
| - [x] Insert 아이디 발급 편의를 위해 SimpleJdbcInsert 만들어보기 |
This file contains hidden or 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
30 changes: 20 additions & 10 deletions
30
app/src/main/java/com/techcourse/AppWebApplicationInitializer.java
This file contains hidden or 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,32 +1,42 @@ | ||
| package com.techcourse; | ||
|
|
||
| import com.techcourse.config.DataSourceConfig; | ||
| import com.techcourse.support.jdbc.init.DatabasePopulatorUtils; | ||
| import jakarta.servlet.ServletContext; | ||
| import jakarta.servlet.ServletRegistration; | ||
| import nextstep.mvc.DispatcherServlet; | ||
| import nextstep.mvc.controller.asis.ControllerHandlerAdapter; | ||
| import nextstep.mvc.controller.tobe.AnnotationHandlerMapping; | ||
| import nextstep.mvc.controller.tobe.HandlerExecutionHandlerAdapter; | ||
| import nextstep.mvc.controller.AnnotationHandlerAdapter; | ||
| import nextstep.mvc.controller.AnnotationHandlerMapping; | ||
| import nextstep.mvc.exception.ComponentContainerException; | ||
| import nextstep.web.ComponentContainer; | ||
| import nextstep.web.WebApplicationInitializer; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class AppWebApplicationInitializer implements WebApplicationInitializer { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(AppWebApplicationInitializer.class); | ||
| private static final Logger LOG = LoggerFactory.getLogger(AppWebApplicationInitializer.class); | ||
| private static final String BASE_PACKAGE = "com.techcourse"; | ||
|
|
||
| @Override | ||
| public void onStartup(ServletContext servletContext) { | ||
| final DispatcherServlet dispatcherServlet = new DispatcherServlet(); | ||
| dispatcherServlet.addHandlerMapping(new ManualHandlerMapping()); | ||
| dispatcherServlet.addHandlerMapping(new AnnotationHandlerMapping("com.techcourse.controller")); | ||
| try { | ||
| LOG.info("Start Components Initializer"); | ||
| DatabasePopulatorUtils.execute(DataSourceConfig.getInstance()); | ||
| ComponentContainer.initializeComponents(DataSourceConfig.getInstance(), BASE_PACKAGE); | ||
| } catch (Exception e) { | ||
| LOG.error("Initialize Components Error: {}", e.getMessage()); | ||
| throw new ComponentContainerException(); | ||
| } | ||
|
|
||
| dispatcherServlet.addHandlerAdapter(new ControllerHandlerAdapter()); | ||
| dispatcherServlet.addHandlerAdapter(new HandlerExecutionHandlerAdapter()); | ||
| final DispatcherServlet dispatcherServlet = new DispatcherServlet(); | ||
| dispatcherServlet.addHandlerMapping(new AnnotationHandlerMapping(BASE_PACKAGE)); | ||
| dispatcherServlet.addHandlerAdapter(new AnnotationHandlerAdapter()); | ||
|
|
||
| final ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet); | ||
| dispatcher.setLoadOnStartup(1); | ||
| dispatcher.addMapping("/"); | ||
|
|
||
| log.info("Start AppWebApplication Initializer"); | ||
| LOG.info("Start AppWebApplication Initializer"); | ||
| } | ||
| } | ||
35 changes: 0 additions & 35 deletions
35
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/ForwardController.java
This file contains hidden or 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 jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import nextstep.mvc.view.JspView; | ||
| import nextstep.mvc.view.ModelAndView; | ||
| import nextstep.web.annotation.Controller; | ||
| import nextstep.web.annotation.RequestMapping; | ||
| import nextstep.web.support.RequestMethod; | ||
|
|
||
| @Controller | ||
| public class ForwardController { | ||
|
|
||
| @RequestMapping(value = "/", method= RequestMethod.GET) | ||
| public ModelAndView page(HttpServletRequest request, HttpServletResponse response) { | ||
| return new ModelAndView(new JspView("/index.jsp")); | ||
| } | ||
| } |
This file contains hidden or 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
16 changes: 0 additions & 16 deletions
16
app/src/main/java/com/techcourse/controller/LogoutController.java
This file was deleted.
Oops, something went wrong.
50 changes: 38 additions & 12 deletions
50
app/src/main/java/com/techcourse/controller/RegisterController.java
This file contains hidden or 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,31 +1,57 @@ | ||
| package com.techcourse.controller; | ||
|
|
||
| import com.techcourse.domain.User; | ||
| import com.techcourse.repository.InMemoryUserRepository; | ||
| import com.techcourse.controller.request.RegisterRequest; | ||
| import com.techcourse.exception.DuplicateAccountException; | ||
| import com.techcourse.service.RegisterService; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import nextstep.mvc.view.JspView; | ||
| import nextstep.mvc.view.ModelAndView; | ||
| import nextstep.web.annotation.Controller; | ||
| import nextstep.web.annotation.RequestMapping; | ||
| import nextstep.web.support.RequestMethod; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @Controller | ||
| public class RegisterController { | ||
|
|
||
| @RequestMapping(value = "/register", method = RequestMethod.POST) | ||
| public ModelAndView register(HttpServletRequest request, HttpServletResponse response) { | ||
| final User user = new User(2, | ||
| request.getParameter("account"), | ||
| request.getParameter("password"), | ||
| request.getParameter("email")); | ||
| InMemoryUserRepository.save(user); | ||
|
|
||
| return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
| private static final Logger LOG = LoggerFactory.getLogger(RegisterController.class); | ||
|
|
||
| private final RegisterService registerService; | ||
|
|
||
| public RegisterController(RegisterService registerService) { | ||
| this.registerService = registerService; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/register", method = RequestMethod.GET) | ||
| public ModelAndView view(HttpServletRequest request, HttpServletResponse response) { | ||
| public ModelAndView show(HttpServletRequest request, HttpServletResponse response) { | ||
| return new ModelAndView(new JspView("/register.jsp")); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/register", method = RequestMethod.POST) | ||
| public ModelAndView save(HttpServletRequest request, HttpServletResponse response) { | ||
| try { | ||
| RegisterRequest registerRequest = getRegisterRequest(request); | ||
| registerService.registerUser(registerRequest); | ||
|
|
||
| LOG.debug("Register Success!!"); | ||
|
|
||
| return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
| } catch (DuplicateAccountException e) { | ||
| LOG.debug("Register Failed..."); | ||
|
|
||
| return new ModelAndView(new JspView("redirect:/409.jsp")); | ||
| } | ||
| } | ||
|
|
||
| private RegisterRequest getRegisterRequest(HttpServletRequest request) { | ||
| String account = request.getParameter("account"); | ||
| String password = request.getParameter("password"); | ||
| String email = request.getParameter("email"); | ||
|
|
||
| LOG.debug("Register Request => account: {}, email: {}", account, email); | ||
|
|
||
| return new RegisterRequest(account, password, email); | ||
| } | ||
| } |
This file contains hidden or 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.
해당 클래스에 불필요한 import 문들이 있는데 제거하면 좋을 것 같아요 👀
Uh oh!
There was an error while loading. Please reload this page.
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.
앗... 꼼꼼한 리뷰 감사합니다 ㅠㅠ 요즘 120자 제한을 두고도 가독성을 위해 조금씩 넘겨서 코드를 짜다보니
코드 리포맷팅을 사용하면 코드 라인이 넘어가는게 싫어서 리포맷팅을 잘 안누르게 되네요.. 이상한 버릇이 생겨버렸어요..
넘길 땐 넘길 줄 알아야 하는데!!!!!