Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IDLE-423] soft-delete가 적용된 즐겨찾기 entity에서, 즐겨찾기 해제 후 재설정 시 발생하는 에러 해결 #187

Merged
merged 1 commit into from
Oct 19, 2024

Conversation

wonjunYou
Copy link
Contributor

@wonjunYou wonjunYou commented Oct 19, 2024

1. 📄 Summary

  • soft-delete가 적용된 즐겨찾기 entity에서, 즐겨찾기 해제 후 다시 설정하는 경우 발생하는 에러를 해결합니다.
  • 에러 원인은 soft-delete한 entity row가 여전히 테이블에 남아 있는 상황에서 재설정하는 경우, 새로운 entity가 생성됩니다.
  • 따라서 한 공고에 대해 여러 개의 즐겨찾기가 생기게 되어 잘못된 쿼리 결과를 유발하였습니다.

해결책
-> 즐겨찾기 생성 로직에서, 기존에 생성된 즐겨찾기 객체가 테이블에 존재하는 경우 이를 재 활성화 하도록 로직을 분기하여 처리했습니다.

Summary by CodeRabbit

  • 새로운 기능
    • 즐겨찾기 직업 게시물 생성 로직 개선: 기존의 즐겨찾기 직업 게시물이 있는지 확인 후 활성화 또는 새로 생성하는 방식으로 변경되었습니다.

@wonjunYou wonjunYou added the 🛠️버그 버그 제보 및 해결 label Oct 19, 2024
@wonjunYou wonjunYou self-assigned this Oct 19, 2024
Copy link

coderabbitai bot commented Oct 19, 2024

Walkthrough

JobPostingFavoriteFacadeService 클래스의 createJobPostingFavorite 메소드가 수정되었습니다. 새로운 로직은 주어진 jobPostingIdcarerId에 대한 기존의 즐겨찾기 작업 게시물을 찾는 시도로 시작됩니다. 즐겨찾기가 발견되면 해당 객체의 active 메소드가 호출됩니다. 즐겨찾기가 없으면 원래의 create 메소드를 호출하여 새로운 즐겨찾기 작업 게시물을 생성합니다. deleteJobPostingFavorite 메소드는 변경되지 않았습니다.

Changes

파일 경로 변경 요약
idle-application/src/main/kotlin/com/swm/idle/application/jobposting/facade/JobPostingFavoriteFacadeService.kt createJobPostingFavorite 메소드의 로직 수정: 기존 즐겨찾기 검색 후 활성화 또는 새 즐겨찾기 생성. deleteJobPostingFavorite 메소드는 변경 없음.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant JobPostingFavoriteFacadeService
    participant JobPostingFavoriteService

    Client->>JobPostingFavoriteFacadeService: createJobPostingFavorite(jobPostingId, carerId)
    JobPostingFavoriteFacadeService->>JobPostingFavoriteService: findByJobPostingIdAndCarerId(jobPostingId, carerId)
    alt 즐겨찾기 발견
        JobPostingFavoriteService-->>JobPostingFavoriteFacadeService: ExistingFavorite
        JobPostingFavoriteFacadeService->>ExistingFavorite: active()
    else 즐겨찾기 없음
        JobPostingFavoriteFacadeService->>JobPostingFavoriteService: create(jobPostingId, carerId)
        JobPostingFavoriteService-->>JobPostingFavoriteFacadeService: NewFavorite
    end
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

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.

@wonjunYou wonjunYou changed the title [IDLE-423] soft-delete가 적용된 즐겨찾기 entity에서, 즐겨찾기 해제 후 다시 설정하는 경우 발생 에러 해결 [IDLE-423] soft-delete가 적용된 즐겨찾기 entity에서, 즐겨찾기 해제 후 재설정 시 발생하는 에러 해결 Oct 19, 2024
Copy link

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: 0

🧹 Outside diff range and nitpick comments (1)
idle-application/src/main/kotlin/com/swm/idle/application/jobposting/facade/JobPostingFavoriteFacadeService.kt (1)

22-27: 변경 사항이 PR 목표를 잘 달성했습니다.

이 변경은 소프트 삭제된 즐겨찾기 엔티티를 다시 추가할 때 발생하는 오류를 해결하는 데 효과적입니다. 기존 즐겨찾기를 확인하고 필요한 경우 재활성화하는 로직이 잘 구현되었습니다.

다음과 같은 개선 사항을 고려해 보시기 바랍니다:

  1. 예외 처리: findByJobPostingIdAndCarerId 메서드가 실패할 경우에 대한 예외 처리를 추가하는 것이 좋습니다.
  2. 로깅: 즐겨찾기가 재활성화되거나 새로 생성될 때 로그를 추가하면 디버깅과 모니터링에 도움이 될 것입니다.
  3. 트랜잭션 처리: 데이터베이스 작업이 원자적으로 수행되도록 트랜잭션 처리를 고려해 보세요.

아래는 이러한 개선 사항을 반영한 코드 예시입니다:

@Transactional
fun createJobPostingFavorite(
    jobPostingId: UUID,
    carerId: UUID,
    jobPostingType: JobPostingType,
) {
    try {
        val existingFavorite = jobPostingFavoriteService.findByJobPostingIdAndCarerId(
            jobPostingId = jobPostingId,
            carerId = carerId,
        )
        
        if (existingFavorite != null) {
            existingFavorite.active()
            logger.info("Reactivated existing favorite for jobPosting: $jobPostingId, carer: $carerId")
        } else {
            jobPostingFavoriteService.create(
                jobPostingId = jobPostingId,
                carerId = carerId,
                jobPostingType = jobPostingType,
            )
            logger.info("Created new favorite for jobPosting: $jobPostingId, carer: $carerId")
        }
    } catch (e: Exception) {
        logger.error("Error creating/reactivating favorite for jobPosting: $jobPostingId, carer: $carerId", e)
        throw e
    }
}

이 변경 사항에 대해 어떻게 생각하시나요?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 83d0c69 and eba79f1.

📒 Files selected for processing (1)
  • idle-application/src/main/kotlin/com/swm/idle/application/jobposting/facade/JobPostingFavoriteFacadeService.kt (1 hunks)
🧰 Additional context used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️버그 버그 제보 및 해결
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant