From 5c3c569aab27ec095f7e4fe6ab0e7b7edf457ee7 Mon Sep 17 00:00:00 2001 From: shinhn Date: Tue, 29 Nov 2022 23:11:30 +0900 Subject: [PATCH] =?UTF-8?q?#65=20feat:=20Board=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=A9=A4=EB=B2=84=20=EC=82=AD=EC=A0=9C=20(=EB=B3=B4=EB=93=9C?= =?UTF-8?q?=20=EB=AA=A8=EC=9E=84=20=ED=83=88=ED=87=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardUserController.java | 21 ++++++++++++++---- .../request/boarduser/DelBoardUserReq.java | 18 +++++++++++++++ .../board/exception/BoardExceptionList.java | 3 ++- .../board/exception/NotFoundUserBoard.java | 9 ++++++++ .../service/boarduser/BoardUserService.java | 2 ++ .../boarduser/BoardUserServiceImpl.java | 22 +++++++++++++++++++ 6 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 server/src/main/java/com/yogit/server/board/dto/request/boarduser/DelBoardUserReq.java create mode 100644 server/src/main/java/com/yogit/server/board/exception/NotFoundUserBoard.java diff --git a/server/src/main/java/com/yogit/server/board/controller/BoardUserController.java b/server/src/main/java/com/yogit/server/board/controller/BoardUserController.java index 2a721d4..da69657 100644 --- a/server/src/main/java/com/yogit/server/board/controller/BoardUserController.java +++ b/server/src/main/java/com/yogit/server/board/controller/BoardUserController.java @@ -10,10 +10,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.*; @Slf4j @RestController @@ -38,4 +35,20 @@ public class BoardUserController { public ApplicationResponse joinBoardUser(@RequestBody @Validated CreateBoardUserReq dto){ return boardUserService.joinBoardUser(dto); } + + /** + * 보드 멤버 제거 + * @author peanut + */ + @ApiOperation(value = "보드 멤버 제거", notes = "보드 모임 탈퇴 요청") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code= 404, message = "존재하지 않는 Board아이디입니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @PatchMapping + public ApplicationResponse delBoardUser(@RequestBody @Validated CreateBoardUserReq dto){ + return boardUserService.delBoardUser(dto); + } } diff --git a/server/src/main/java/com/yogit/server/board/dto/request/boarduser/DelBoardUserReq.java b/server/src/main/java/com/yogit/server/board/dto/request/boarduser/DelBoardUserReq.java new file mode 100644 index 0000000..23f05dc --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/request/boarduser/DelBoardUserReq.java @@ -0,0 +1,18 @@ +package com.yogit.server.board.dto.request.boarduser; + +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class DelBoardUserReq { + @ApiModelProperty(example = "1") + @ApiParam(value = "userId,유저 PK", required = true) + private Long userId; + + @ApiModelProperty(example = "1") + @ApiParam(value = "boardId, 보드 PK", required = true) + private Long boardId; +} diff --git a/server/src/main/java/com/yogit/server/board/exception/BoardExceptionList.java b/server/src/main/java/com/yogit/server/board/exception/BoardExceptionList.java index 660e2de..102d272 100644 --- a/server/src/main/java/com/yogit/server/board/exception/BoardExceptionList.java +++ b/server/src/main/java/com/yogit/server/board/exception/BoardExceptionList.java @@ -13,7 +13,8 @@ public enum BoardExceptionList { NOT_FOUND_BOARD("B0001", NOT_FOUND,"존재하지 않는 Board아이디입니다."), NOT_HOST_OF_BOARD("B0002",HttpStatus.BAD_REQUEST, "요청한 유저가 호스트가 아닙니다."), MAX_BOARD_USER("B003", HttpStatus.BAD_REQUEST, "보드 인원이 다 찼습니다."), - DUPLICATED_BOARD_USER("B004", HttpStatus.BAD_REQUEST, "이미 보드에 참여했습니다."); + DUPLICATED_BOARD_USER("B004", HttpStatus.BAD_REQUEST, "이미 보드에 참여했습니다."), + NOT_FOUND_USER_BOARD("B005", NOT_FOUND, "보드에 가입된 인원이 아닙니다."); private final String CODE; private final HttpStatus HTTPSTATUS; diff --git a/server/src/main/java/com/yogit/server/board/exception/NotFoundUserBoard.java b/server/src/main/java/com/yogit/server/board/exception/NotFoundUserBoard.java new file mode 100644 index 0000000..5a8a9f4 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/exception/NotFoundUserBoard.java @@ -0,0 +1,9 @@ +package com.yogit.server.board.exception; + +import static com.yogit.server.board.exception.BoardExceptionList.NOT_FOUND_USER_BOARD; + +public class NotFoundUserBoard extends BoardException { + public NotFoundUserBoard(){ + super(NOT_FOUND_USER_BOARD.getCODE(), NOT_FOUND_USER_BOARD.getHTTPSTATUS(), NOT_FOUND_USER_BOARD.getMESSAGE()); + } +} diff --git a/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserService.java b/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserService.java index bbe6314..66cd1a9 100644 --- a/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserService.java +++ b/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserService.java @@ -7,4 +7,6 @@ public interface BoardUserService { ApplicationResponse joinBoardUser(CreateBoardUserReq createBoardUserReq); + + ApplicationResponse delBoardUser(CreateBoardUserReq createBoardUserReq); } diff --git a/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserServiceImpl.java index 11ad8f5..a592fea 100644 --- a/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserServiceImpl.java @@ -7,6 +7,7 @@ import com.yogit.server.board.exception.DuplicatedBoardUserException; import com.yogit.server.board.exception.MaxBoardUserException; import com.yogit.server.board.exception.NotFoundBoardException; +import com.yogit.server.board.exception.NotFoundUserBoard; import com.yogit.server.board.repository.BoardRepository; import com.yogit.server.board.repository.BoardUserRepository; import com.yogit.server.global.dto.ApplicationResponse; @@ -17,6 +18,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Optional; + @Service @Transactional(readOnly = true) @RequiredArgsConstructor @@ -55,4 +58,23 @@ public ApplicationResponse joinBoardUser(CreateBoardUserReq dto) { BoardUserRes res = BoardUserRes.toDto(boardUser,user, board); return ApplicationResponse.create("보드에 유저가 조인되었습니다.", res); } + + @Transactional + @Override + public ApplicationResponse delBoardUser(CreateBoardUserReq createBoardUserReq){ + + User user = userRepository.findById(createBoardUserReq.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + Board board = boardRepository.findBoardById(createBoardUserReq.getBoardId()) + .orElseThrow(() -> new NotFoundBoardException()); + + Optional boardUser = boardUserRepository.findByUserIdAndBoardId(createBoardUserReq.getUserId(), createBoardUserReq.getBoardId()); + + if(!boardUser.isPresent()) throw new NotFoundUserBoard(); + + boardUserRepository.deleteById(boardUser.get().getId()); + + return ApplicationResponse.ok(); + } }