1
1
package page .time .api .domain .lecture .dao ;
2
2
3
- import com .querydsl .core .BooleanBuilder ;
4
3
import com .querydsl .core .types .dsl .BooleanExpression ;
5
4
import com .querydsl .jpa .impl .JPAQueryFactory ;
6
5
import lombok .RequiredArgsConstructor ;
7
6
import org .springframework .stereotype .Repository ;
7
+ import org .springframework .util .CollectionUtils ;
8
8
import page .time .api .domain .lecture .domain .Lecture ;
9
9
import page .time .api .domain .lecture .domain .Type ;
10
10
@@ -21,17 +21,17 @@ public class LectureRepositoryCustomImpl implements LectureRepositoryCustom {
21
21
private static final String NONE = "None" ;
22
22
23
23
@ Override
24
- public List <Lecture > findByFilter (String campus , Type type , Integer grade , List <String > day , List <String > time , String major , Boolean isExceeded , String lectureName , Long cursor , int limit ) {
24
+ public List <Lecture > findByFilter (List < String > campuses , List < Type > types , List < Integer > grades , List <String > days , List <String > times , List < String > majors , Boolean isExceeded , String lectureName , Long cursor , int limit ) {
25
25
return query
26
26
.selectFrom (lecture )
27
27
.where (
28
28
containsToLectureName (lectureName ),
29
- eqToMajor ( major ),
30
- eqToDay ( day ),
31
- eqToTime ( time ),
32
- eqToGrade ( grade ),
33
- eqToType ( type ),
34
- eqToCampus ( campus ),
29
+ eqToMajors ( majors ),
30
+ eqToDays ( days ),
31
+ eqToTimes ( times ),
32
+ eqToGrades ( grades ),
33
+ eqToTypes ( types ),
34
+ eqToCampuses ( campuses ),
35
35
eqToIsExceeded (isExceeded ),
36
36
gtCursor (cursor )
37
37
)
@@ -52,47 +52,54 @@ public List<String> findByMajor(String major) {
52
52
.fetch ();
53
53
}
54
54
55
- private BooleanExpression eqToCampus ( String campus ) {
56
- if (campus == null || campus .isEmpty ()) {
55
+ private BooleanExpression eqToCampuses ( List < String > campuses ) {
56
+ if (CollectionUtils .isEmpty (campuses )) {
57
57
return null ;
58
58
}
59
- return lecture .campus .contains (campus );
59
+ return campuses .stream ()
60
+ .map (lecture .campus ::contains )
61
+ .reduce (BooleanExpression ::or )
62
+ .orElse (null );
60
63
}
61
64
62
- private BooleanExpression eqToType ( Type type ) {
63
- if (type == null ) {
65
+ private BooleanExpression eqToTypes ( List < Type > types ) {
66
+ if (CollectionUtils . isEmpty ( types ) ) {
64
67
return null ;
65
68
}
66
- return lecture .type .eq (type );
69
+ return types .stream ()
70
+ .map (lecture .type ::eq )
71
+ .reduce (BooleanExpression ::or )
72
+ .orElse (null );
67
73
}
68
74
69
- private BooleanExpression eqToGrade ( Integer grade ) {
70
- if (grade == null ) {
75
+ private BooleanExpression eqToGrades ( List < Integer > grades ) {
76
+ if (CollectionUtils . isEmpty ( grades ) ) {
71
77
return null ;
72
78
}
73
- return lecture .grade .eq (grade );
79
+ return grades .stream ()
80
+ .map (lecture .grade ::eq )
81
+ .reduce (BooleanExpression ::or )
82
+ .orElse (null );
74
83
}
75
84
76
- private BooleanBuilder eqToDay (List <String > days ) {
77
- if (days == null || days .isEmpty ()) {
85
+ private BooleanExpression eqToDays (List <String > days ) {
86
+ if (CollectionUtils .isEmpty (days )) {
78
87
return null ;
79
88
}
80
- BooleanBuilder builder = new BooleanBuilder ();
81
- days .stream ()
89
+ return days .stream ()
82
90
.map (lecture .time ::contains )
83
- .forEach ( builder ::or );
84
- return builder ;
91
+ .reduce ( BooleanExpression ::or )
92
+ . orElse ( null ) ;
85
93
}
86
94
87
- private BooleanBuilder eqToTime (List <String > times ) {
88
- if (times == null || times .isEmpty ()) {
95
+ private BooleanExpression eqToTimes (List <String > times ) {
96
+ if (CollectionUtils .isEmpty (times )) {
89
97
return null ;
90
98
}
91
- BooleanBuilder builder = new BooleanBuilder ();
92
- times .stream ()
99
+ return times .stream ()
93
100
.map (lecture .time ::contains )
94
- .forEach ( builder ::or );
95
- return builder ;
101
+ .reduce ( BooleanExpression ::or )
102
+ . orElse ( null ) ;
96
103
}
97
104
98
105
private BooleanExpression eqToMajor (String major ) {
@@ -102,6 +109,16 @@ private BooleanExpression eqToMajor(String major) {
102
109
return lecture .major .contains (major );
103
110
}
104
111
112
+ private BooleanExpression eqToMajors (List <String > majors ) {
113
+ if (CollectionUtils .isEmpty (majors )) {
114
+ return null ;
115
+ }
116
+ return majors .stream ()
117
+ .map (lecture .major ::contains )
118
+ .reduce (BooleanExpression ::or )
119
+ .orElse (null );
120
+ }
121
+
105
122
private BooleanExpression eqToIsExceeded (Boolean isExceeded ) {
106
123
if (isExceeded == null ) {
107
124
return null ;
@@ -122,4 +139,4 @@ private BooleanExpression gtCursor(Long cursor) {
122
139
}
123
140
return lecture .id .gt (cursor );
124
141
}
125
- }
142
+ }
0 commit comments