From fcb418cfc6efc39211a730a9c764fc93b85fe685 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Tue, 8 Nov 2022 01:23:16 +0900 Subject: [PATCH 1/6] =?UTF-8?q?#9=20refactor:=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EB=93=B1=EB=A1=9D=20swagger=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=84=A4=EB=AA=85=20=EB=B6=80=EB=B6=84=EC=97=90=20?= =?UTF-8?q?images=EC=97=90=EB=8C=80=ED=95=9C=20=EC=84=A4=EB=AA=85=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yogit/server/board/controller/BoardController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/yogit/server/board/controller/BoardController.java b/server/src/main/java/com/yogit/server/board/controller/BoardController.java index e377423..510ca1f 100644 --- a/server/src/main/java/com/yogit/server/board/controller/BoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/BoardController.java @@ -31,7 +31,7 @@ public class BoardController { * 게시글 등록 * @author 토마스 */ - @ApiOperation(value = "게시글 등록", notes = "그룹 게시글에 필요한 정보를 입력받아 게시글 생성.") + @ApiOperation(value = "게시글 등록", notes = "그룹 게시글에 필요한 정보를 입력받아 게시글 생성. , swagger 에서 이미지(multipartfile)처리가 잘 되지 않으므로, postman으로 테스트 바랍니다. https://solar-desert-882435.postman.co/workspace/Yogit~3e0fe8f2-15e0-41c4-9fcd-b614a975c12a/request/23528495-7fcef771-fae5-486b-a423-b47daf2d0514") @ApiResponses({ @ApiResponse(code= 201, message = "요청에 성공하였습니다."), @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), From e504ea689012b58206dbe2a7bd37e3e0b517773c Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Tue, 8 Nov 2022 17:38:04 +0900 Subject: [PATCH 2/6] =?UTF-8?q?#23=20feat:=20GetAllClipBoard=20=ED=81=B4?= =?UTF-8?q?=EB=A6=BD=EB=B3=B4=EB=93=9C=20=EC=A0=84=EC=B2=B4=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=EC=BD=94=EB=A9=98=ED=8A=B8=20=EA=B0=AF?= =?UTF-8?q?=EC=88=98=20=EA=B3=84=EC=82=B0=20API=EA=B5=AC=ED=98=84,=20fix:G?= =?UTF-8?q?etClipBoardRes=20commentCnt=ED=95=84=EB=93=9C=EA=B0=92=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/board/controller/ClipBoardController.java | 2 +- .../board/dto/response/clipboard/GetClipBoardRes.java | 9 +++++++-- .../board/service/clipboard/ClipBoardService.java | 2 +- .../board/service/clipboard/ClipBoardServiceImpl.java | 11 +++++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java index eea2686..c72de62 100644 --- a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java @@ -70,7 +70,7 @@ public ApplicationResponse findClipBoard(@RequestBody @Validate @ApiResponse(code = 4000 , message = "서버 오류입니다.") }) @PostMapping("/get/all") - public ApplicationResponse> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){ + public ApplicationResponse> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){ return clipBoardService.findAllClipBoards(getAllClipBoardsReq); } } diff --git a/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java b/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java index 559ad05..4385ec3 100644 --- a/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java +++ b/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java @@ -40,6 +40,10 @@ public class GetClipBoardRes { @ApiParam(value = "코멘트들") private List commentResList; + @ApiModelProperty(example = "2") + @ApiParam(value = "클립보드에 달린 코멘트 갯수") + private Integer commentCnt; + @ApiModelProperty(example = "ACTIVE") @ApiParam(value = "객체 상태") private BaseStatus status; @@ -60,6 +64,7 @@ public static GetClipBoardRes toDto(ClipBoard clipBoard, List commen .title(clipBoard.getTitle()) .content(clipBoard.getContent()) .commentResList(commentResList) + .commentCnt(commentResList.size()) .status(clipBoard.getStatus()) .createdAt(clipBoard.getCreatedAt()) .updatedAt(clipBoard.getUpdatedAt()) @@ -67,14 +72,14 @@ public static GetClipBoardRes toDto(ClipBoard clipBoard, List commen } @Builder - - public GetClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, List commentResList, BaseStatus status, String createdAt, String updatedAt) { + public GetClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, List commentResList, Integer commentCnt, BaseStatus status, String createdAt, String updatedAt) { this.clipBoardId = clipBoardId; this.userId = userId; this.boardId = boardId; this.title = title; this.content = content; this.commentResList = commentResList; + this.commentCnt = commentCnt; this.status = status; this.createdAt = createdAt; this.updatedAt = updatedAt; diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java index 9bce9de..f62d26c 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java @@ -15,5 +15,5 @@ public interface ClipBoardService { ApplicationResponse findClipBoard(GetClipBoardReq getClipBoardReq); - ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); + ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); } diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java index 37aa717..a9af588 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java @@ -79,7 +79,7 @@ public ApplicationResponse findClipBoard(GetClipBoardReq dto){ @Transactional(readOnly = true) @Override - public ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq dto){ + public ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq dto){ User user = userRepository.findById(dto.getUserId()) .orElseThrow(() -> new NotFoundUserException()); @@ -87,10 +87,13 @@ public ApplicationResponse> findAllClipBoards(GetAllClipBoard Board board = boardRepository.findBoardById(dto.getBoardId()) .orElseThrow(() -> new NotFoundBoardException()); - List clipBoardResList = clipBoardRepository.findAllByBoardId(dto.getBoardId()).stream() - .map(clipBoard -> ClipBoardRes.toDto(clipBoard)) + // 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함 + List 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(clipBoardResList); + return ApplicationResponse.ok(getClipBoardResList); } } From 31ac457fc01a67ee2284d80685b1ad9ef8fefb8c Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Tue, 8 Nov 2022 18:07:56 +0900 Subject: [PATCH 3/6] =?UTF-8?q?#23=20=ED=81=B4=EB=A6=BD=EB=B3=B4=EB=93=9C?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9CAPI=EA=B5=AC=ED=98=84(deleteClipBoard)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/ClipBoardController.java | 22 +++++++++++++++---- .../request/clipboard/DeleteClipBoardReq.java | 19 ++++++++++++++++ .../yogit/server/board/entity/ClipBoard.java | 8 +++++++ .../clipboard/ClipBoardExceptionList.java | 3 ++- .../NotUserOfClipBoardException.java | 8 +++++++ .../service/clipboard/ClipBoardService.java | 3 +++ .../clipboard/ClipBoardServiceImpl.java | 22 +++++++++++++++++++ 7 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 server/src/main/java/com/yogit/server/board/dto/request/clipboard/DeleteClipBoardReq.java create mode 100644 server/src/main/java/com/yogit/server/board/exception/clipboard/NotUserOfClipBoardException.java diff --git a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java index c72de62..aa87f9d 100644 --- a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java @@ -1,6 +1,7 @@ package com.yogit.server.board.controller; import com.yogit.server.board.dto.request.clipboard.CreateClipBoardReq; +import com.yogit.server.board.dto.request.clipboard.DeleteClipBoardReq; import com.yogit.server.board.dto.request.clipboard.GetAllClipBoardsReq; import com.yogit.server.board.dto.request.clipboard.GetClipBoardReq; import com.yogit.server.board.dto.response.clipboard.ClipBoardRes; @@ -13,10 +14,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -73,4 +71,20 @@ public ApplicationResponse findClipBoard(@RequestBody @Validate public ApplicationResponse> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){ return clipBoardService.findAllClipBoards(getAllClipBoardsReq); } + + + /** + * 클립보드 삭제 + * @author 토마스 + */ + @ApiOperation(value = "클립보드 삭제", notes = "클립보드 ID로 클립보드 삭제 요청.") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @PatchMapping("/{clipBoardId}/status") + public ApplicationResponse deleteClipBoard(@PathVariable("clipBoardId") Long clipBoardId, @RequestBody @Validated DeleteClipBoardReq deleteClipBoardReq){ + return clipBoardService.deleteClipBoard(deleteClipBoardReq); + } } diff --git a/server/src/main/java/com/yogit/server/board/dto/request/clipboard/DeleteClipBoardReq.java b/server/src/main/java/com/yogit/server/board/dto/request/clipboard/DeleteClipBoardReq.java new file mode 100644 index 0000000..c7ede80 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/request/clipboard/DeleteClipBoardReq.java @@ -0,0 +1,19 @@ +package com.yogit.server.board.dto.request.clipboard; + +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class DeleteClipBoardReq { + + @ApiModelProperty(example = "1") + @ApiParam(value = "유저 ID", required = true) + private Long userId; + + @ApiModelProperty(example = "1") + @ApiParam(value = "clipBoard ID", required = true) + private Long clipBoardId; +} diff --git a/server/src/main/java/com/yogit/server/board/entity/ClipBoard.java b/server/src/main/java/com/yogit/server/board/entity/ClipBoard.java index 3995a42..3a9f55b 100644 --- a/server/src/main/java/com/yogit/server/board/entity/ClipBoard.java +++ b/server/src/main/java/com/yogit/server/board/entity/ClipBoard.java @@ -2,6 +2,7 @@ import com.yogit.server.board.dto.request.clipboard.CreateClipBoardReq; import com.yogit.server.config.domain.BaseEntity; +import com.yogit.server.config.domain.BaseStatus; import com.yogit.server.user.entity.User; import lombok.AccessLevel; import lombok.Builder; @@ -41,4 +42,11 @@ public ClipBoard(CreateClipBoardReq dto, User user, Board board) { this.title = dto.getTitle(); this.content = dto.getContent(); } + + /* + 연관관계 편의 메서드 + */ + public void deleteClipBoard(){ + this.setStatus(BaseStatus.INACTIVE); + } } diff --git a/server/src/main/java/com/yogit/server/board/exception/clipboard/ClipBoardExceptionList.java b/server/src/main/java/com/yogit/server/board/exception/clipboard/ClipBoardExceptionList.java index dad5f8d..a2ff93c 100644 --- a/server/src/main/java/com/yogit/server/board/exception/clipboard/ClipBoardExceptionList.java +++ b/server/src/main/java/com/yogit/server/board/exception/clipboard/ClipBoardExceptionList.java @@ -10,7 +10,8 @@ @RequiredArgsConstructor public enum ClipBoardExceptionList { - NOT_FOUND_CLIP_BOARD("CB0001", NOT_FOUND, "존재하지 않는 ClipBoard아이디입니다."); + NOT_FOUND_CLIP_BOARD("CB0001", NOT_FOUND, "존재하지 않는 ClipBoard아이디입니다."), + NOT_USER_OF_CLIPBOARD("CB0002", HttpStatus.BAD_REQUEST, "요청한 유저가 클립보드의 호스트가 아닙니다."); private final String CODE; private final HttpStatus HTTPSTATUS; diff --git a/server/src/main/java/com/yogit/server/board/exception/clipboard/NotUserOfClipBoardException.java b/server/src/main/java/com/yogit/server/board/exception/clipboard/NotUserOfClipBoardException.java new file mode 100644 index 0000000..2791f81 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/exception/clipboard/NotUserOfClipBoardException.java @@ -0,0 +1,8 @@ +package com.yogit.server.board.exception.clipboard; + +public class NotUserOfClipBoardException extends ClipBoardException{ + public NotUserOfClipBoardException(){ + super(ClipBoardExceptionList.NOT_USER_OF_CLIPBOARD.getCODE(), ClipBoardExceptionList.NOT_USER_OF_CLIPBOARD.getHTTPSTATUS(), ClipBoardExceptionList.NOT_USER_OF_CLIPBOARD.getMESSAGE()); + } + +} diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java index f62d26c..0053177 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java @@ -1,6 +1,7 @@ package com.yogit.server.board.service.clipboard; import com.yogit.server.board.dto.request.clipboard.CreateClipBoardReq; +import com.yogit.server.board.dto.request.clipboard.DeleteClipBoardReq; import com.yogit.server.board.dto.request.clipboard.GetAllClipBoardsReq; import com.yogit.server.board.dto.request.clipboard.GetClipBoardReq; import com.yogit.server.board.dto.response.clipboard.ClipBoardRes; @@ -16,4 +17,6 @@ public interface ClipBoardService { ApplicationResponse findClipBoard(GetClipBoardReq getClipBoardReq); ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); + + ApplicationResponse deleteClipBoard(DeleteClipBoardReq deleteClipBoardReq); } diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java index a9af588..4004e9a 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java @@ -1,6 +1,7 @@ package com.yogit.server.board.service.clipboard; import com.yogit.server.board.dto.request.clipboard.CreateClipBoardReq; +import com.yogit.server.board.dto.request.clipboard.DeleteClipBoardReq; import com.yogit.server.board.dto.request.clipboard.GetAllClipBoardsReq; import com.yogit.server.board.dto.request.clipboard.GetClipBoardReq; import com.yogit.server.board.dto.response.clipboard.ClipBoardRes; @@ -11,6 +12,7 @@ import com.yogit.server.board.entity.Comment; import com.yogit.server.board.exception.NotFoundBoardException; import com.yogit.server.board.exception.clipboard.NotFoundClipBoardException; +import com.yogit.server.board.exception.clipboard.NotUserOfClipBoardException; import com.yogit.server.board.exception.comment.NotFoundCommentException; import com.yogit.server.board.repository.BoardRepository; import com.yogit.server.board.repository.ClipBoardRepository; @@ -96,4 +98,24 @@ public ApplicationResponse> findAllClipBoards(GetAllClipBo return ApplicationResponse.ok(getClipBoardResList); } + + + @Transactional(readOnly = false) + @Override + public ApplicationResponse deleteClipBoard(DeleteClipBoardReq dto){ + User user = userRepository.findById(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + ClipBoard clipBoard = clipBoardRepository.findClipBoardById(dto.getClipBoardId()) + .orElseThrow(() -> new NotFoundClipBoardException()); + + //Validation: 요청 사용자와 클립보드 생성자가 같은지 검증 + if(!user.getId().equals(clipBoard.getUser().getId())){ + throw new NotUserOfClipBoardException(); + } + + clipBoard.deleteClipBoard();// 삭제 + ClipBoardRes clipBoardRes = ClipBoardRes.toDto(clipBoard); + return ApplicationResponse.ok(clipBoardRes); + } } From 9267b535630d000c6597bdfe987da25de7a9717d Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Tue, 8 Nov 2022 20:30:09 +0900 Subject: [PATCH 4/6] =?UTF-8?q?#23=20=ED=81=B4=EB=A6=BD=EB=B3=B4=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20API=EA=B5=AC=ED=98=84(updateClipBoard)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/ClipBoardController.java | 22 ++++++++++--- .../request/clipboard/PatchClipBoardReq.java | 31 +++++++++++++++++++ .../yogit/server/board/entity/ClipBoard.java | 6 ++++ .../service/clipboard/ClipBoardService.java | 7 ++--- .../clipboard/ClipBoardServiceImpl.java | 25 ++++++++++++--- 5 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 server/src/main/java/com/yogit/server/board/dto/request/clipboard/PatchClipBoardReq.java diff --git a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java index aa87f9d..a1238ca 100644 --- a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java @@ -1,9 +1,6 @@ package com.yogit.server.board.controller; -import com.yogit.server.board.dto.request.clipboard.CreateClipBoardReq; -import com.yogit.server.board.dto.request.clipboard.DeleteClipBoardReq; -import com.yogit.server.board.dto.request.clipboard.GetAllClipBoardsReq; -import com.yogit.server.board.dto.request.clipboard.GetClipBoardReq; +import com.yogit.server.board.dto.request.clipboard.*; import com.yogit.server.board.dto.response.clipboard.ClipBoardRes; import com.yogit.server.board.dto.response.clipboard.GetClipBoardRes; import com.yogit.server.board.service.clipboard.ClipBoardService; @@ -73,6 +70,23 @@ public ApplicationResponse> findAllClipBoards(@RequestBody } + /** + * 클립보드 수정 + * @author 토마스 + */ + @ApiOperation(value = "클립보드 수정", notes = "클립보드 ID, title, content로 클립보드 수정 요청.") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code= 404, message = "존재하지 않는 클립보드입니다."), + @ApiResponse(code= 404, message = "요청한 유저가 클립보드의 호스트가 아닙니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @PatchMapping("/{clipBoardId}") + public ApplicationResponse updateClipBoard(@PathVariable("clipBoardId") Long clipBoardid, @RequestBody @Validated PatchClipBoardReq patchClipBoardReq){ + return clipBoardService.updateClipBoard(patchClipBoardReq); + } + /** * 클립보드 삭제 * @author 토마스 diff --git a/server/src/main/java/com/yogit/server/board/dto/request/clipboard/PatchClipBoardReq.java b/server/src/main/java/com/yogit/server/board/dto/request/clipboard/PatchClipBoardReq.java new file mode 100644 index 0000000..acbf4f6 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/request/clipboard/PatchClipBoardReq.java @@ -0,0 +1,31 @@ +package com.yogit.server.board.dto.request.clipboard; + +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@Data +@NoArgsConstructor +public class PatchClipBoardReq { + + @ApiModelProperty(example = "1") + @ApiParam(value = "유저 ID", required = true) + private Long userId; + + @ApiModelProperty(example = "1") + @ApiParam(value = "clipBoard ID", required = true) + private Long clipBoardId; + + @ApiModelProperty(example = "질문이 있습니다.") + @ApiParam(value = "클립보드 제목", required = true) + @NotBlank + private String title; + + @ApiModelProperty(example = "경복궁역 몇 번 출구인가요?") + @ApiParam(value = "클립보드 상세 내용", required = false) + @NotBlank + private String content; +} diff --git a/server/src/main/java/com/yogit/server/board/entity/ClipBoard.java b/server/src/main/java/com/yogit/server/board/entity/ClipBoard.java index 3a9f55b..ef12b91 100644 --- a/server/src/main/java/com/yogit/server/board/entity/ClipBoard.java +++ b/server/src/main/java/com/yogit/server/board/entity/ClipBoard.java @@ -1,6 +1,7 @@ package com.yogit.server.board.entity; import com.yogit.server.board.dto.request.clipboard.CreateClipBoardReq; +import com.yogit.server.board.dto.request.clipboard.PatchClipBoardReq; import com.yogit.server.config.domain.BaseEntity; import com.yogit.server.config.domain.BaseStatus; import com.yogit.server.user.entity.User; @@ -49,4 +50,9 @@ public ClipBoard(CreateClipBoardReq dto, User user, Board board) { public void deleteClipBoard(){ this.setStatus(BaseStatus.INACTIVE); } + + public void updateClipBoard(PatchClipBoardReq dto){ + this.title = dto.getTitle(); + this.content = dto.getContent(); + } } diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java index 0053177..4d3c003 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java @@ -1,9 +1,6 @@ package com.yogit.server.board.service.clipboard; -import com.yogit.server.board.dto.request.clipboard.CreateClipBoardReq; -import com.yogit.server.board.dto.request.clipboard.DeleteClipBoardReq; -import com.yogit.server.board.dto.request.clipboard.GetAllClipBoardsReq; -import com.yogit.server.board.dto.request.clipboard.GetClipBoardReq; +import com.yogit.server.board.dto.request.clipboard.*; import com.yogit.server.board.dto.response.clipboard.ClipBoardRes; import com.yogit.server.board.dto.response.clipboard.GetClipBoardRes; import com.yogit.server.global.dto.ApplicationResponse; @@ -19,4 +16,6 @@ public interface ClipBoardService { ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); ApplicationResponse deleteClipBoard(DeleteClipBoardReq deleteClipBoardReq); + + ApplicationResponse updateClipBoard(PatchClipBoardReq patchClipBoardReq); } diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java index 4004e9a..8dc4431 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java @@ -1,9 +1,6 @@ package com.yogit.server.board.service.clipboard; -import com.yogit.server.board.dto.request.clipboard.CreateClipBoardReq; -import com.yogit.server.board.dto.request.clipboard.DeleteClipBoardReq; -import com.yogit.server.board.dto.request.clipboard.GetAllClipBoardsReq; -import com.yogit.server.board.dto.request.clipboard.GetClipBoardReq; +import com.yogit.server.board.dto.request.clipboard.*; import com.yogit.server.board.dto.response.clipboard.ClipBoardRes; import com.yogit.server.board.dto.response.clipboard.GetClipBoardRes; import com.yogit.server.board.dto.response.comment.CommentRes; @@ -100,6 +97,26 @@ public ApplicationResponse> findAllClipBoards(GetAllClipBo } + @Transactional(readOnly = false) + @Override + public ApplicationResponse updateClipBoard(PatchClipBoardReq dto){ + //필요 객체 조회 + User user = userRepository.findById(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + ClipBoard clipBoard = clipBoardRepository.findClipBoardById(dto.getClipBoardId()) + .orElseThrow(() -> new NotFoundClipBoardException()); + + //Validation: 요청 사용자와 클립보드 생성자가 같은지 검증 + if(!user.getId().equals(clipBoard.getUser().getId())){ + throw new NotUserOfClipBoardException(); + } + + clipBoard.updateClipBoard(dto); // 업데이트 + ClipBoardRes clipBoardRes = ClipBoardRes.toDto(clipBoard); + return ApplicationResponse.ok(clipBoardRes); + } + @Transactional(readOnly = false) @Override public ApplicationResponse deleteClipBoard(DeleteClipBoardReq dto){ From bb7e349ecc9afcdfb42223f0a3d455afbb1807ac Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Tue, 8 Nov 2022 21:11:08 +0900 Subject: [PATCH 5/6] =?UTF-8?q?#23=20=ED=81=B4=EB=A6=BD=EB=B3=B4=EB=93=9C?= =?UTF-8?q?=20=EB=8B=A8=EA=B1=B4=EC=A1=B0=ED=9A=8C(findClipBoard)=20Res?= =?UTF-8?q?=EC=97=90=20=EC=9C=A0=EC=A0=80=EC=9D=B4=EB=A6=84,=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=ED=94=84=EB=A1=9C=ED=95=84=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/ClipBoardController.java | 28 ++++++------ .../response/clipboard/GetClipBoardRes.java | 16 ++++++- .../service/clipboard/ClipBoardService.java | 2 +- .../clipboard/ClipBoardServiceImpl.java | 44 ++++++++++--------- 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java index a1238ca..0d133c6 100644 --- a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java @@ -54,20 +54,20 @@ public ApplicationResponse 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> 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> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){ +// return clipBoardService.findAllClipBoards(getAllClipBoardsReq); +// } /** diff --git a/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java b/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java index 4385ec3..cc1a0ad 100644 --- a/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java +++ b/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java @@ -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; @@ -56,10 +64,12 @@ public class GetClipBoardRes { @ApiParam(value = "마지막 업데이트 시각") private String updatedAt; - public static GetClipBoardRes toDto(ClipBoard clipBoard, List commentResList){ + public static GetClipBoardRes toDto(ClipBoard clipBoard, List 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()) @@ -72,9 +82,11 @@ public static GetClipBoardRes toDto(ClipBoard clipBoard, List commen } @Builder - public GetClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, List 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 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; diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java index 4d3c003..a87d36f 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java @@ -13,7 +13,7 @@ public interface ClipBoardService { ApplicationResponse findClipBoard(GetClipBoardReq getClipBoardReq); - ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); +// ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); ApplicationResponse deleteClipBoard(DeleteClipBoardReq deleteClipBoardReq); diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java index 8dc4431..3f2f6f7 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java @@ -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; @@ -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 @@ -70,31 +72,33 @@ public ApplicationResponse 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> findAllClipBoards(GetAllClipBoardsReq dto){ - - User user = userRepository.findById(dto.getUserId()) - .orElseThrow(() -> new NotFoundUserException()); - - Board board = boardRepository.findBoardById(dto.getBoardId()) - .orElseThrow(() -> new NotFoundBoardException()); - - // 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함 - List 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> findAllClipBoards(GetAllClipBoardsReq dto){ +// +// User user = userRepository.findById(dto.getUserId()) +// .orElseThrow(() -> new NotFoundUserException()); +// +// Board board = boardRepository.findBoardById(dto.getBoardId()) +// .orElseThrow(() -> new NotFoundBoardException()); +// +// // 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함 +// List 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) From 2fc56fd89b44d52e3591141bbbea2ee07ccd7d7d Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Tue, 8 Nov 2022 21:22:52 +0900 Subject: [PATCH 6/6] =?UTF-8?q?#23=20feat:=ED=81=B4=EB=A6=BD=EB=B3=B4?= =?UTF-8?q?=EB=93=9C=20=EC=A0=84=EC=B2=B4=EC=A1=B0=ED=9A=8C(findAllClipBoa?= =?UTF-8?q?rds)=20Res=EC=97=90=20userName,=20profileImgUrl=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EA=B0=92=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/ClipBoardController.java | 28 ++++++------- .../service/clipboard/ClipBoardService.java | 2 +- .../clipboard/ClipBoardServiceImpl.java | 40 ++++++++++--------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java index 0d133c6..a1238ca 100644 --- a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java @@ -54,20 +54,20 @@ public ApplicationResponse 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> 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> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){ + return clipBoardService.findAllClipBoards(getAllClipBoardsReq); + } /** diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java index a87d36f..4d3c003 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java @@ -13,7 +13,7 @@ public interface ClipBoardService { ApplicationResponse findClipBoard(GetClipBoardReq getClipBoardReq); -// ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); + ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); ApplicationResponse deleteClipBoard(DeleteClipBoardReq deleteClipBoardReq); diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java index 3f2f6f7..36b4452 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java @@ -80,25 +80,27 @@ public ApplicationResponse findClipBoard(GetClipBoardReq dto){ } -// @Transactional(readOnly = true) -// @Override -// public ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq dto){ -// -// User user = userRepository.findById(dto.getUserId()) -// .orElseThrow(() -> new NotFoundUserException()); -// -// Board board = boardRepository.findBoardById(dto.getBoardId()) -// .orElseThrow(() -> new NotFoundBoardException()); -// -// // 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함 -// List 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> findAllClipBoards(GetAllClipBoardsReq dto){ + + User user = userRepository.findById(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + Board board = boardRepository.findBoardById(dto.getBoardId()) + .orElseThrow(() -> new NotFoundBoardException()); + + // 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함 + // 유저 profileImgUrl 또한 img uuid -> s3 url로 변환 + List getClipBoardResList = clipBoardRepository.findAllByBoardId(dto.getBoardId()).stream() + .map(clipBoard -> GetClipBoardRes.toDto(clipBoard, commentRepository.findAllCommentsByClipBoardId(clipBoard.getId()).stream() + .map(comment -> CommentRes.toDto(comment)) + .collect(Collectors.toList()), + awsS3Service.makeUrlOfFilename(clipBoard.getUser().getProfileImg()))) + .collect(Collectors.toList()); + + return ApplicationResponse.ok(getClipBoardResList); + } @Transactional(readOnly = false)