Merge branch 'Be/Board' into 'backend'

[Back-End] feat : 게시판 조회 최신순 조회로 변경

See merge request s11-webmobile1-sub2/S11P12A701!99
This commit is contained in:
김기창 2024-08-08 09:48:51 +09:00
commit 8c936e1762
2 changed files with 3 additions and 2 deletions

View File

@ -38,7 +38,7 @@ public class BoardController {
List<ResponseBoardSummaryDto> boardSummaries = boardService.findBoards(pageNo, category, lectureId); List<ResponseBoardSummaryDto> boardSummaries = boardService.findBoards(pageNo, category, lectureId);
if(boardSummaries.isEmpty()) if(boardSummaries.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(boardSummaries, HttpStatus.NO_CONTENT);
return new ResponseEntity<>(boardSummaries, HttpStatus.OK); return new ResponseEntity<>(boardSummaries, HttpStatus.OK);
} }

View File

@ -12,6 +12,7 @@ import com.edufocus.edufocus.user.model.entity.vo.User;
import com.edufocus.edufocus.user.model.repository.UserRepository; import com.edufocus.edufocus.user.model.repository.UserRepository;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -39,7 +40,7 @@ public class BoardServiceImpl implements BoardService {
@Transactional @Transactional
public List<ResponseBoardSummaryDto> findBoards(int pageNo, String category, long lectureId) { public List<ResponseBoardSummaryDto> findBoards(int pageNo, String category, long lectureId) {
Pageable pageable = PageRequest.of(pageNo, PAGE_SIZE); Pageable pageable = PageRequest.of(pageNo, PAGE_SIZE, Sort.by("created_at").descending());
List<Board> boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable).getContent(); List<Board> boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable).getContent();