Skip to content

Commit

Permalink
Merge pull request #120 from Gamegoo-repo/feat/115
Browse files Browse the repository at this point in the history
[Feat/115] ๊ฒŒ์‹œํŒ ๊ธ€ ๋ชฉ๋ก ์กฐํšŒ ํ•„ํ„ฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„
  • Loading branch information
Eunjin3395 authored Aug 8, 2024
2 parents 50f34c2 + 7e57253 commit b1bdfaa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/main/java/com/gamegoo/controller/board/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,20 @@ public ApiResponse<String> delete(@PathVariable Long postId

@GetMapping("/list")
@Operation(summary = "๊ฒŒ์‹œํŒ ๊ธ€ ๋ชฉ๋ก ์กฐํšŒ API", description = "๊ฒŒ์‹œํŒ์—์„œ ๊ธ€ ๋ชฉ๋ก์„ ์กฐํšŒํ•˜๋Š” API ์ž…๋‹ˆ๋‹ค.")
@Parameter(name = "pageIdx", description = "์กฐํšŒํ•  ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
public ApiResponse<List<BoardResponse.boardListResponseDTO>> boardList(@RequestParam(defaultValue = "1") int pageIdx){
List<BoardResponse.boardListResponseDTO> result = boardService.getBoardList(pageIdx);
@Parameter(name = "pageIdx", description = "์กฐํšŒํ•  ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”. ํŽ˜์ด์ง€ ๋‹น 20๊ฐœ์˜ ๊ฒŒ์‹œ๋ฌผ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.")
public ApiResponse<List<BoardResponse.boardListResponseDTO>> boardList(@RequestParam(defaultValue = "1") int pageIdx,
@RequestParam(required = false) Integer mode,
@RequestParam(required = false) String tier,
@RequestParam(required = false) Integer mainPosition,
@RequestParam(required = false) Boolean voice){

// <ํฌ์ง€์…˜ ์ •๋ณด> ์ „์ฒด: 0, ํƒ‘: 1, ์ •๊ธ€: 2, ๋ฏธ๋“œ: 3, ๋ฐ”ํ…€:4, ์„œํฌํ„ฐ:5
if (mainPosition != null && mainPosition == 0) {
// ์ „์ฒด ํฌ์ง€์…˜ ์„ ํƒ ์‹œ ํ•„ํ„ฐ๋ง์—์„œ ์ œ์™ธ
mainPosition = null;
}

List<BoardResponse.boardListResponseDTO> result = boardService.getBoardList(mode,tier,mainPosition,voice,pageIdx);
return ApiResponse.onSuccess(result);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/gamegoo/dto/board/BoardResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static class boardListResponseDTO{
List<Long> championList;
Double winRate;
LocalDateTime createdAt;
Boolean voice;
}

@Getter
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/gamegoo/repository/board/BoardRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface BoardRepository extends JpaRepository<Board,Long>{
Page<Board> findByMemberId(Long memberId, Pageable pageable);

@Query("SELECT b From Board b JOIN b.member m WHERE" +
"(:mode IS NULL OR b.mode = :mode) AND " +
"(:tier IS NULL OR m.tier = :tier) AND " +
"(:mainPosition IS NULL OR b.mainPosition = :mainPosition OR b.subPosition = :mainPosition) AND " +
"(:voice IS NULL OR b.voice = :voice)")

Page<Board> findByFilters(@Param("mode") Integer mode,
@Param("tier") String tier,
@Param("mainPosition") Integer mainPosition,
@Param("voice") Boolean voice,
Pageable pageable);
}
5 changes: 3 additions & 2 deletions src/main/java/com/gamegoo/service/board/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void delete(Long boardId, Long memberId){

// ๊ฒŒ์‹œํŒ ๊ธ€ ๋ชฉ๋ก ์กฐํšŒ
@Transactional(readOnly = true)
public List<BoardResponse.boardListResponseDTO> getBoardList(int pageIdx){
public List<BoardResponse.boardListResponseDTO> getBoardList(Integer mode, String tier, Integer mainPosition, Boolean voice, int pageIdx){

// pageIdx ๊ฐ’ ๊ฒ€์ฆ.
if (pageIdx <= 0){
Expand All @@ -248,7 +248,7 @@ public List<BoardResponse.boardListResponseDTO> getBoardList(int pageIdx){
// ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ pageIdx๋ฅผ 1 ๊ฐ์†Œ -> pageIdx=1 ์ผ ๋•Œ, 1 ํŽ˜์ด์ง€.
Pageable pageable = PageRequest.of(pageIdx-1, PAGE_SIZE, Sort.by(Sort.Direction.DESC, "createdAt"));

List<Board> boards = boardRepository.findAll(pageable).getContent();
List<Board> boards = boardRepository.findByFilters(mode, tier, mainPosition, voice, pageable).getContent();

return boards.stream().map(board -> {

Expand All @@ -268,6 +268,7 @@ public List<BoardResponse.boardListResponseDTO> getBoardList(int pageIdx){
.championList(member.getMemberChampionList().stream().map(MemberChampion::getId).collect(Collectors.toList()))
.winRate(member.getWinRate())
.createdAt(board.getCreatedAt())
.voice(board.getVoice())
.build();

}).collect(Collectors.toList());
Expand Down

0 comments on commit b1bdfaa

Please sign in to comment.