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
@@ -0,0 +1,41 @@
package com.olive.pribee.global.common;

import lombok.Getter;

@Getter
public class DataPageMappingDto<T> {
private final T data;
private final long totalElements;
private final int totalPages;
private final int size;
private final int numberOfElements;

private DataPageMappingDto(T data, long totalElements, int totalPages, int size,
int numberOfElements) {
this.data = data;
this.totalElements = totalElements;
this.size = size;
this.numberOfElements = numberOfElements;
this.totalPages = totalPages;
}

private DataPageMappingDto(T data, String message, long totalElements, int totalPages, int size,
int numberOfElements) {
this.data = data;
this.totalElements = totalElements;
this.size = size;
this.numberOfElements = numberOfElements;
this.totalPages = totalPages;
}

public static <T> DataPageMappingDto<T> of(T data, long totalElements, int totalPages, int size,
int numberOfElements) {
return new DataPageMappingDto<>(data, totalElements, totalPages, size, numberOfElements);
}

public static <T> DataPageMappingDto<T> of(T data, Integer code, String message, long totalElements,
int totalPages, int size,
int numberOfElements) {
return new DataPageMappingDto<>(data, message, totalElements, totalPages, size, numberOfElements);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.olive.pribee.module.feed.controller;

import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -9,11 +8,10 @@
import org.springframework.web.bind.annotation.RestController;

import com.mongodb.lang.Nullable;
import com.olive.pribee.global.common.DataPageResponseDto;
import com.olive.pribee.global.common.DataResponseDto;
import com.olive.pribee.global.common.ResponseDto;
import com.olive.pribee.global.enums.DetectKeyword;
import com.olive.pribee.module.auth.domain.entity.Member;
import com.olive.pribee.module.feed.dto.res.FbPostRes;
import com.olive.pribee.module.feed.dto.res.FbPostTotalRes;
import com.olive.pribee.module.feed.service.FbPostService;

Expand All @@ -32,14 +30,12 @@ public class FbPostController implements FbPostControllerDocs {
@GetMapping
public ResponseEntity<ResponseDto> getExhibitions(
@AuthenticationPrincipal Member member,
@Schema(description = "필터를 의미합니다.") @RequestParam(name = "detectType") @Nullable DetectKeyword detectType,
@Schema(description = "검색어를 의미합니다.") @RequestParam(name = "keyword") @Nullable String keyword,
@Schema(description = "0번부터 시작합니다. 조회할 페이지 번호를 의미합니다.") @RequestParam(name = "page") int page,
@Schema(description = "조회할 페이지 크기를 의미합니다.") @RequestParam(name = "size") int size) {
@Schema(description = "필터를 의미합니다.") @RequestParam(name = "detectType") @Nullable DetectKeyword detectType,
@Schema(description = "검색어를 의미합니다.") @RequestParam(name = "keyword") @Nullable String keyword,
@Schema(description = "0번부터 시작합니다. 조회할 페이지 번호를 의미합니다.") @RequestParam(name = "page") int page,
@Schema(description = "조회할 페이지 크기를 의미합니다.") @RequestParam(name = "size") int size) {
FbPostTotalRes resPage = fbPostService.getTotalPost(member.getId(), detectType, keyword, page, size);
return ResponseEntity.status(200).body(
DataPageResponseDto.of(resPage.getFbPostResPage().getContent(), 200, resPage.getFbPostResPage().getTotalElements(),
resPage.getFbPostResPage().getTotalPages(), resPage.getFbPostResPage().getSize(), resPage.getFbPostResPage().getNumberOfElements()));
return ResponseEntity.status(200).body(DataResponseDto.of(resPage, 200));
}

// 게시물 첨부 조회
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.olive.pribee.module.feed.dto.res;

import java.util.List;

import org.springframework.data.domain.Page;

import com.olive.pribee.global.common.DataPageMappingDto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -22,19 +26,21 @@ public class FbPostTotalRes {
private Double averageDangerScore;

@Schema(description = "게시물 정보")
private Page<FbPostRes> fbPostResPage;
private DataPageMappingDto<List<FbPostRes>> fbPostResPage;

public static FbPostTotalRes of(
long totalPostCount,
long detectPostCount,
Double averageDangerScore,
Page<FbPostRes> fbPostResPage
) {

return FbPostTotalRes.builder()
.totalPostCount(totalPostCount)
.detectPostCount(detectPostCount)
.averageDangerScore(averageDangerScore)
.fbPostResPage(fbPostResPage)
.fbPostResPage(DataPageMappingDto.of(fbPostResPage.getContent(), fbPostResPage.getTotalElements(),
fbPostResPage.getTotalPages(), fbPostResPage.getSize(), fbPostResPage.getNumberOfElements()))
.build();
}
}