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

fix - 챌린지 생성 시 중복된 일별 챌린지를 생성하지 않도록 유효성 검사 로직 추가 #185

Merged
merged 2 commits into from
Jul 21, 2024

Conversation

kseysh
Copy link
Member

@kseysh kseysh commented Jul 19, 2024

Related issue 🚀

Work Description 💚

  • 챌린지 생성 시에 중복된 일별 챌린지를 생성하지 않도록 유효성 검사 로직을 추가하였습니다.

PR 참고 사항

  • Querydsl을 활용하여 userId와 challengeDate가 같은 일별 챌린지가 하나씩 있는지 확인하는 것이 아닌, 아래의 쿼리를 이용해 한 번에 일별 챌린지가 존재하는지 확인하도록 하였습니다.
  • selectOne과 fetchFirst를 활용하여 exist의 쿼리 성능을 최대한 끌어내고자 하였습니다.
  • 참고 블로그입니다.
select
        1 
    from
        daily_challenge dc1_0 
    where
        dc1_0.user_id=? 
        and dc1_0.challenge_date in (?, ?, ?, ?, ?, ?, ?) 
    limit
        ?

@kseysh kseysh added 🐞 BugFix 에러 수정, 버그 수정 🔧 Modify 코드 수정 (기능의 변화가 있을 때) labels Jul 19, 2024
@kseysh kseysh requested a review from jumining July 19, 2024 10:24
@kseysh kseysh self-assigned this Jul 19, 2024
Copy link
Collaborator

@jumining jumining left a comment

Choose a reason for hiding this comment

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

조건이 여러개일 때 쿼리 사용하는 방면이 훨씬 좋아보이네요~ JPAQueryFactory를 사용해서 jpa로 쿼리 사용하는 방법은 처음 구경해봤습니다


@Repository
@RequiredArgsConstructor
public class DailyChallengeRepositoryImpl implements DailyChallengeRepository {

private final DailyChallengeJpaRepository dailyChallengeJpaRepository;
private final JPAQueryFactory queryFactory;
Copy link
Collaborator

Choose a reason for hiding this comment

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

jpa는 JPAQueryFactory 이런 것도 지원해주는군요

@kseysh kseysh merged commit 8a34f26 into develop Jul 21, 2024
1 check passed
@jumining jumining deleted the fix/#162-duplicate-daily-challenge branch November 19, 2024 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 BugFix 에러 수정, 버그 수정 🔧 Modify 코드 수정 (기능의 변화가 있을 때)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix - dailyChallenege 중복 생성 오류
2 participants