Skip to content

Commit

Permalink
refactor(profile) : 프로필 전체 조회할 때의 필터 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Woongbin06 committed Apr 24, 2024
1 parent 1a441c9 commit 000269f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public record Filter(
Boolean isRecruited,
List<Major> majors,
String cardinals
Major major,
Long cardinal
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public List<Profile> findAllFiltered(Filter filter) {
.leftJoin(profile.writer, user)
.fetchJoin()
.where(
majorFilter(filter.majors()),
majorFilter(filter.major()),
recruitedFilter(filter.isRecruited()),
admissionYearFilter(filter.cardinals())
cardinalFilter(filter.cardinal())
).fetch();
}

private BooleanExpression majorFilter(List<Major> majors) {
if (majors == null) {
private BooleanExpression majorFilter(Major major) {
if (major == null) {
return null;
}

return profile.information.major.in(majors);
return profile.information.major.eq(major);
}

private BooleanExpression recruitedFilter(Boolean isRecruited) {
Expand All @@ -54,15 +54,11 @@ private BooleanExpression recruitedFilter(Boolean isRecruited) {
return profile.company.isNotEmpty();
}

private BooleanExpression admissionYearFilter(String admissionYear) {
if (admissionYear == null) {
private BooleanExpression cardinalFilter(Long cardinal) {
if (cardinal == null) {
return null;
}

List<Integer> list = Arrays.stream(admissionYear.split("-"))
.map(Integer::parseInt)
.toList();

return user.cardinal.between(list.get(0), list.get(1));
return user.cardinal.eq(cardinal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

public record FilterRequest(
@RequestParam(required = false)
Boolean isReqruited,
Boolean isRecruited,
@RequestParam(required = false)
List<Major> majors,
Major major,
@RequestParam(required = false)
String cardinals
Long cardinal
) {
public Filter toDomain() {
return new Filter(
isReqruited,
majors,
cardinals
isRecruited,
major,
cardinal
);
}
}

0 comments on commit 000269f

Please sign in to comment.