Skip to content

Conversation

@dnzp75
Copy link
Collaborator

@dnzp75 dnzp75 commented Mar 26, 2025

미리 말씀 드릴 사항

  • 이전 pr 브랜치를 merge해서 Files changed 양이 좀 많아진 것 같습니다. 감안해서 봐주시면 좋을 것 같습니다.
  • 좋아요 추가 기능에 필요한 Diary, User Domain 일부도 추가했습니다.

작업 사항

  • 좋아요 추가 API 구현
  • 좋아요 추가 API 단위 테스트 작성
  • 테스트를 하기 위한 Domain 별 Fixture 추가

(03.27) 추가 작업 사항

  • 좋아요 취소 API 구현
  • 좋아요 취소 API 단위 테스트 작성

@dnzp75 dnzp75 added the enhancement New feature or request label Mar 26, 2025
@dnzp75 dnzp75 requested review from a user, InJunKangW, TTaiJin and sapiens2000 March 26, 2025 08:48
@dnzp75 dnzp75 self-assigned this Mar 26, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private SocialType socialType;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socialType은 왜 넣으신걸까요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERDcloud 보면서 추가 했었습니다.
User 테이블에 Provider 컬럼있는 것 있는거 보고 이것을 socialType으로 구분할 것으로 예상해서 작성했습니다.

제가 잘못 알고 있는게 있을까요?

@cr-gpt
Copy link

cr-gpt bot commented Mar 26, 2025

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@dnzp75 dnzp75 changed the title 좋아요 추가 기능 구현 좋아요 추가/취소 기능 구현 Mar 26, 2025
@github-actions
Copy link

Claude의 전체 변경사항 및 관련 파일에 대한 리뷰:

개선된 사항:

  • 예외 처리와 에러 코드 체계가 잘 구조화되어 있습니다.
  • 좋아요 기능의 단위 테스트가 잘 작성되어 있습니다.
  • BaseEntity를 통한 공통 필드 관리가 잘 되어 있습니다.

주요 이슈:

  1. 트랜잭션 관리 개선 필요

    • 제안: LikeService의 메서드에 @transactional 애노테이션을 추가하여 트랜잭션 관리를 개선하세요.
    @Service
    @RequiredArgsConstructor
    public class LikeService {
        @Transactional
        public LikeAddResponseDto addLike(Long userId, LikeAddRequestDto requestDto) {
            // 기존 코드
        }
    
        @Transactional
        public LikeCancelResponseDto cancelLike(Long userId, Long diaryId) {
            // 기존 코드
        }
    }
  2. 예외 처리 일관성 개선

    • 제안: NotFoundLikeException을 추가하고, cancelLike 메서드에서 사용하세요.
    public class NotFoundLikeException extends LikeException {
        public NotFoundLikeException() {
            super(LikeErrorCode.NOT_FOUND_LIKE);
        }
    }
    
    @Transactional
    public LikeCancelResponseDto cancelLike(Long userId, Long diaryId) {
        Like like = likeRepository.findByUserIdAndDiaryId(userId, diaryId)
            .orElseThrow(NotFoundLikeException::new);
        likeRepository.delete(like);
        Long likeCount = diaryService.decreaseLikeCount(diaryId);
        return LikeCancelResponseDto.of(false, likeCount);
    }
  3. API 응답 일관성 개선

    • 제안: API 응답에 공통 포맷을 적용하세요.
    public class ApiResponse<T> {
        private final boolean success;
        private final T data;
        private final String message;
    
        // 생성자, 정적 팩토리 메서드 등
    }
    
    @PostMapping
    public ResponseEntity<ApiResponse<LikeAddResponseDto>> addLike(@Valid @RequestBody LikeAddRequestDto requestDto) {
        LikeAddResponseDto response = likeService.addLike(userId, requestDto);
        return ResponseEntity.ok(ApiResponse.success(response));
    }

