분류 전체보기
-
패스트캠퍼스 챌린지 16일차JAVA/Spring 2021. 11. 16. 23:42
1. 테스트를 잘 하는 방법 기존의 테스트 방식 테스트는 모두 사람이 하는 것이었고, 한번의 테스트는 상당한 노동력을 필요로 했음 SI에서는 전용 테스트 팀이 따로 있었고, 인수인계 전에 인수 테스트라는 것을 진행하여 기능적인 테스트를 꼼꼼히 진행했음 그 후에 불어온 테스트의 바람 하지만 로직이 대부분 쿼리에 있는 mybatis에서는 테스트하기가 까다로웠음 그 후 시간이 지나 JPA를 하게 되고, 쿼리가 아닌 자바 코드에 로직이 많이 담기게 됨 - 유지보수성의 극적인 향상(쿼리로는 다형성이나 디자인패턴 전략 등을 하기 어렵거나 불가능) - 자바 코드에 담긴 로직은 쿼리에 담긴 로직에 비해 테스트하기가 상대적으로 편리함 TDD & 실무 클래스의 구성이나 프로그램 구조가 잡히지 않은 상태에서는 테스트를 먼저..
-
패스트캠퍼스 챌린지 15일차JAVA/Spring 2021. 11. 15. 23:32
1. 예외처리를 활용한 서비스 로직 리팩토링 비효율적으로 코드를 짤 경우 불필요하고도 연이은 유효성 검사가 나타나는 모습을 볼 수 있다. 물론 때에 따라서 try catch를 통한 예외 처리는 필수적이지만 더욱 간단하고 효율적으로 해결할 수 있는 방안이 있는 상황에서 굳이 가독성이 떨어지는 코딩을 할 필요는 없을 것이다. 오늘은 비효율적인 코딩의 예시를 함께 살펴본 뒤, 효율적인 코드로 리팩토링하는 방법을 알아본다. 우선 Validation에 대한 결과로 뭔가를 return하려고 할 때 볼 수 있는 모습이다. dmaker.service.DMakerService public DeveloperVaildationDto validateCreateDeveloperRequest(CreateDeveloper.Reqe..
-
패스트캠퍼스 챌린지 14일차JAVA/Spring 2021. 11. 14. 23:59
1. 예외처리를 제대로 안했을 때의 문제점 지난 시간에 예외 처리를 했던 방법으로는 각각의 Controller에 Exception 처리를 해주어야하기 때문에 Controller가 많아질 경우 너무 많은 Exception 처리를 삽입해야 한다는 문제점이 있다. 이를 해소하기 위해 글로벌 단위로 예외 처리를 해주는 방법을 학습한다. 우선 각각의 Controller에 예외 처리에 대한 '조언'을 해주는 DMakerExceptionHandler를 만들어준다. dmaker.exception.DMakerExceptionHandler @Slf4j // @RestControllerAdvice 어노테이션을 달아줌으로써 전체 Controller에 Exception 처리를 // 적용할 수 있다. @RestController..
-
패스트캠퍼스 챌린지 13일차JAVA/Spring 2021. 11. 13. 23:50
1. 글로벌 예외 처리 (Global Exception) 예전에는 대개 예외들을 try catch로 잡아낸 후 이 예외에 대한 결과값을 짜서 return하는 방식(true와 false를 return하는 방식을 많이 사용)으로 예외 처리에 대한 코드를 작성했다. 이런 코드가 짜여질 경우 return되는 값에 대한 처리가 필요하기 때문에 코드가 훨씬 길어지게 된다. 지금까지는 코드 작성 시 예외 발생 없이 성공하는 경우들에 처리를 구체적으로 진행했다면 이번에는 실패에 대한 예외 처리를 구체적으로 정의하는 코드들을 학습한다. 우선 아래와 같이 Controller에 포함된 각각의 메서드에 try catch를 통해 Exception을 처리할 수도 있다. dmaker.controller.DMakerControlle..
-
패스트캠퍼스 챌린지 12일차JAVA/Spring 2021. 11. 12. 22:00
1. Developer Delete(삭제), 트랜잭션 실무 개발 오늘은 DB에 저장된 데이터를 삭제하는 방법과 실무에서의 트랜잭션 개발에 관련하여 학습한다. 이전에 했던 것과 동일하게 우선 Controller에 developer를 delete하는 메서드를 등록해준다. 삭제를 위한 프로토콜로는 'Delete'가 있다. dmaker.controller.DMakerController @DeleteMapping("/developer/{memberId}") public DeveloperDetailDto deleteDeveloper( @PathVariable String memberId ){ return dMakerService.deleteDeveloper(memberId); } 트랜잭션은 하나는 성공하고 다른 하..
-
패스트캠퍼스 챌린지 11일차JAVA/Spring 2021. 11. 11. 11:13
1. Developer Put(수정) 기능 개발 프로토콜은 약속과도 같은 것이다. 안 지켜도 입력된 동작이 수행될 때 문제가 발생하지는 않지만 프로토콜에 맞춰서 코드를 짜주어야 소통 + 협업 시에 훨씬 편리하게 업무를 진행할 수 있다. 데이터 수정 시에는 Put 메서드를 통해 요청을 전송한다. 먼저 DMakerController에 @PutMapping 어노테이션을 붙인 메서드를 하나 만들어준다. dmaker.controller.DMakerController @PutMapping("/developer/{memberId}") public DeveloperDetailDto editDeveloper ( @PathVariable String memberId, // 수정 요청 시 수정될 값을 받아야하기 때문에 넣어..
-
패스트캠퍼스 챌린지 10일차JAVA/Spring 2021. 11. 10. 21:13
1. Developer Get(조회) 기능 개발 지난번에 생성한 Developer를 조회하는 기능에 대해 알아본다. 먼저, 전체 개발자 목록을 조회하는 방법이다. DMakerController에 정의된 getAllDevelopers에서 return값을 DeveloperDto가 담긴 List로 설정해준다. dmaker.controller.DMakerController @GetMapping("/developers") // return하는 값을 DeveloperDto가 들어가는 List로 설정해준다. public List getAllDevelopers() { // GET /developers HTTP/1.1 log.info("GET /developers HTTP/1.1"); return dMakerServic..
-
패스트캠퍼스 챌린지 9일차JAVA/Spring 2021. 11. 9. 21:05
1. 간단한 HTTP 테스트 만들기 이제까지 구현했던 createDeveloper를 실제로 POST Request를 전송시켜 정상적으로 작동이 되는지 테스트해본다. 먼저, createDeveloper에서 developer 빌드 시 들어가야하는 값들을 request로부터 받아올 수 있도록 수정한다. dmaker.service.DMakerService @Transactional public CreateDeveloper.Response createDeveloper(CreateDeveloper.Request request) { validateCreateDeveloperRequest(request); // developer 빌드 시 필요한 값들을 request로부터 받아오도록 수정해준다. Developer dev..