Lv.6 DIPDIPDIPDIPDIPDIP Repository 의존성 역전!public class EntityFinder { public static T findByIdOrThrow(JpaRepository repository, Long id, ErrorCode errorCode) { return repository.findById(id) .orElseThrow(() -> new InvalidRequestException(errorCode)); }}public class EntityValidator { public static void isExistsById(JpaRepository repository, Long id, ErrorCode errorCode) { if(id ==.. 2025. 1. 4. Lv.6 리팩토링을 리팩토링하기 1. dto에서 검증로직을 수행하는 것은 뭔가 조금 애매?@Valuepublic class SigninRequestDto { String email; String password; public SigninRequestDto(String email, String password) { this.email = email; this.password = password; validate(); } private void validate() { if (email == null || !email.matches("^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,}$")) { throw new IllegalArgume.. 2025. 1. 2. Lv.4 N+1 문제 개선하기 우선 fetch join과 EntityGraph의 차이를 알고 갈 필요가 있다.https://stackoverflow.com/questions/21549480/spring-data-fetch-join-with-paging-is-not-working Spring-Data FETCH JOIN with Paging is not workingI am trying to use HQL fetching my entity along with sub-entities using JOIN FETCH, this is working fine if I want all the results but it is not the case if I want a Page My entity is @Entity @D...stackoverflow.. 2025. 1. 1. Lv.5 테스트코드 수정하기 1. PasswordEncoderTestmatches메서드에서 encodedPassword와 rawPassword의 위치가 바뀌어있다.코드 누가 짰냐 ㅡㅡ 하면서 수정해줬다boolean matches = passwordEncoder.matches(rawPassword, encodedPassword); 2. CommentServiceTestcomment쪽에서 반환된 result객체를 구체적으로 확인하지 않고 있다. result가 notnull인지만 확인하는 테스트코드를 짠 사람은 정말 혼내줘야한다// thenassertNotNull(result);assertEquals(request.getContents(), result.getContents());assertEquals(user.getId(), resu.. 2025. 1. 1. Lv.3-4 & Lv.6 전체적인 리팩토링 일기 문제1. response가 과도하게 많아 관리하기 힘드며, entity에서 response로 변환하는 과정을 response에 대한 생성자로 처리해 유지보수 하기 힘들다. 2. service계층에서 처리하고 있는 일이 너무 많다. token 생성, entity -> dto 로 변환작업, 비즈니스 로직, request 에대한 validate로직.. SRP를 완벽하게 위반하고 있다. 3. 예외처리가 미흡하다. 1. 과도하게 많은 response 압축과 변환과정 간소화public interface Mapper { S toDto(E entity);}@Componentpublic class UserMapper implements Mapper { @Override public UserRespons.. 2024. 12. 31. Lv.6 의존성에 주목하여 리팩토링 하기: DIP @Service@RequiredArgsConstructorpublic class AuthService { private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; private final JwtUtil jwtUtil; public SignupResponse signup(SignupRequest signupRequest) { if (userRepository.existsByEmail(signupRequest.getEmail())) { throw new InvalidRequestException("이미 존재하는 이메일입니다."); } .. 2024. 12. 30. 이전 1 다음