From af0b7d82cc3893ed6428e21ccfeb4c62f40501b0 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Wed, 7 Dec 2022 17:52:37 +0900 Subject: [PATCH] =?UTF-8?q?#9=20#65=20feat:=20=EB=B3=B4=EB=93=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=B0=B8=EC=97=AC=20=EC=8B=9C(joinBoardUs?= =?UTF-8?q?er)=20res=EC=97=90=20=EC=B0=B8=EC=97=AC=EC=9E=90=EB=93=A4=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=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 --- .../dto/response/boarduser/BoardUserRes.java | 32 ++++++++++++++----- .../boarduser/BoardUserServiceImpl.java | 16 +++++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/com/yogit/server/board/dto/response/boarduser/BoardUserRes.java b/server/src/main/java/com/yogit/server/board/dto/response/boarduser/BoardUserRes.java index 105040b..cd5efbc 100644 --- a/server/src/main/java/com/yogit/server/board/dto/response/boarduser/BoardUserRes.java +++ b/server/src/main/java/com/yogit/server/board/dto/response/boarduser/BoardUserRes.java @@ -9,6 +9,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; +import java.util.stream.Collectors; + @Data @NoArgsConstructor public class BoardUserRes { @@ -25,18 +28,31 @@ public class BoardUserRes { @ApiParam(value = "boardUserId, 보드 멤버 PK") private Long boardUserId; - public static BoardUserRes toDto(BoardUser boardUser, User user, Board board){ - return BoardUserRes.builder() - .userId(user.getId()) - .boardId(board.getId()) - .boardUserId(boardUser.getId()) - .build(); - } + @ApiModelProperty(example = "[1,2,3]") + @ApiParam(value = "참여 유저 이미지 ID 리스트") + private List userIds; + + @ApiModelProperty(example = "['이미지 url','이미지2 url']") + @ApiParam(value = "참여 유저 이미지 url 리스트") + private List userImageUrls; @Builder - public BoardUserRes(Long userId, Long boardId, Long boardUserId) { + public BoardUserRes(Long userId, Long boardId, Long boardUserId, List userIds, List userImageUrls) { this.userId = userId; this.boardId = boardId; this.boardUserId = boardUserId; + this.userIds = userIds; + this.userImageUrls = userImageUrls; + } + + + public static BoardUserRes toDto(BoardUser boardUser, User user, Board board, List users, List userImageUrls){ + return BoardUserRes.builder() + .userId(user.getId()) + .boardId(board.getId()) + .boardUserId(boardUser.getId()) + .userIds(users.stream().map(User::getId).collect(Collectors.toList())) + .userImageUrls(userImageUrls) + .build(); } } 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 90a983f..1715acd 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 @@ -11,6 +11,7 @@ import com.yogit.server.board.repository.BoardRepository; import com.yogit.server.board.repository.BoardUserRepository; 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; @@ -19,7 +20,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service @Transactional(readOnly = true) @@ -30,6 +33,7 @@ public class BoardUserServiceImpl implements BoardUserService{ private final UserRepository userRepository; private final BoardRepository boardRepository; private final UserService userService; + private final AwsS3Service awsS3Service; @Transactional(readOnly = false) @Override @@ -59,7 +63,17 @@ public ApplicationResponse joinBoardUser(CreateBoardUserReq dto) { board.addCurrentMember();// 보드 현재 인원 +1 board.addBoardUser(boardUser); // 보드에 멤버 추가 - BoardUserRes res = BoardUserRes.toDto(boardUser,user, board); + List participants = board.getBoardUsers().stream() + .filter(bu -> !bu.getUser().equals(board.getHost())) + .map(bu -> bu.getUser()) + .collect(Collectors.toList()); + + List participantsImageUUIds = board.getBoardUsers().stream() + .filter(bu -> !bu.getUser().equals(board.getHost())) + .map(bu -> bu.getUser().getProfileImg()) + .collect(Collectors.toList()); + + BoardUserRes res = BoardUserRes.toDto(boardUser,user, board, participants, awsS3Service.makeUrlsOfFilenames(participantsImageUUIds)); return ApplicationResponse.create("보드에 유저가 조인되었습니다.", res); }