Skip to content

Commit

Permalink
Merge pull request #146 from teamterning/develop
Browse files Browse the repository at this point in the history
[🔀 merge] [2차] 코드 리펙토링 사항 적용 (5)
  • Loading branch information
JungYoonShin authored Sep 25, 2024
2 parents 707c0c9 + bdd8af6 commit 025a6cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public enum ErrorMessage {
UNAUTHORIZED_JWT_EXCEPTION(401, "유효하지 않은 토큰입니다"),

// 회원가입
FAILED_SIGN_UP(401, "회원가입에 실패하였습니다"),
EXISTS_USER_ALREADY(401, "이미 존재하는 유저입니다"),
FAILED_SIGN_UP(400, "회원가입에 실패하였습니다"),
EXISTS_USER_ALREADY(409, "이미 존재하는 유저입니다"),

// 사용자 필터링 정보 생성
FAILED_SIGN_UP_USER_FILTER_CREATION(404, "사용자 필터 생성에 실패하였습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.NumberTemplate;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;
import org.terning.terningserver.domain.InternshipAnnouncement;
import org.terning.terningserver.domain.enums.Grade;
import org.terning.terningserver.domain.enums.WorkingPeriod;
Expand Down Expand Up @@ -63,31 +65,25 @@ public Page<InternshipAnnouncement> searchInternshipAnnouncement(String keyword,

List<InternshipAnnouncement> internshipAnnouncements = jpaQueryFactory
.selectFrom(internshipAnnouncement)
.leftJoin(internshipAnnouncement.scraps).fetchJoin()
.leftJoin(internshipAnnouncement.scraps)
.where(contentLike(keyword))
.orderBy(sortAnnouncementsByDeadline().asc(), createOrderSpecifier(sortBy))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

Long count = jpaQueryFactory
JPAQuery<Long> count = jpaQueryFactory
.select(internshipAnnouncement.count())
.from(internshipAnnouncement)
.leftJoin(internshipAnnouncement.scraps)
.where(contentLike(keyword))
.fetchOne();
.where(contentLike(keyword));

// 인턴공고가 없을 경우, 즉 count가 null일 경우 0L을 기본값으로 설정
long announcementCount = (count != null) ? count : 0L;

return new PageImpl<>(internshipAnnouncements, pageable, announcementCount);
return PageableExecutionUtils.getPage(internshipAnnouncements, pageable, count::fetchOne);
}

private BooleanExpression contentLike(String keyword) {
return internshipAnnouncement.title.contains(keyword);
}


//정렬 조건(5가지, 채용 마감 이른 순, 짧은 근무 기간 순, 긴 근무 기간 순,
private OrderSpecifier createOrderSpecifier(String sortBy) {
return switch (sortBy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private User findUserById(long id) {

private User findUserByRefreshToken(String refreshToken) {
return userRepository.findByRefreshToken(getTokenFromBearerString(refreshToken))
.orElseThrow(() -> new CustomException(INVALID_USER));
.orElseThrow(() -> new CustomException(FAILED_TOKEN_REISSUE));
}


Expand Down

0 comments on commit 025a6cb

Please sign in to comment.