Skip to content

Commit

Permalink
#23 클립보드 단건조회(findClipBoard) Res에 유저이름, 유저프로필이미지 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Nov 8, 2022
1 parent 9267b53 commit bb7e349
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ public ApplicationResponse<GetClipBoardRes> findClipBoard(@RequestBody @Validate
}


/**
* 클립보드 전체 조회
* @author 토마스
*/
@ApiOperation(value = "클립보드 전체 조회", notes = "Board ID로 클립보드 전체 조회 요청.")
@ApiResponses({
@ApiResponse(code= 201, message = "요청에 성공하였습니다."),
@ApiResponse(code= 404, message = "존재하지 않는 유저입니다."),
@ApiResponse(code = 4000 , message = "서버 오류입니다.")
})
@PostMapping("/get/all")
public ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){
return clipBoardService.findAllClipBoards(getAllClipBoardsReq);
}
// /**
// * 클립보드 전체 조회
// * @author 토마스
// */
// @ApiOperation(value = "클립보드 전체 조회", notes = "Board ID로 클립보드 전체 조회 요청.")
// @ApiResponses({
// @ApiResponse(code= 201, message = "요청에 성공하였습니다."),
// @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."),
// @ApiResponse(code = 4000 , message = "서버 오류입니다.")
// })
// @PostMapping("/get/all")
// public ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){
// return clipBoardService.findAllClipBoards(getAllClipBoardsReq);
// }


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public class GetClipBoardRes {
@ApiParam(value = "유저 ID")
private Long userId;

@ApiModelProperty(example = "Park jun")
@ApiParam(value = "유저 이름")
private String userName;

@ApiModelProperty(example = "추가 예정")
@ApiParam(value = "유저 프로필 이미지 url")
private String profileImgUrl;

@ApiModelProperty(example = "1")
@ApiParam(value = "Board ID")
private Long boardId;
Expand Down Expand Up @@ -56,10 +64,12 @@ public class GetClipBoardRes {
@ApiParam(value = "마지막 업데이트 시각")
private String updatedAt;

public static GetClipBoardRes toDto(ClipBoard clipBoard, List<CommentRes> commentResList){
public static GetClipBoardRes toDto(ClipBoard clipBoard, List<CommentRes> commentResList, String profileImgUrl){
return GetClipBoardRes.builder()
.clipBoardId(clipBoard.getId())
.userId(clipBoard.getUser().getId())
.userName(clipBoard.getUser().getName())
.profileImgUrl(profileImgUrl)
.boardId(clipBoard.getBoard().getId())
.title(clipBoard.getTitle())
.content(clipBoard.getContent())
Expand All @@ -72,9 +82,11 @@ public static GetClipBoardRes toDto(ClipBoard clipBoard, List<CommentRes> commen
}

@Builder
public GetClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, List<CommentRes> commentResList, Integer commentCnt, BaseStatus status, String createdAt, String updatedAt) {
public GetClipBoardRes(Long clipBoardId, Long userId, String userName, String profileImgUrl, Long boardId, String title, String content, List<CommentRes> commentResList, Integer commentCnt, BaseStatus status, String createdAt, String updatedAt) {
this.clipBoardId = clipBoardId;
this.userId = userId;
this.userName = userName;
this.profileImgUrl = profileImgUrl;
this.boardId = boardId;
this.title = title;
this.content = content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ClipBoardService {

ApplicationResponse<GetClipBoardRes> findClipBoard(GetClipBoardReq getClipBoardReq);

ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq);
// ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq);

ApplicationResponse<ClipBoardRes> deleteClipBoard(DeleteClipBoardReq deleteClipBoardReq);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.yogit.server.board.repository.ClipBoardRepository;
import com.yogit.server.board.repository.CommentRepository;
import com.yogit.server.global.dto.ApplicationResponse;
import com.yogit.server.s3.AwsS3Service;
import com.yogit.server.user.entity.User;
import com.yogit.server.user.exception.NotFoundUserException;
import com.yogit.server.user.repository.UserRepository;
Expand All @@ -34,6 +35,7 @@ public class ClipBoardServiceImpl implements ClipBoardService{
private final UserRepository userRepository;
private final BoardRepository boardRepository;
private final CommentRepository commentRepository;
private final AwsS3Service awsS3Service;

@Transactional(readOnly = false)
@Override
Expand Down Expand Up @@ -70,31 +72,33 @@ public ApplicationResponse<GetClipBoardRes> findClipBoard(GetClipBoardReq dto){
.map(comment -> CommentRes.toDto(comment))
.collect(Collectors.toList());

String profileImgUrl = awsS3Service.makeUrlOfFilename(user.getProfileImg());// 유저 프로필 사진 multipart -> url 로 변환

// 코멘트 추가
GetClipBoardRes getClipBoardRes = GetClipBoardRes.toDto(clipBoard, comments);
GetClipBoardRes getClipBoardRes = GetClipBoardRes.toDto(clipBoard, comments, profileImgUrl);
return ApplicationResponse.ok(getClipBoardRes);
}


@Transactional(readOnly = true)
@Override
public ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(GetAllClipBoardsReq dto){

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

Board board = boardRepository.findBoardById(dto.getBoardId())
.orElseThrow(() -> new NotFoundBoardException());

// 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함
List<GetClipBoardRes> getClipBoardResList = clipBoardRepository.findAllByBoardId(dto.getBoardId()).stream()
.map(clipBoard -> GetClipBoardRes.toDto(clipBoard, commentRepository.findAllCommentsByClipBoardId(clipBoard.getId()).stream()
.map(comment -> CommentRes.toDto(comment))
.collect(Collectors.toList())))
.collect(Collectors.toList());

return ApplicationResponse.ok(getClipBoardResList);
}
// @Transactional(readOnly = true)
// @Override
// public ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(GetAllClipBoardsReq dto){
//
// User user = userRepository.findById(dto.getUserId())
// .orElseThrow(() -> new NotFoundUserException());
//
// Board board = boardRepository.findBoardById(dto.getBoardId())
// .orElseThrow(() -> new NotFoundBoardException());
//
// // 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함
// List<GetClipBoardRes> getClipBoardResList = clipBoardRepository.findAllByBoardId(dto.getBoardId()).stream()
// .map(clipBoard -> GetClipBoardRes.toDto(clipBoard, commentRepository.findAllCommentsByClipBoardId(clipBoard.getId()).stream()
// .map(comment -> CommentRes.toDto(comment))
// .collect(Collectors.toList())))
// .collect(Collectors.toList());
//
// return ApplicationResponse.ok(getClipBoardResList);
// }


@Transactional(readOnly = false)
Expand Down

0 comments on commit bb7e349

Please sign in to comment.