Skip to content

Commit

Permalink
#23 refactor: createClipBoard, updateClipBoard의 res 필드를 클립 보드 조회res와 …
Browse files Browse the repository at this point in the history
…같게 수정
  • Loading branch information
xhaktmchl committed Dec 8, 2022
1 parent f349382 commit ee237de
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public ApplicationResponse<ClipBoardRes> updateClipBoard(@PathVariable("clipBoar
@ApiResponse(code = 4000 , message = "서버 오류입니다.")
})
@PatchMapping("/{clipBoardId}/status")
public ApplicationResponse<ClipBoardRes> deleteClipBoard(@PathVariable("clipBoardId") Long clipBoardId, @RequestBody @Validated DeleteClipBoardReq deleteClipBoardReq){
public ApplicationResponse<String> deleteClipBoard(@PathVariable("clipBoardId") Long clipBoardId, @RequestBody @Validated DeleteClipBoardReq deleteClipBoardReq){
return clipBoardService.deleteClipBoard(deleteClipBoardReq);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yogit.server.board.dto.response.clipboard;


import com.yogit.server.board.dto.response.comment.CommentRes;
import com.yogit.server.board.entity.ClipBoard;
import com.yogit.server.config.domain.BaseStatus;
import io.swagger.annotations.ApiModelProperty;
Expand All @@ -9,6 +10,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
public class ClipBoardRes {
Expand All @@ -21,6 +24,14 @@ public class ClipBoardRes {
@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 All @@ -33,6 +44,14 @@ public class ClipBoardRes {
@ApiParam(value = "클립보드 상세 내용")
private String content;

@ApiModelProperty(example = "댓글1")
@ApiParam(value = "코멘트들")
private List<CommentRes> commentResList;

@ApiModelProperty(example = "2")
@ApiParam(value = "클립보드에 달린 코멘트 갯수")
private Integer commentCnt;

@ApiModelProperty(example = "ACTIVE")
@ApiParam(value = "객체 상태")
private BaseStatus status;
Expand All @@ -45,26 +64,34 @@ public class ClipBoardRes {
@ApiParam(value = "마지막 업데이트 시각")
private String updatedAt;

public static ClipBoardRes toDto(ClipBoard clipBoard){
public static ClipBoardRes toDto(ClipBoard clipBoard, List<CommentRes> commentResList, String profileImgUrl){
return ClipBoardRes.builder()
.clipBoardId(clipBoard.getId())
.userId(clipBoard.getUser().getId())
.userName(clipBoard.getUser().getName())
.profileImgUrl(profileImgUrl)
.boardId(clipBoard.getBoard().getId())
// .title(clipBoard.getTitle())
.title(clipBoard.getTitle())
.content(clipBoard.getContent())
.commentResList(commentResList)
.commentCnt(commentResList.size())
.status(clipBoard.getStatus())
.createdAt(clipBoard.getCreatedAt())
.updatedAt(clipBoard.getUpdatedAt())
.build();
}

@Builder
public ClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, BaseStatus status, String createdAt, String updatedAt) {
public ClipBoardRes(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;
this.commentResList = commentResList;
this.commentCnt = commentCnt;
this.status = status;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ClipBoardService {

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

ApplicationResponse<ClipBoardRes> deleteClipBoard(DeleteClipBoardReq deleteClipBoardReq);
ApplicationResponse<String> deleteClipBoard(DeleteClipBoardReq deleteClipBoardReq);

ApplicationResponse<ClipBoardRes> updateClipBoard(PatchClipBoardReq patchClipBoardReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ public ApplicationResponse<ClipBoardRes> createClipBoard(CreateClipBoardReq dto)
// ClipBoard객체 생성
ClipBoard clipBoard = new ClipBoard(dto, user, board);
ClipBoard savedClipBoard = clipBoardRepository.save(clipBoard); // 생성 요청
ClipBoardRes clipBoardRes = ClipBoardRes.toDto(savedClipBoard);// resDto로 변환
return ApplicationResponse.create("클립보드 생성에 성공하였습니다.", clipBoardRes);

List<CommentRes> comments = commentRepository.findAllCommentsByClipBoardId(clipBoard.getId()).stream()
.map(comment -> CommentRes.toDto(comment))
.collect(Collectors.toList());

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

ClipBoardRes res = ClipBoardRes.toDto(savedClipBoard, comments, profileImgUrl);// resDto로 변환
return ApplicationResponse.create("클립보드 생성에 성공하였습니다.", res);
}


Expand Down Expand Up @@ -175,13 +182,20 @@ public ApplicationResponse<ClipBoardRes> updateClipBoard(PatchClipBoardReq dto){
}

clipBoard.updateClipBoard(dto); // 업데이트
ClipBoardRes clipBoardRes = ClipBoardRes.toDto(clipBoard);

List<CommentRes> comments = commentRepository.findAllCommentsByClipBoardId(clipBoard.getId()).stream()
.map(comment -> CommentRes.toDto(comment))
.collect(Collectors.toList());

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

ClipBoardRes clipBoardRes = ClipBoardRes.toDto(clipBoard, comments, profileImgUrl);
return ApplicationResponse.ok(clipBoardRes);
}

@Transactional(readOnly = false)
@Override
public ApplicationResponse<ClipBoardRes> deleteClipBoard(DeleteClipBoardReq dto){
public ApplicationResponse<String> deleteClipBoard(DeleteClipBoardReq dto){

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

Expand All @@ -197,7 +211,7 @@ public ApplicationResponse<ClipBoardRes> deleteClipBoard(DeleteClipBoardReq dto)
}

clipBoard.deleteClipBoard();// 삭제
ClipBoardRes clipBoardRes = ClipBoardRes.toDto(clipBoard);
return ApplicationResponse.ok(clipBoardRes);
// ClipBoardRes clipBoardRes = ClipBoardRes.toDto(clipBoard);
return ApplicationResponse.ok("클립 보드가 삭제되었습니다.");
}
}

0 comments on commit ee237de

Please sign in to comment.