Skip to content

Commit

Permalink
feat : board best 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
Ready-Bridge committed Sep 28, 2024
1 parent 866d3f8 commit c293b73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public ApiResponse<Void> deleteBoard(@PathVariable("boardId") String boardId) {
public ApiResponse<GetBoardsResponse> getBoards() {
return ApiResponse.ok(boardService.getBoards());
}

@GetMapping("/best")
public ApiResponse<GetBoardsResponse> getBestBoards(){
return ApiResponse.ok(boardService.getBestBoards());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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();
}
}

0 comments on commit c293b73

Please sign in to comment.