1414import com .querydsl .core .types .dsl .BooleanExpression ;
1515import com .querydsl .core .types .dsl .Expressions ;
1616import com .querydsl .jpa .impl .JPAQueryFactory ;
17- import java .time .LocalDate ;
1817import java .util .List ;
1918import java .util .Optional ;
2019import java .util .Set ;
2120import lombok .RequiredArgsConstructor ;
2221import org .programmers .signalbuddyfinal .domain .feedback .dto .FeedbackResponse ;
22+ import org .programmers .signalbuddyfinal .domain .feedback .dto .FeedbackSearchCondition ;
2323import org .programmers .signalbuddyfinal .domain .feedback .entity .Feedback ;
2424import org .programmers .signalbuddyfinal .domain .feedback .entity .enums .AnswerStatus ;
2525import org .programmers .signalbuddyfinal .domain .feedback .entity .enums .FeedbackCategory ;
@@ -58,26 +58,20 @@ public class CustomFeedbackRepositoryImpl implements CustomFeedbackRepository {
5858
5959 @ Override
6060 public Page <FeedbackResponse > findAllByActiveMembers (
61- Pageable pageable ,
62- SearchTarget target ,
63- AnswerStatus answerStatus , Set <FeedbackCategory > categories ,
64- Long crossroadId , String keyword
61+ Pageable pageable , Long crossroadId ,
62+ FeedbackSearchCondition condition
6563 ) {
66- BooleanExpression searchCondition = searchCondition (target , keyword );
64+ BooleanExpression searchCondition = searchCondition (condition );
6765 BooleanExpression activityMember = member .memberStatus .eq (MemberStatus .ACTIVITY );
68- BooleanExpression answerStatusCondition = answerStatusCondition (answerStatus );
69- BooleanExpression categoriesCondition = categoriesCondition (categories );
7066 BooleanExpression crossroadIdCondition = crossroadIdCondition (crossroadId );
7167
7268 List <FeedbackResponse > results = jpaQueryFactory
7369 .select (feedbackResponseDto )
7470 .from (feedback )
7571 .join (member ).on (feedback .member .eq (member )).fetchJoin ()
7672 .where (
77- searchCondition
78- .and (answerStatusCondition )
79- .and (categoriesCondition )
80- .and (crossroadIdCondition )
73+ crossroadIdCondition
74+ .and (searchCondition )
8175 .and (activityMember )
8276 .and (isNotDeletedFeedback )
8377 )
@@ -91,10 +85,8 @@ public Page<FeedbackResponse> findAllByActiveMembers(
9185 .from (feedback )
9286 .join (member ).on (feedback .member .eq (member )).fetchJoin ()
9387 .where (
94- searchCondition
95- .and (answerStatusCondition )
96- .and (categoriesCondition )
97- .and (crossroadIdCondition )
88+ crossroadIdCondition
89+ .and (searchCondition )
9890 .and (activityMember )
9991 .and (isNotDeletedFeedback )
10092 ).fetchOne ()
@@ -120,29 +112,16 @@ public Page<FeedbackResponse> findPagedExcludingMember(Long memberId, Pageable p
120112
121113 @ Override
122114 public Page <FeedbackResponse > findAllByFilter (
123- Pageable pageable , SearchTarget target ,
124- String keyword , AnswerStatus answerStatus ,
125- Set <FeedbackCategory > categories ,
126- LocalDate startDate , LocalDate endDate ,
127- Boolean deleted
115+ Pageable pageable ,
116+ FeedbackSearchCondition condition
128117 ) {
129- BooleanExpression searchCondition = searchCondition (target , keyword );
130- BooleanExpression answerStatusCondition = answerStatusCondition (answerStatus );
131- BooleanExpression categoriesCondition = categoriesCondition (categories );
132- BooleanExpression betweenDates = betweenDates (feedback .createdAt , startDate , endDate );
133- BooleanExpression deletedCondition = deletedCondition (deleted );
118+ BooleanExpression searchCondition = searchCondition (condition );
134119
135120 List <FeedbackResponse > results = jpaQueryFactory
136121 .select (feedbackResponseDto )
137122 .from (feedback )
138123 .join (member ).on (feedback .member .eq (member )).fetchJoin ()
139- .where (
140- searchCondition
141- .and (answerStatusCondition )
142- .and (deletedCondition )
143- .and (categoriesCondition )
144- .and (betweenDates )
145- )
124+ .where (searchCondition )
146125 .offset (pageable .getOffset ()).limit (pageable .getPageSize ())
147126 .orderBy (getOrderSpecifiers (pageable , feedback .getType (), "feedback" )).fetch ();
148127
@@ -151,13 +130,8 @@ public Page<FeedbackResponse> findAllByFilter(
151130 .select (feedback .count ())
152131 .from (feedback )
153132 .join (member ).on (feedback .member .eq (member )).fetchJoin ()
154- .where (
155- searchCondition
156- .and (answerStatusCondition )
157- .and (deletedCondition )
158- .and (categoriesCondition )
159- .and (betweenDates )
160- ).fetchOne ()
133+ .where (searchCondition )
134+ .fetchOne ()
161135 ).orElse (0L );
162136
163137 return new PageImpl <>(results , pageable , count );
@@ -175,6 +149,23 @@ public Feedback findByIdOrThrow(Long id ) {
175149 ).orElseThrow (() -> new BusinessException (FeedbackErrorCode .NOT_FOUND_FEEDBACK ));
176150 }
177151
152+ private BooleanExpression searchCondition (FeedbackSearchCondition condition ) {
153+ return Expressions .allOf (
154+ searchKeyword (condition .getTarget (), condition .getKeyword ()),
155+ answerStatusCondition (condition .getAnswerStatus ()),
156+ categoriesCondition (condition .getCategories ()),
157+ condition .getAdminSearchCondition ()
158+ .map (adminCondition -> Expressions .allOf (
159+ betweenDates (
160+ feedback .createdAt ,
161+ adminCondition .getStartDate (), adminCondition .getEndDate ()
162+ ),
163+ deletedCondition (adminCondition .getDeleted ())
164+ ))
165+ .orElse (Expressions .TRUE )
166+ );
167+ }
168+
178169 private BooleanExpression answerStatusCondition (AnswerStatus answerStatus ) {
179170 if (answerStatus == null ) {
180171 return Expressions .TRUE ;
@@ -205,7 +196,7 @@ private BooleanExpression categoriesCondition(Set<FeedbackCategory> categories)
205196 return expression ;
206197 }
207198
208- private BooleanExpression searchCondition (SearchTarget target , String keyword ) {
199+ private BooleanExpression searchKeyword (SearchTarget target , String keyword ) {
209200 BooleanExpression fulltextSearch = Expressions .TRUE ;
210201 if (SearchTarget .WRITER .equals (target )) {
211202 fulltextSearch = fulltextSearch (keyword , member .nickname );
0 commit comments