Skip to content

Conversation

@kyoooooong
Copy link
Contributor

@kyoooooong kyoooooong commented Feb 12, 2025

#️⃣ 요약 설명

📝 작업 내용

  1. 예외 처리 부분에서 JOBID가 아니라 JOB을 기준으로 처리하도록 하였습니다.
  2. 사용자의 직무ID와 같은 스크랩한 컨텐츠를 가져올 때 filter() 을 사용해 처리하도록 수정하였습니다.

코드의 흐름이나 중요한 부분을 작성해주세요.

// 핵심 코드를 붙여넣기 해주세요

코드에 대한 간단한 설명 부탁드립니다.

동작 확인

기능을 실행했을 때 정상 동작하는지 여부를 확인하고 사진을 올려주세요

ex) 테스트 코드 작성후 성공 사진
ex) swagger 사진

💬 리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

Summary by CodeRabbit

  • 새로운 기능
    • 스크랩된 콘텐츠 응답에 직무 관련 식별 정보가 추가되어, 사용자에게 더 풍부한 정보를 제공합니다.
  • 리팩토링
    • 콘텐츠 스크랩 필터링 및 페이징 로직을 개선하여, 결과의 정확성과 일관성이 향상되었습니다.

@kyoooooong kyoooooong added the fix 버그/에러 수정 label Feb 12, 2025
@kyoooooong kyoooooong self-assigned this Feb 12, 2025
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

이번 PR에서는 ContentScrapResponseDTOLong jobId 필드를 추가하여 데이터 구조를 확장하고, 멤버와 jobId 기반의 조회 메서드를 ContentScrapRepository에서 제거하였습니다. 또한, ContentScrapServicegetScrapContents 메서드에서는 멤버의 job 객체를 확인한 후 전체 스크랩 데이터를 조회하여 jobId 기준으로 필터링하는 로직으로 변경되었으며, 페이지네이션 관련 반환 정보도 업데이트되었습니다.

Changes

파일 변경 요약
src/main/java/UMC/.../ContentScrapResponseDTO.java ContentScrapResponseDTO에 새로운 필드 Long jobId 추가
src/main/java/UMC/.../ContentScrapRepository.java findByMemberAndJobId 메서드 제거 (멤버와 jobId 기반 조회 기능 삭제)
src/main/java/UMC/.../ContentScrapService.java getScrapContents 메서드 로직 수정: 멤버의 job 객체 체크 및 전체 스크랩 조회 후 jobId 기준 필터링, 페이지네이션 처리 변경

Sequence Diagram(s)

sequenceDiagram
    participant M as Member
    participant S as ContentScrapService
    participant R as ContentScrapRepository

    M->>S: getScrapContents(member, page, size)
    S->>S: member.getJob() 여부 확인
    alt job 정보 없음
        S->>M: 기본/빈 응답 반환
    else job 정보 존재
        S->>R: 멤버의 전체 스크랩 조회 요청
        R-->>S: 모든 스크랩 데이터 반환
        S->>S: jobId 기준으로 스크랩 필터링
        S->>M: 필터링된 스크랩과 페이지네이션 정보 포함 응답 반환
    end
Loading

Possibly related PRs

Suggested reviewers

  • jpark0506
  • KSLEE19
  • jjeongdong
  • veronees

Poem

안녕하세요, 토끼가 전하는 기쁜 소식!
코드 속 작은 변화들이 춤추며 새싹을 피우네.
jobId가 추가되어 새로운 길을 열었고,
잊혀진 메서드는 추억 속으로 사라졌네.
뛰노는 발바닥처럼, 코드도 즐겁게 달려요! 🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kyoooooong kyoooooong changed the title [CMAT-63] 스크랩한 컨텐츠 조회 API 수정 [CMAT-63] fix: 스크랩한 컨텐츠 조회 API 수정 Feb 12, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e9f1c7 and da692ba.

📒 Files selected for processing (3)
  • src/main/java/UMC/career_mate/domain/contentScrap/dto/response/ContentScrapResponseDTO.java (1 hunks)
  • src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java (0 hunks)
  • src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java (1 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java
🔇 Additional comments (4)
src/main/java/UMC/career_mate/domain/contentScrap/dto/response/ContentScrapResponseDTO.java (2)

11-11: 적절한 필드 추가입니다!

jobId 필드를 추가함으로써 다음과 같은 이점이 있습니다:

  • Job 기반의 컨텐츠 필터링이 가능해집니다
  • ID 필드 타입(Long)의 일관성을 유지합니다
  • 스크랩된 컨텐츠 조회 API의 요구사항을 잘 반영합니다

5-13: 전반적인 구조가 잘 설계되어 있습니다!

  • Record를 사용하여 불변성을 보장합니다
  • Builder 패턴을 통해 객체 생성의 유연성을 제공합니다
  • 필드들이 논리적으로 잘 정렬되어 있습니다
src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java (2)

56-60: Job 객체를 직접 검증하도록 개선되었습니다!

jobId 대신 job 객체를 직접 검증하도록 변경한 것은 좋은 개선입니다. 이는 더 객체지향적이며 도메인 모델을 더 잘 반영합니다.


71-77: 페이지네이션 정확성 검증이 필요합니다.

필터링 이후 실제 반환되는 데이터 크기가 요청된 페이지 크기와 다를 수 있습니다. 또한 hasNext 값이 필터링 전의 전체 데이터를 기준으로 계산되어 부정확할 수 있습니다.

페이지네이션 로직이 의도한 대로 동작하는지 확인해주세요:

  1. 필터링 후 빈 페이지가 반환되는 경우
  2. 마지막 페이지의 hasNext 값이 정확한지
  3. 실제 클라이언트가 요청한 size만큼의 데이터가 반환되는지

Comment on lines +64 to 69
Page<ContentScrap> allScraps = contentScrapRepository.findByMember(member, pageRequest);

List<ContentScrapResponseDTO> contentList = scraps.stream()
List<ContentScrapResponseDTO> contentList = allScraps.stream()
.filter(scrap -> scrap.getContent().getJob().getId().equals(jobId))
.map(ContentScrapConverter::toContentScrapResponseDTO)
.toList();
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

성능 최적화가 필요할 수 있습니다.

현재 구현은 다음과 같은 잠재적인 성능 문제가 있습니다:

  1. 모든 스크랩을 메모리에 로드한 후 필터링하므로 데이터가 많은 경우 메모리 사용량이 증가할 수 있습니다.
  2. scrap.getContent().getJob() 호출로 인한 N+1 쿼리 문제가 발생할 수 있습니다.

다음과 같은 개선을 고려해보세요:

@Query("SELECT cs FROM ContentScrap cs " +
       "JOIN FETCH cs.content c " +
       "JOIN FETCH c.job j " +
       "WHERE cs.member = :member AND j.id = :jobId")
Page<ContentScrap> findByMemberAndJobIdWithFetch(
    @Param("member") Member member,
    @Param("jobId") Long jobId,
    Pageable pageable
);

@kyoooooong kyoooooong closed this Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 버그/에러 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants