diff --git a/src/main/java/com/olive/pribee/global/common/DataPageMappingDto.java b/src/main/java/com/olive/pribee/global/common/DataPageMappingDto.java new file mode 100644 index 0000000..04ffbf7 --- /dev/null +++ b/src/main/java/com/olive/pribee/global/common/DataPageMappingDto.java @@ -0,0 +1,41 @@ +package com.olive.pribee.global.common; + +import lombok.Getter; + +@Getter +public class DataPageMappingDto { + 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 DataPageMappingDto of(T data, long totalElements, int totalPages, int size, + int numberOfElements) { + return new DataPageMappingDto<>(data, totalElements, totalPages, size, numberOfElements); + } + + public static DataPageMappingDto of(T data, Integer code, String message, long totalElements, + int totalPages, int size, + int numberOfElements) { + return new DataPageMappingDto<>(data, message, totalElements, totalPages, size, numberOfElements); + } +} \ No newline at end of file diff --git a/src/main/java/com/olive/pribee/module/feed/controller/FbPostController.java b/src/main/java/com/olive/pribee/module/feed/controller/FbPostController.java index 349ef1e..98a0e54 100644 --- a/src/main/java/com/olive/pribee/module/feed/controller/FbPostController.java +++ b/src/main/java/com/olive/pribee/module/feed/controller/FbPostController.java @@ -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; @@ -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; @@ -32,14 +30,12 @@ public class FbPostController implements FbPostControllerDocs { @GetMapping public ResponseEntity 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)); } // 게시물 첨부 조회 diff --git a/src/main/java/com/olive/pribee/module/feed/dto/res/FbPostTotalRes.java b/src/main/java/com/olive/pribee/module/feed/dto/res/FbPostTotalRes.java index 1b63516..1ef4fe5 100644 --- a/src/main/java/com/olive/pribee/module/feed/dto/res/FbPostTotalRes.java +++ b/src/main/java/com/olive/pribee/module/feed/dto/res/FbPostTotalRes.java @@ -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; @@ -22,7 +26,7 @@ public class FbPostTotalRes { private Double averageDangerScore; @Schema(description = "게시물 정보") - private Page fbPostResPage; + private DataPageMappingDto> fbPostResPage; public static FbPostTotalRes of( long totalPostCount, @@ -30,11 +34,13 @@ public static FbPostTotalRes of( Double averageDangerScore, Page 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(); } }