Skip to content

Commit

Permalink
#9 feat: 보드 조회API-도시 별(1개) 전체 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Apr 29, 2023
1 parent 325b749 commit dfe0230
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ public ApplicationResponse<List<List<GetAllBoardRes>>> findBoardsByCategories(@R
return boardService.findBoardsByCategories(dto);
}


/**
* 게시글 도시 별(1개) 전체 조회
* @author 토마스
*/
@ApiOperation(value = "게시글 도시 별(1개) 전체 조회", notes = "게시글 도시 별(1개) 전체 조회")
@ApiResponses({
@ApiResponse(code= 201, message = "요청에 성공하였습니다."),
@ApiResponse(code= 404, message = "존재하지 않는 유저입니다."),
@ApiResponse(code = 4000 , message = "서버 오류입니다.")
})
@PostMapping("/get/city")
public ApplicationResponse<GetAllBoardsByCityRes> findAllBoardsByCityName(@RequestBody @Validated GetAllBoardsByCityReq getAllBoardsByCityReq){
return boardService.findAllBoardsByCityName(getAllBoardsByCityReq);
}

/**
* 게시글 My Club 조회: 자신이 생성한 보드들 조회
* @author 토마스
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.yogit.server.board.dto.request;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class GetAllBoardsByCityReq {

@ApiModelProperty(example = "1")
@ApiParam(value = "유저 ID", required = true)
private Long userId;

@ApiModelProperty(example = "1")
@ApiParam(value = "페이징 조회 페이지", required = true)
private int cursor;

@ApiModelProperty(example = "SEOUL")
@ApiParam(value = "City 이름", required = true)
private String cityName;

@ApiModelProperty(example = "reb5085c395164587b84ac583d023011f.0.sryrq.IDLsECw-rsTozfsX0Yz-CA")
@ApiParam(value = "애플 리프레쉬 토큰", required = true)
private String refreshToken;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.yogit.server.board.dto.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
public class GetAllBoardsByCityRes {

@ApiModelProperty(example = "[보드1, 보드2]", value = "보드 리스트")
private List<GetAllBoardRes> getAllBoardResList;

@ApiModelProperty(example = "10", value = "페이징 전체 페이지")
private int totalPage;

@Builder
public GetAllBoardsByCityRes(List<GetAllBoardRes> getAllBoardResList, int totalPage) {
this.getAllBoardResList = getAllBoardResList;
this.totalPage = totalPage;
}


public static GetAllBoardsByCityRes toDto(List<GetAllBoardRes> getAllBoardResList, int totalPage){
return GetAllBoardsByCityRes.builder()
.getAllBoardResList(getAllBoardResList)
.totalPage(totalPage)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public interface BoardRepository extends JpaRepository<Board, Long> {
@Query("select b from Board b where b.status = 'ACTIVE' and b.category.id = :categoryId")
Page<Board> findAllBoardsByCategory(Pageable pageable, @Param("categoryId") Long categoryId);

@Query("select b from Board b where b.status = 'ACTIVE' and b.city.cityName = :cityName")
Page<Board> findAllBoardsByCityName(Pageable pageable, @Param("cityName") String cityName);

@Query("select b from Board b where b.status = 'ACTIVE' and b.host.id = :userId")
Page<Board> findMyClubBoardsByUserId(Pageable pageable, @Param("userId") Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface BoardService {
ApplicationResponse<GetBoardRes> findBoard(GetBoardReq getBoardReq);

ApplicationResponse<DeleteBoardImageRes> deleteBoardImage(DeleteBoardImageReq deleteBoardImageReq);

ApplicationResponse<GetAllBoardsByCityRes> findAllBoardsByCityName(GetAllBoardsByCityReq getAllBoardsByCityReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,50 @@ public ApplicationResponse<List<List<GetAllBoardRes>>> findBoardsByCategories(Ge
return ApplicationResponse.ok(boardsByCategories);
}


@Transactional(readOnly = true)
@Override
public ApplicationResponse<GetAllBoardsByCityRes> findAllBoardsByCityName(GetAllBoardsByCityReq dto){

tokenService.validateRefreshToken(dto.getUserId(), dto.getRefreshToken());

int cursor = dto.getCursor();

User user = userRepository.findByUserId(dto.getUserId())
.orElseThrow(() -> new NotFoundUserException());

List<User> blockedUsers = blockRepository.findBlocksByBlockingUserId(dto.getUserId()).stream()
.map(block -> block.getBlockedUser())
.collect(Collectors.toList());

// jpa 다중 정렬 order
Sort sort = Sort.by(
Sort.Order.desc("id")
);
PageRequest pageRequest = PageRequest.of(cursor, PAGING_SIZE, sort);

Page<Board> boards = boardRepository.findAllBoardsByCityName(pageRequest, dto.getCityName());
// 보드 res에 이미지uuid -> aws s3 url로 변환
/*List<GetAllBoardRes> boardsRes = boards.stream()
.filter(board -> !blockedUsers.contains(board.getHost())) // 차단당한 유저의 데이터 제외
.map(board -> GetAllBoardRes.toDto(board, awsS3Service.makeUrlOfFilename(board.getBoardImagesUUids().get(0)), board.getBoardUsers().stream().map(boardUser -> awsS3Service.makeUrlOfFilename(boardUser.getUser().getProfileImg())).collect(Collectors.toList())))
.collect(Collectors.toList());*/

// 보드 res에 이미지uuid -> aws s3 url로 변환
//TODO: 동작 잘 되는지 확인
List<GetAllBoardRes> boardsRes = new ArrayList<>();
for(Board b:boards){
if(!blockedUsers.contains(b.getHost())){
// 보드 현재 인원
List<BoardUser> participantsOrigin = boardUserRepository.findAllByBoardId(b.getId());
b.changeBoardCurrentMember(participantsOrigin.size());
boardsRes.add(GetAllBoardRes.toDto(b, awsS3Service.makeUrlOfFilename(b.getBoardImagesUUids().get(0)), b.getBoardUsers().stream().filter(boardUser -> boardUser.getStatus().equals(BaseStatus.ACTIVE)).map(boardUser -> awsS3Service.makeUrlOfFilename(boardUser.getUser().getProfileImg())).collect(Collectors.toList())));
}
}

return ApplicationResponse.ok(GetAllBoardsByCityRes.toDto(boardsRes, boards.getTotalPages()));
}

@Transactional(readOnly = true)
@Override
public ApplicationResponse<GetBoardRes> findBoard(GetBoardReq dto){
Expand Down

0 comments on commit dfe0230

Please sign in to comment.