Skip to content

Commit

Permalink
chore(profile): ProfileQueryRepository 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobhboy committed Apr 25, 2024
1 parent 3746e00 commit 3de41e4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import com.sickgyun.server.profile.domain.Profile;
import com.sickgyun.server.profile.domain.value.Filter;

public interface ProfileQueryRepository {
public interface QueryProfileRepository {
List<Profile> findAllFiltered(Filter filter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public record Filter(
Boolean isRecruited,
List<Major> majors,
String cardinals
Long cardinal
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.sickgyun.server.profile.domain.QProfile.*;
import static com.sickgyun.server.user.domain.QUser.*;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Repository;
Expand All @@ -12,7 +11,7 @@
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.sickgyun.server.profile.domain.Profile;
import com.sickgyun.server.profile.domain.repository.ProfileQueryRepository;
import com.sickgyun.server.profile.domain.repository.QueryProfileRepository;
import com.sickgyun.server.profile.domain.value.Filter;
import com.sickgyun.server.profile.domain.value.Major;

Expand All @@ -21,7 +20,7 @@
@Repository
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ProfileQueryRepositoryImpl implements ProfileQueryRepository {
public class QueryProfileRepositoryImpl implements QueryProfileRepository {

private final JPAQueryFactory queryFactory;

Expand All @@ -34,7 +33,7 @@ public List<Profile> findAllFiltered(Filter filter) {
.where(
majorFilter(filter.majors()),
recruitedFilter(filter.isRecruited()),
admissionYearFilter(filter.cardinals())
cardinalFilter(filter.cardinal())
).fetch();
}

Expand All @@ -47,22 +46,18 @@ private BooleanExpression majorFilter(List<Major> majors) {
}

private BooleanExpression recruitedFilter(Boolean isRecruited) {
if (isRecruited == null) {
if (isRecruited == null || !isRecruited) {
return null;
}

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 @@ -13,13 +13,13 @@ public record FilterRequest(
@RequestParam(required = false)
List<Major> majors,
@RequestParam(required = false)
String cardinals
Long cardinal
) {
public Filter toDomain() {
return new Filter(
isReqruited,
majors,
cardinals
cardinal
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.springframework.stereotype.Service;

import com.sickgyun.server.profile.domain.Profile;
import com.sickgyun.server.profile.domain.repository.ProfileQueryRepository;
import com.sickgyun.server.profile.domain.repository.ProfileRepository;
import com.sickgyun.server.profile.domain.repository.QueryProfileRepository;
import com.sickgyun.server.profile.domain.value.Filter;
import com.sickgyun.server.user.domain.User;

Expand All @@ -16,7 +16,7 @@
@RequiredArgsConstructor
public class ProfileReader {
private final ProfileRepository profileRepository;
private final ProfileQueryRepository queryRepository;
private final QueryProfileRepository queryRepository;

public Profile findProfileByWriter(User writer) {
return profileRepository.getByWriter(writer);
Expand Down

0 comments on commit 3de41e4

Please sign in to comment.