Skip to content

Commit d3e9f8a

Browse files
committed
♻️ refactor: QueryDsl 적용
1 parent 1da524c commit d3e9f8a

File tree

6 files changed

+72
-10
lines changed

6 files changed

+72
-10
lines changed

http/test.http

+3
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ Content-Type: application/json
7474

7575
### 보고서 조회
7676
GET http://localhost:8080/api/v1/reports/0
77+
78+
### 공고 검색
79+
GET http://localhost:8080/api/v1/announcements?search=무신사

src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public ApiResponse<ProposeCreateResponse> createPropose(
4444
return ApiResponse.onSuccess(proposeService.createPropose(authOrganization, request));
4545
}
4646

47+
// TODO QueryDsl 변경 테스트 후 수정 필요
4748
@GetMapping("/me")
4849
public ApiResponse<List<ProposeSummaryGetResponse>> getMyProposes(
4950
@AuthOrganization Organization authOrganization,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.sponus.sponusbe.domain.propose.repository;
2+
3+
import java.util.List;
4+
5+
import com.sponus.sponusbe.domain.propose.entity.Propose;
6+
7+
public interface ProposeCustomRepository {
8+
9+
List<Propose> findSentPropose(Long id);
10+
11+
List<Propose> findReceivedProposeWithAnnouncementId(Long organizationId, Long announcementId);
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.sponus.sponusbe.domain.propose.repository;
2+
3+
import java.util.List;
4+
5+
import org.springframework.stereotype.Repository;
6+
7+
import com.querydsl.jpa.impl.JPAQueryFactory;
8+
import com.sponus.sponusbe.domain.propose.entity.Propose;
9+
import com.sponus.sponusbe.domain.propose.entity.QPropose;
10+
11+
import jakarta.persistence.EntityManager;
12+
import lombok.RequiredArgsConstructor;
13+
14+
@RequiredArgsConstructor
15+
@Repository
16+
public class ProposeCustomRepositoryImpl implements ProposeCustomRepository {
17+
18+
private final EntityManager entityManager;
19+
20+
@Override
21+
22+
public List<Propose> findSentPropose(Long id) {
23+
QPropose p = QPropose.propose;
24+
25+
JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
26+
27+
return queryFactory.selectFrom(p)
28+
.where(p.proposingOrganization.id.eq(id))
29+
.leftJoin(p.proposingOrganization).fetchJoin()
30+
.fetch();
31+
}
32+
33+
@Override
34+
public List<Propose> findReceivedProposeWithAnnouncementId(Long organizationId, Long announcementId) {
35+
QPropose p = QPropose.propose;
36+
37+
JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
38+
39+
return queryFactory.selectFrom(p)
40+
.where(p.proposedOrganization.id.eq(organizationId)
41+
.and(p.announcement.id.eq(announcementId)))
42+
.leftJoin(p.proposedOrganization).fetchJoin()
43+
.leftJoin(p.announcement)
44+
.fetch();
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package com.sponus.sponusbe.domain.propose.repository;
22

3-
import java.util.List;
4-
53
import org.springframework.data.jpa.repository.JpaRepository;
6-
import org.springframework.data.jpa.repository.Query;
74

85
import com.sponus.sponusbe.domain.propose.entity.Propose;
96

107
public interface ProposeRepository extends JpaRepository<Propose, Long> {
11-
@Query("SELECT p FROM Propose p WHERE p.proposingOrganization.id = :id")
12-
List<Propose> findSentPropose(Long id);
13-
14-
@Query("SELECT p FROM Propose p WHERE p.proposedOrganization.id = :organizationId AND p.announcement.id = :announcementId")
15-
List<Propose> findReceivedProposeWithAnnouncementId(Long organizationId, Long announcementId);
8+
// @Query("SELECT p FROM Propose p WHERE p.proposingOrganization.id = :id")
9+
// List<Propose> findSentPropose(Long id);
10+
//
11+
// @Query("SELECT p FROM Propose p WHERE p.proposedOrganization.id = :organizationId AND p.announcement.id = :announcementId")
12+
// List<Propose> findReceivedProposeWithAnnouncementId(Long organizationId, Long announcementId);
1613

1714
}

src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeQueryService.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.sponus.sponusbe.domain.propose.entity.Propose;
1313
import com.sponus.sponusbe.domain.propose.exception.ProposeErrorCode;
1414
import com.sponus.sponusbe.domain.propose.exception.ProposeException;
15+
import com.sponus.sponusbe.domain.propose.repository.ProposeCustomRepository;
1516
import com.sponus.sponusbe.domain.propose.repository.ProposeRepository;
1617

1718
import lombok.RequiredArgsConstructor;
@@ -23,20 +24,22 @@ public class ProposeQueryService {
2324

2425
private final ProposeRepository proposeRepository;
2526

27+
private final ProposeCustomRepository proposeCustomRepository;
28+
2629
public List<ProposeSummaryGetResponse> getProposes(Organization organization, ProposeGetCondition condition) {
2730
// TODO : 추후에 QueryDSL 이용
2831
List<ProposeSummaryGetResponse> response;
2932
if (condition.isSentPropose()) {
3033
// 내가 보낸 제안은 그냥 반환
31-
response = proposeRepository.findSentPropose(organization.getId()).stream()
34+
response = proposeCustomRepository.findSentPropose(organization.getId()).stream()
3235
.map(ProposeSummaryGetResponse::from)
3336
.toList();
3437
} else {
3538
// 내가 받은 제안은 공고 id 별로 보여줘야하고, 공고 id가 없으면 안됨
3639
if (condition.announcementId() == null) {
3740
throw new ProposeException(ProposeErrorCode.ANNOUNCEMENT_ID_IS_REQUIRED);
3841
}
39-
response = proposeRepository.findReceivedProposeWithAnnouncementId(
42+
response = proposeCustomRepository.findReceivedProposeWithAnnouncementId(
4043
organization.getId(),
4144
condition.announcementId())
4245
.stream()

0 commit comments

Comments
 (0)