Skip to content

Commit

Permalink
refactor : 첨부 URL 전체 조회 QueryDSL 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
oznchex committed Aug 17, 2024
1 parent dbf0a5a commit d7042ed
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -10,6 +11,7 @@
@Configuration
public class QueryDSLConfig {

@PersistenceContext
private final EntityManager entityManager;

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

public interface AttachUrlRepository extends JpaRepository<AttachUrl, Long> {
public interface AttachUrlRepository extends JpaRepository<AttachUrl, Long>, AttachUrlRepositoryCustom{

boolean existsByProfileId(final Long profileId);

Optional<AttachUrl> findByProfileId(@Param("profileId") final Long profileId);

@Query("SELECT attachUrl FROM AttachUrl attachUrl WHERE attachUrl.profile.id = :profileId")
List<AttachUrl> findAllByProfileId(@Param("profileId") final Long profileId);

@Modifying
@Transactional
@Query("DELETE FROM AttachUrl attachUrl WHERE attachUrl.profile.id = :profileId")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package liaison.linkit.profile.domain.repository.attach;

import liaison.linkit.profile.domain.attach.AttachUrl;

import java.util.List;

public interface AttachUrlRepositoryCustom {
List<AttachUrl> findAllByProfileId(final Long profileId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package liaison.linkit.profile.domain.repository.attach;

import com.querydsl.jpa.impl.JPAQueryFactory;
import liaison.linkit.profile.domain.attach.AttachUrl;
import liaison.linkit.profile.domain.attach.QAttachUrl;
import lombok.RequiredArgsConstructor;

import java.util.List;

@RequiredArgsConstructor
public class AttachUrlRepositoryCustomImpl implements AttachUrlRepositoryCustom {
private final JPAQueryFactory jpaQueryFactory;

@Override
public List<AttachUrl> findAllByProfileId(final Long profileId){
QAttachUrl attachUrl = QAttachUrl.attachUrl;
return jpaQueryFactory.selectFrom(attachUrl)
.where(attachUrl.profile.id.eq(profileId))
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
@Transactional
@Slf4j
public class AttachService {

private final ProfileRepository profileRepository;
private final AttachUrlRepository attachUrlRepository;
// private final AttachFileRepository attachFileRepository;
Expand All @@ -54,7 +53,6 @@ private List<AttachUrl> getAttachUrls(final Long profileId) {
} catch (Exception e) {
throw new BadRequestException(NOT_FOUND_ATTACH_URLS_BY_PROFILE_ID);
}

}

// 해당 회원이 1개라도 Attach URL 보유하고 있는지
Expand Down

0 comments on commit d7042ed

Please sign in to comment.