Skip to content

Commit

Permalink
[feature/Inhabas#228] 공모전 게시판 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
skytin1004 committed Feb 16, 2024
1 parent 1ee68ca commit c6115ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.inhabas.api.domain.contest.repository;

import static com.inhabas.api.domain.contest.domain.QContestBoard.contestBoard;

import com.inhabas.api.domain.contest.domain.QContestBoard;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import java.util.Map;
import java.util.function.BiFunction;

import lombok.RequiredArgsConstructor;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import com.inhabas.api.domain.contest.domain.ContestBoard;
import com.inhabas.api.domain.contest.domain.QContestBoard;
import com.inhabas.api.domain.contest.domain.valueObject.ContestType;
import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
Expand All @@ -29,16 +27,12 @@ public class ContestBoardRepositoryImpl implements ContestBoardRepositoryCustom
private QContestBoard contestBoard = QContestBoard.contestBoard;

// 필드 이름과 정렬 기준을 매핑
private OrderSpecifier<?> getSortedColumn(
Order order, QContestBoard contestBoard, String fieldName) {
Map<String, BiFunction<Order, QContestBoard, OrderSpecifier<?>>> orderSpecifierMap =
new HashMap<>();
private OrderSpecifier<?> getSortedColumn(Order order, QContestBoard contestBoard, String fieldName) {
Map<String, BiFunction<Order, QContestBoard, OrderSpecifier<?>>> orderSpecifierMap = new HashMap<>();
orderSpecifierMap.put("id", (o, cb) -> new OrderSpecifier<>(o, cb.id));
orderSpecifierMap.put("dateContestEnd", (o, cb) -> new OrderSpecifier<>(o, cb.dateContestEnd));

return orderSpecifierMap
.getOrDefault(fieldName, (o, cb) -> new OrderSpecifier<>(Order.DESC, cb.dateContestEnd))
.apply(order, contestBoard);
return orderSpecifierMap.getOrDefault(fieldName, (o, cb) -> new OrderSpecifier<>(Order.DESC, cb.dateContestEnd)).apply(order, contestBoard);
}

// 페이지 요청에 따른 정렬
Expand All @@ -47,8 +41,7 @@ public List<OrderSpecifier<?>> getAllOrderSpecifiers(Pageable pageable) {
if (pageable.getSort() != null) {
for (Sort.Order order : pageable.getSort()) {
Order direction = order.getDirection().isAscending() ? Order.ASC : Order.DESC;
OrderSpecifier<?> orderSpecifier =
getSortedColumn(direction, contestBoard, order.getProperty());
OrderSpecifier<?> orderSpecifier = getSortedColumn(direction, contestBoard, order.getProperty());
orders.add(orderSpecifier);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class ContestBoardServiceImpl implements ContestBoardService {

private final ContestBoardRepository contestBoardRepository;

private final ContestFieldRepository contestFieldRepository;

private final BoardSecurityChecker boardSecurityChecker;

private final MemberRepository memberRepository;
Expand Down Expand Up @@ -67,6 +65,7 @@ public List<ContestBoardDto> getContestBoardsByType(
return contestBoardList.stream()
.map(
contestBoard -> {
//첨부파일들 중 첫번째 이미지 = 썸네일
FileDownloadDto thumbnail =
contestBoard.getFiles().stream()
.filter(file -> isImageFile(file.getName()))
Expand Down

0 comments on commit c6115ca

Please sign in to comment.