Skip to content

Commit

Permalink
fix: 그룹 외래키 참조 문제 QueryDslConfig로 수정 (#59) (KAN-110)
Browse files Browse the repository at this point in the history
  • Loading branch information
OziinG committed Nov 1, 2024
1 parent c7f5bac commit 62a0532
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.ioteatime.meonghanyangserver.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QueryDslConfig {

@PersistenceContext private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package org.ioteatime.meonghanyangserver.user.repository;

import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.ioteatime.meonghanyangserver.group.domain.QGroupUserEntity;
import org.ioteatime.meonghanyangserver.user.domain.QUserEntity;
import org.ioteatime.meonghanyangserver.user.domain.UserEntity;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@RequiredArgsConstructor
public class UserRepositoryImpl implements UserRepository {
private final JpaUserRepository jpaUserRepository;
private final JPAQueryFactory queryFactory;

@Override
public Optional<UserEntity> findById(Long userId) {
Expand All @@ -21,8 +26,15 @@ public Optional<UserEntity> findByEmail(String email) {
}

@Override
@Transactional
public void deleteById(Long userId) {
jpaUserRepository.deleteById(userId);

QGroupUserEntity groupUser = QGroupUserEntity.groupUserEntity;
QUserEntity user = QUserEntity.userEntity;

queryFactory.delete(groupUser).where(groupUser.user.id.eq(userId)).execute();

queryFactory.delete(user).where(user.id.eq(userId)).execute();
}

@Override
Expand Down

0 comments on commit 62a0532

Please sign in to comment.