Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static in.koreatech.koin.global.code.ApiResponseCode.*;
import static io.swagger.v3.oas.annotations.enums.ParameterIn.PATH;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -86,7 +88,8 @@ ResponseEntity<LostItemArticlesResponse> getLostItemArticlesV2(
@RequestParam(required = false) String type,
@RequestParam(required = false) Integer page,
@RequestParam(required = false) Integer limit,
@RequestParam(required = false, name = "category", defaultValue = "ALL") LostItemCategoryFilter itemCategory,
@Parameter(description = "카테고리 (복수 선택 가능, 미선택 시 전체)")
@RequestParam(required = false, name = "category") List<LostItemCategoryFilter> itemCategories,
@Parameter(description = "물품 상태 (ALL: 전체, FOUND: 찾음, NOT_FOUND: 찾는 중)")
@RequestParam(required = false, defaultValue = "ALL") LostItemFoundStatus foundStatus,
@Parameter(description = "정렬 순서 (LATEST: 최신순(default), OLDEST: 오래된순)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static in.koreatech.koin.domain.user.model.UserType.*;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -68,15 +70,15 @@ public ResponseEntity<LostItemArticlesResponse> getLostItemArticlesV2(
@Parameter(description = "분실물 타입 (LOST: 분실물, FOUND: 습득물)") @RequestParam(required = false) String type,
@RequestParam(required = false) Integer page,
@RequestParam(required = false) Integer limit,
@RequestParam(required = false, name = "category", defaultValue = "ALL") LostItemCategoryFilter itemCategory,
@RequestParam(required = false, name = "category") List<LostItemCategoryFilter> itemCategories,
@RequestParam(required = false, defaultValue = "ALL") LostItemFoundStatus foundStatus,
@RequestParam(required = false, name = "sort", defaultValue = "LATEST") LostItemSortType sort,
@RequestParam(required = false, name = "author", defaultValue = "ALL") LostItemAuthorFilter authorType,
@RequestParam(required = false, name = "title") String title,
@UserId Integer userId
) {
LostItemArticlesResponse response = lostItemArticleService.getLostItemArticlesV2(type, page, limit, userId,
foundStatus, itemCategory, sort, authorType, title);
foundStatus, itemCategories, sort, authorType, title);
return ResponseEntity.ok().body(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public interface LostItemArticleCustomRepository {

LostItemArticleSummary getArticleSummary(Integer articleId);

Long countLostItemArticlesWithFilters(String type, Boolean isFound, String itemCategory,
Long countLostItemArticlesWithFilters(String type, Boolean isFound, List<String> itemCategories,
Integer lostItemArticleBoardId, Integer authorId, String titleQuery);

List<Article> findLostItemArticlesWithFilters(Integer boardId, String type, Boolean isFound,
String itemCategoryFilter, LostItemSortType sort, PageRequest pageRequest, Integer authorId, String titleQuery);
List<String> itemCategories, LostItemSortType sort, PageRequest pageRequest, Integer authorId, String titleQuery);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public LostItemArticleSummary getArticleSummary(Integer articleId) {
.fetchFirst();
}

public Long countLostItemArticlesWithFilters(String type, Boolean isFound, String itemCategory,
public Long countLostItemArticlesWithFilters(String type, Boolean isFound, List<String> itemCategories,
Integer lostItemArticleBoardId, Integer authorId, String titleQuery) {
BooleanExpression filter = getFilter(lostItemArticleBoardId, type, itemCategory, isFound, authorId, titleQuery);
BooleanExpression filter = getFilter(lostItemArticleBoardId, type, itemCategories, isFound, authorId, titleQuery);

return queryFactory
.select(article.count())
Expand All @@ -51,9 +51,9 @@ public Long countLostItemArticlesWithFilters(String type, Boolean isFound, Strin
}

public List<Article> findLostItemArticlesWithFilters(Integer boardId, String type, Boolean isFound,
String itemCategory, LostItemSortType sort, PageRequest pageRequest, Integer authorId, String titleQuery) {
List<String> itemCategories, LostItemSortType sort, PageRequest pageRequest, Integer authorId, String titleQuery) {

BooleanExpression predicate = getFilter(boardId, type, itemCategory, isFound, authorId, titleQuery);
BooleanExpression predicate = getFilter(boardId, type, itemCategories, isFound, authorId, titleQuery);
OrderSpecifier<?>[] orderSpecifiers = getOrderSpecifiers(sort);

return queryFactory
Expand All @@ -67,7 +67,7 @@ public List<Article> findLostItemArticlesWithFilters(Integer boardId, String typ
.fetch();
}

private BooleanExpression getFilter(Integer boardId, String type, String itemCategory, Boolean isFound,
private BooleanExpression getFilter(Integer boardId, String type, List<String> itemCategories, Boolean isFound,
Integer authorId, String titleQuery) {
BooleanExpression filter = article.board.id.eq(boardId)
.and(article.isDeleted.isFalse())
Expand All @@ -81,8 +81,8 @@ private BooleanExpression getFilter(Integer boardId, String type, String itemCat
filter = filter.and(lostItemArticle.isFound.eq(isFound));
}

if (itemCategory != null && !itemCategory.isBlank()) {
filter = filter.and(lostItemArticle.category.eq(itemCategory));
if (itemCategories != null && !itemCategories.isEmpty()) {
filter = filter.and(lostItemArticle.category.in(itemCategories));
}

if (authorId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -102,7 +103,7 @@ public LostItemArticlesResponse getLostItemArticles(String type, Integer page, I
}

public LostItemArticlesResponse getLostItemArticlesV2(String type, Integer page, Integer limit, Integer userId,
LostItemFoundStatus foundStatus, LostItemCategoryFilter itemCategory, LostItemSortType sort,
LostItemFoundStatus foundStatus, List<LostItemCategoryFilter> itemCategories, LostItemSortType sort,
LostItemAuthorFilter authorType, String titleQuery) {
Integer authorIdFilter = authorType.getRequiredAuthorId(userId);

Expand All @@ -114,19 +115,23 @@ public LostItemArticlesResponse getLostItemArticlesV2(String type, Integer page,
.map(LostItemFoundStatus::getQueryStatus)
.orElse(null);

String itemCategoryFilter = Optional.ofNullable(itemCategory)
.filter(category -> category != LostItemCategoryFilter.ALL)
.map(LostItemCategoryFilter::getStatus)
List<String> itemCategoryFilters = Optional.ofNullable(itemCategories)
.filter(categories -> !categories.isEmpty())
.filter(categories -> !categories.contains(LostItemCategoryFilter.ALL))
.map(categories -> categories.stream()
.map(LostItemCategoryFilter::getStatus)
.filter(Objects::nonNull)
.collect(Collectors.toList()))
.orElse(null);

Long total = lostItemArticleRepository.countLostItemArticlesWithFilters(type, foundStatusFilter,
itemCategoryFilter, LOST_ITEM_BOARD_ID, authorIdFilter, refinedTitleQuery);
itemCategoryFilters, LOST_ITEM_BOARD_ID, authorIdFilter, refinedTitleQuery);

Criteria criteria = Criteria.of(page, limit, total.intValue());
PageRequest pageRequest = PageRequest.of(criteria.getPage(), criteria.getLimit());

List<Article> articles = lostItemArticleRepository.findLostItemArticlesWithFilters(LOST_ITEM_BOARD_ID, type,
foundStatusFilter, itemCategoryFilter, sort, pageRequest, authorIdFilter, refinedTitleQuery);
foundStatusFilter, itemCategoryFilters, sort, pageRequest, authorIdFilter, refinedTitleQuery);
Page<Article> articlePage = new PageImpl<>(articles, pageRequest, total);

return LostItemArticlesResponse.of(articlePage, criteria, userId);
Expand Down
Loading