관련 파일에 대한 영향 분석:

  • LikeService의 변경은 LikeController와 관련 테스트 코드에 영향을 줄 수 있습니다. 컨트롤러와 테스트 코드를 업데이트해야 할 수 있습니다.
  • 새로운 예외 클래스 추가는 GlobalExceptionHandler에 영향을 줄 수 있습니다. 새 예외에 대한 처리 로직을 추가해야 합니다.
  • API 응답 포맷 변경은 프론트엔드나 API를 사용하는 다른 서비스에 영향을 줄 수 있습니다. 변경 사항을 문서화하고 관련 팀에 공유해야 합니다.

전반적인 의견:
코드 구조와 예외 처리가 잘 되어 있지만, 트랜잭션 관리와 API 응답 일관성에 개선의 여지가 있습니다. 제안된 변경사항을 적용하면 코드의 안정성과 일관성이 향상될 것입니다.

@sonarqubecloud
Copy link

@github-actions
Copy link

Claude의 전체 변경사항 및 관련 파일에 대한 리뷰:

개선된 사항:

  • BaseEntity 클래스를 통한 공통 필드 관리
  • 예외 처리를 위한 커스텀 예외 클래스 구현
  • 단위 테스트를 위한 Fixture 클래스 구현

주요 이슈:

  1. 트랜잭션 관리 개선

    • 제안: LikeService의 메서드에 @transactional 어노테이션을 추가하여 트랜잭션 관리를 개선합니다.
    @Service
    @RequiredArgsConstructor
    public class LikeService {
        @Transactional
        public LikeAddResponseDto addLike(Long userId, LikeAddRequestDto requestDto) {
            // 메서드 내용
        }
    
        @Transactional
        public LikeCancelResponseDto cancelLike(Long userId, Long diaryId) {
            // 메서드 내용
        }
    }
  2. 비즈니스 로직 개선

    • 제안: DiaryService에서 좋아요 수를 증가/감소시키는 로직을 Diary 엔티티로 이동하여 객체지향적 설계를 강화합니다.
    @Entity
    public class Diary extends BaseEntity {
        // 기존 필드들
    
        public void incrementLikeCount() {
            this.likeCount++;
        }
    
        public void decrementLikeCount() {
            this.likeCount = Math.max(0, this.likeCount - 1);
        }
    }
  3. 테스트 코드 개선

    • 제안: LikeServiceTest에서 더 다양한 시나리오를 테스트하고, 경계값 테스트를 추가합니다.
    @Test
    @DisplayName("좋아요 취소 - 좋아요 수가 0일 때")
    void cancelLike_WhenLikeCountIsZero() {
        // given
        Long userId = 1L;
        Long diaryId = 123L;
        given(likeRepository.findByUserIdAndDiaryId(userId, diaryId)).willReturn(Optional.of(like));
        given(diaryService.decreaseLikeCount(diaryId)).willReturn(0L);
    
        // when
        LikeCancelResponseDto response = likeService.cancelLike(userId, diaryId);
    
        // then
        assertThat(response.likeCount()).isEqualTo(0);
        assertThat(response.liked()).isFalse();
    }

관련 파일에 대한 영향 분석:

  • LikeService의 변경은 LikeController와 관련 테스트 코드에 영향을 줄 수 있습니다. 트랜잭션 관리 개선으로 데이터 일관성이 향상될 것입니다.
  • Diary 엔티티의 변경은 DiaryService와 관련 테스트 코드에 영향을 줄 수 있습니다. 객체지향적 설계가 강화되어 코드 유지보수성이 향상될 것입니다.
  • 테스트 코드 개선은 전반적인 코드 품질과 신뢰성 향상에 기여할 것입니다.

전반적인 의견:
코드 구조와 예외 처리, 테스트 코드 작성 등 전반적으로 잘 구현되어 있습니다. 제안된 개선사항을 적용하면 코드의 품질과 유지보수성이 더욱 향상될 것입니다.

@dnzp75 dnzp75 merged commit adb0836 into develop Mar 27, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants