전체 글

전체 글

    [TIL - 20240103] Spring Data JPA @Modifying 문제

    💻문제점 public interface CommentRepository extends JpaRepository { @Modifying @Query("UPDATE Comment c SET c.member = NULL WHERE c.member.id = :memberId") void setMemberToNull(Long memberId); } @Modifying 애노테이션은 @Query 애노테이션으로 작성된 INSERT, UPDATE, DELETE와 같은 쿼리에 사용됩니다. (SELECT제외) @Test @DisplayName("회원이 작성한 댓글의 Member를 null로 변경") void setMemberToNullTest() { // given Member otherMember = MemberFixtu..

    [TIL - 20231228] Interface의 default 메서드를 활용한 Enum 확장

    💻문제점 Enum 값에 숫자 값을 넣어주기 위해 다음과 같이 setCalorie()를 선언했다. 문제는, OVER_INTAKE 밖에 사용되지 않는 메서드이기 때문에, 그 외에는 Enum의 message만 반환하는 점이 어색함이 많았다. NotificationMessage.java @Getter public enum NotificationMessage { // sse SSE_CONNECTION("SSE 연결이 완료되었습니다."), // intake OVER_INTAKE("오늘의 칼로리 섭취량이 %dKcal 초과되었습니다."); private final String message; NotificationMessage(String message) { this.message = message; } public ..

    [TIL - 20231226] jacoco 패키지, 클래스 Report에서 제외

    💻문제점 jacoco 코드 커버리지 적용했다. 이제 jacoco Report에 추가하지 않을 패키지나 클래스를 제외해보자. 🔍해결 build.gradle jacocoTestReport { reports { html.required = true xml.required = false csv.required = false } excludedClassFilesForReport(classDirectories) dependsOn test finalizedBy 'jacocoTestCoverageVerification' } jacocoTestCoverageVerification { excludedClassFilesForReport(classDirectories) violationRules { rule { element..

    [TIL - 20231222] AuthenticationEntryPoint를 사용한 JWT 예외 핸들링

    💻문제점 JwtAuthenticationFilter.java @Override protected void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String extractToken = request.getHeader(JwtUtils.AUTH_TOKEN_HEADER); jwtUtils.extractBearerToken(extractToken) .ifPresent( jwt -> { jwtUtils.validateToken(jwt); if (SecurityContextHolder.getContext()..

    [TIL - 20231222] searchWeeklyIntakeCalories 로직 개선

    💻문제점1 NutrientsQueryService.java public List searchWeeklyIntakeCalories( Long memberId, LocalDate startDate, LocalDate endDate) { memberQueryService.search(memberId); List caloriesOfMealTypes = new ArrayList(); LocalDate currentDate = startDate; while (!currentDate.isAfter(endDate)) { LocalDateTime startDateTime = currentDate.atStartOfDay(); LocalDateTime endDateTime = currentDate.atTime(LocalTi..

    [TIL-20231222] Illegal pop() with non-matching JdbcValuesSourceProcessingState

    💻문제점1 MemberContorller.java @GetMapping("/nutrients/week") public ResponseEntity getWeeklyIntakeCalorie( @AuthenticationPrincipal UserDetailsImpl userDetails, @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate, @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) { List mealCalories = nutrientsQueryService.searchWeeklyIntakeCalor..

    [TIL-20231220] 리플렉션을 사용한 private 필드 접근 및 값 설정

    💻문제점 테스트 코드를 작성하던 중 문제가 발생했다. @Test @DisplayName("금일 섭취량 조회") void searchDailyIntakeNutrientsTest() { // given Long memberId = member.getId(); Meal meal = meals.get(0); mealLogs = List.of( MealLogFixture.BREAKFAST.get(meals, member), MealLogFixture.LUNCH.get(meals, member)); int expectedSize = meals.size() * mealLogs.size(); LocalDate date = mealLogs.get(0).getModifiedAt().toLocalDate(); LocalDa..