diff --git a/src/main/java/com/github/cokothon/domain/board/controller/BoardController.java b/src/main/java/com/github/cokothon/domain/board/controller/BoardController.java index fe5b260..852ebd1 100644 --- a/src/main/java/com/github/cokothon/domain/board/controller/BoardController.java +++ b/src/main/java/com/github/cokothon/domain/board/controller/BoardController.java @@ -60,4 +60,9 @@ public ApiResponse deleteBoard(@PathVariable("boardId") String boardId) { public ApiResponse getBoards() { return ApiResponse.ok(boardService.getBoards()); } + + @GetMapping("/best") + public ApiResponse getBestBoards(){ + return ApiResponse.ok(boardService.getBestBoards()); + } } diff --git a/src/main/java/com/github/cokothon/domain/board/service/BoardService.java b/src/main/java/com/github/cokothon/domain/board/service/BoardService.java index e43ef0f..f975fa8 100644 --- a/src/main/java/com/github/cokothon/domain/board/service/BoardService.java +++ b/src/main/java/com/github/cokothon/domain/board/service/BoardService.java @@ -10,15 +10,21 @@ import com.github.cokothon.domain.user.schema.User; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Sort; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import java.util.List; +import static org.springframework.data.mongodb.core.aggregation.Aggregation.addFields; + @Service @RequiredArgsConstructor public class BoardService { private final BoardRepository boardRepository; + private final MongoTemplate mongoTemplate; public void createBoard(User user, CreateBoardRequest dto) { @@ -83,4 +89,17 @@ public GetBoardsResponse getBoards() { .boards(boards) .build(); } + + public GetBoardsResponse getBestBoards() { + + Aggregation aggregation = Aggregation.newAggregation( + addFields().addField("likeCount").withValueOfToArraySize("like").build(), + + + ) + + return GetBoardsResponse.builder() + .boards(boards) + .build(); + } }