From 7ab1b51b4d5fb8378e1d00b7a57b271d683ae3af Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Thu, 26 Jan 2023 21:32:55 +0900 Subject: [PATCH] =?UTF-8?q?#65=20feat:=20=EB=B3=B4=EB=93=9C=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=8A=B9=EC=9D=B8API(approveBoardUser)-=ED=98=B8?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EA=B0=80=20=EC=8B=A0=EC=B2=AD=EC=9E=90=20?= =?UTF-8?q?=EC=8A=B9=EC=9D=B8,=20fix:=EB=B3=B4=EB=93=9C=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=ED=95=A0=EB=95=8C=20=EC=8A=B9=EC=9D=B8?= =?UTF-8?q?=EB=90=9C=20=EC=82=AC=EB=9E=8C=EB=A7=8C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardUserController.java | 17 +++++++ .../yogit/server/board/entity/BoardUser.java | 7 +++ .../service/boarduser/BoardUserService.java | 2 + .../boarduser/BoardUserServiceImpl.java | 49 +++++++++++++++++-- 4 files changed, 72 insertions(+), 3 deletions(-) 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 da69657..213db55 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 @@ -36,6 +36,23 @@ public ApplicationResponse joinBoardUser(@RequestBody @Validated C return boardUserService.joinBoardUser(dto); } + + /** + * 보드 멤버 입장 승인 + * @author 토마스 + */ + @ApiOperation(value = "호스트가 보드 멤버 입장 승인", notes = "호스트가 보드 모임 가입 신청 수락, applyStatus를 변경") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code= 404, message = "존재하지 않는 Board아이디입니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @PostMapping + public ApplicationResponse approveBoardUser(@RequestBody @Validated CreateBoardUserReq dto){ + return boardUserService.approveBoardUser(dto); + } + /** * 보드 멤버 제거 * @author peanut diff --git a/server/src/main/java/com/yogit/server/board/entity/BoardUser.java b/server/src/main/java/com/yogit/server/board/entity/BoardUser.java index 239dc00..08f7237 100644 --- a/server/src/main/java/com/yogit/server/board/entity/BoardUser.java +++ b/server/src/main/java/com/yogit/server/board/entity/BoardUser.java @@ -25,6 +25,8 @@ public class BoardUser extends BaseEntity { @JoinColumn(name = "board_id") private Board board; + private Integer applyStatus; // 승인 전=0, 승인 됨=1 + /* 연관관계 편의 메서드 */ @@ -33,5 +35,10 @@ public BoardUser(User user, Board board) { this.user = user; this.board = board; // board.addBoardUser(this); + this.applyStatus = 0; + } + + public void changeApplyStatus(){ + this.applyStatus = 1; } } 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 66cd1a9..fcf0545 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 @@ -8,5 +8,7 @@ public interface BoardUserService { ApplicationResponse joinBoardUser(CreateBoardUserReq createBoardUserReq); + ApplicationResponse approveBoardUser(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 124566d..433541f 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 @@ -65,16 +65,18 @@ public ApplicationResponse joinBoardUser(CreateBoardUserReq dto) { BoardUser boardUser = new BoardUser(user, board); BoardUser savedBoardUser = boardUserRepository.save(boardUser); - board.addCurrentMember();// 보드 현재 인원 +1 + //board.addCurrentMember();// 보드 현재 인원 +1 board.addBoardUser(boardUser); // 보드에 멤버 추가 List participants = board.getBoardUsers().stream() - .filter(bu -> !bu.getUser().equals(board.getHost())) + //.filter(bu -> !bu.getUser().equals(board.getHost())) + .filter(bu -> bu.getApplyStatus().equals(1)) // 참여 승인된 사람만 조회 .map(bu -> bu.getUser()) .collect(Collectors.toList()); List participantsImageUUIds = board.getBoardUsers().stream() - .filter(bu -> !bu.getUser().equals(board.getHost())) + //.filter(bu -> !bu.getUser().equals(board.getHost())) + .filter(bu -> bu.getApplyStatus().equals(1)) // 참여 승인된 사람만 조회 .map(bu -> bu.getUser().getProfileImg()) .collect(Collectors.toList()); @@ -92,6 +94,47 @@ public ApplicationResponse joinBoardUser(CreateBoardUserReq dto) { return ApplicationResponse.create("보드에 유저가 조인되었습니다.", res); } + + @Transactional(readOnly = false) + @Override + public ApplicationResponse approveBoardUser(CreateBoardUserReq dto){ + + userService.validateRefreshToken(dto.getUserId(), dto.getRefreshToken()); + + User user = userRepository.findByUserId(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + Board board = boardRepository.findBoardById(dto.getBoardId()) + .orElseThrow(() -> new NotFoundBoardException()); + + BoardUser boardUser = boardUserRepository.findByUserIdAndBoardId(user.getId(), board.getId()) + .orElseThrow(() -> new NotFoundUserBoard()); + + // Validation: 보드 인원 다 차면 신청 불가능 검증 + if(board.getCurrentMember() >= board.getTotalMember()){ + throw new MaxBoardUserException(); + } + + boardUser.changeApplyStatus(); // 참여 승인으로 상태 업데이트 + board.addCurrentMember();// 보드 현재 인원 +1 + //board.addBoardUser(boardUser); // 보드에 멤버 추가 + + List participants = board.getBoardUsers().stream() + //.filter(bu -> !bu.getUser().equals(board.getHost())) + .filter(bu -> bu.getApplyStatus().equals(1)) // 참여 승인된 사람만 조회 + .map(bu -> bu.getUser()) + .collect(Collectors.toList()); + + List participantsImageUUIds = board.getBoardUsers().stream() + //.filter(bu -> !bu.getUser().equals(board.getHost())) + .filter(bu -> bu.getApplyStatus().equals(1)) // 참여 승인된 사람만 조회 + .map(bu -> bu.getUser().getProfileImg()) + .collect(Collectors.toList()); + + BoardUserRes res = BoardUserRes.toDto(boardUser,user, board, participants, awsS3Service.makeUrlsOfFilenames(participantsImageUUIds)); + return ApplicationResponse.create("보드에 유저가 조인되었습니다.", res); + } + @Transactional @Override public ApplicationResponse delBoardUser(CreateBoardUserReq dto){