From 3de41e4f3918fa1d7b1cdda2e8a4cbe783471aee Mon Sep 17 00:00:00 2001 From: bo Date: Thu, 25 Apr 2024 09:07:16 +0900 Subject: [PATCH] =?UTF-8?q?chore(profile):=20ProfileQueryRepository=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...itory.java => QueryProfileRepository.java} | 2 +- .../server/profile/domain/value/Filter.java | 2 +- ...l.java => QueryProfileRepositoryImpl.java} | 19 +++++++------------ .../presentation/dto/FilterRequest.java | 4 ++-- .../service/implementation/ProfileReader.java | 4 ++-- 5 files changed, 13 insertions(+), 18 deletions(-) rename main-server/src/main/java/com/sickgyun/server/profile/domain/repository/{ProfileQueryRepository.java => QueryProfileRepository.java} (84%) rename main-server/src/main/java/com/sickgyun/server/profile/infra/database/{ProfileQueryRepositoryImpl.java => QueryProfileRepositoryImpl.java} (72%) diff --git a/main-server/src/main/java/com/sickgyun/server/profile/domain/repository/ProfileQueryRepository.java b/main-server/src/main/java/com/sickgyun/server/profile/domain/repository/QueryProfileRepository.java similarity index 84% rename from main-server/src/main/java/com/sickgyun/server/profile/domain/repository/ProfileQueryRepository.java rename to main-server/src/main/java/com/sickgyun/server/profile/domain/repository/QueryProfileRepository.java index a845329..9d61ea7 100644 --- a/main-server/src/main/java/com/sickgyun/server/profile/domain/repository/ProfileQueryRepository.java +++ b/main-server/src/main/java/com/sickgyun/server/profile/domain/repository/QueryProfileRepository.java @@ -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 findAllFiltered(Filter filter); } diff --git a/main-server/src/main/java/com/sickgyun/server/profile/domain/value/Filter.java b/main-server/src/main/java/com/sickgyun/server/profile/domain/value/Filter.java index 07ce96e..161d5ff 100644 --- a/main-server/src/main/java/com/sickgyun/server/profile/domain/value/Filter.java +++ b/main-server/src/main/java/com/sickgyun/server/profile/domain/value/Filter.java @@ -5,6 +5,6 @@ public record Filter( Boolean isRecruited, List majors, - String cardinals + Long cardinal ) { } diff --git a/main-server/src/main/java/com/sickgyun/server/profile/infra/database/ProfileQueryRepositoryImpl.java b/main-server/src/main/java/com/sickgyun/server/profile/infra/database/QueryProfileRepositoryImpl.java similarity index 72% rename from main-server/src/main/java/com/sickgyun/server/profile/infra/database/ProfileQueryRepositoryImpl.java rename to main-server/src/main/java/com/sickgyun/server/profile/infra/database/QueryProfileRepositoryImpl.java index b8f960f..5dcf3cf 100644 --- a/main-server/src/main/java/com/sickgyun/server/profile/infra/database/ProfileQueryRepositoryImpl.java +++ b/main-server/src/main/java/com/sickgyun/server/profile/infra/database/QueryProfileRepositoryImpl.java @@ -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; @@ -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; @@ -21,7 +20,7 @@ @Repository @RequiredArgsConstructor @Transactional(readOnly = true) -public class ProfileQueryRepositoryImpl implements ProfileQueryRepository { +public class QueryProfileRepositoryImpl implements QueryProfileRepository { private final JPAQueryFactory queryFactory; @@ -34,7 +33,7 @@ public List findAllFiltered(Filter filter) { .where( majorFilter(filter.majors()), recruitedFilter(filter.isRecruited()), - admissionYearFilter(filter.cardinals()) + cardinalFilter(filter.cardinal()) ).fetch(); } @@ -47,22 +46,18 @@ private BooleanExpression majorFilter(List 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 list = Arrays.stream(admissionYear.split("-")) - .map(Integer::parseInt) - .toList(); - - return user.cardinal.between(list.get(0), list.get(1)); + return user.cardinal.eq(cardinal); } } diff --git a/main-server/src/main/java/com/sickgyun/server/profile/presentation/dto/FilterRequest.java b/main-server/src/main/java/com/sickgyun/server/profile/presentation/dto/FilterRequest.java index c653d87..786a2ce 100644 --- a/main-server/src/main/java/com/sickgyun/server/profile/presentation/dto/FilterRequest.java +++ b/main-server/src/main/java/com/sickgyun/server/profile/presentation/dto/FilterRequest.java @@ -13,13 +13,13 @@ public record FilterRequest( @RequestParam(required = false) List majors, @RequestParam(required = false) - String cardinals + Long cardinal ) { public Filter toDomain() { return new Filter( isReqruited, majors, - cardinals + cardinal ); } } diff --git a/main-server/src/main/java/com/sickgyun/server/profile/service/implementation/ProfileReader.java b/main-server/src/main/java/com/sickgyun/server/profile/service/implementation/ProfileReader.java index ae08d19..ba28b28 100644 --- a/main-server/src/main/java/com/sickgyun/server/profile/service/implementation/ProfileReader.java +++ b/main-server/src/main/java/com/sickgyun/server/profile/service/implementation/ProfileReader.java @@ -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; @@ -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);