Skip to content

Commit

Permalink
#9 #65 feat: 보드 유저 참여 시(joinBoardUser) res에 참여자들 프로필이미지 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Dec 7, 2022
1 parent 42a3eda commit af0b7d8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class BoardUserRes {
Expand All @@ -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<Long> userIds;

@ApiModelProperty(example = "['이미지 url','이미지2 url']")
@ApiParam(value = "참여 유저 이미지 url 리스트")
private List<String> userImageUrls;

@Builder
public BoardUserRes(Long userId, Long boardId, Long boardUserId) {
public BoardUserRes(Long userId, Long boardId, Long boardUserId, List<Long> userIds, List<String> 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<User> users, List<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -59,7 +63,17 @@ public ApplicationResponse<BoardUserRes> joinBoardUser(CreateBoardUserReq dto) {
board.addCurrentMember();// 보드 현재 인원 +1
board.addBoardUser(boardUser); // 보드에 멤버 추가

BoardUserRes res = BoardUserRes.toDto(boardUser,user, board);
List<User> participants = board.getBoardUsers().stream()
.filter(bu -> !bu.getUser().equals(board.getHost()))
.map(bu -> bu.getUser())
.collect(Collectors.toList());

List<String> 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);
}

Expand Down

0 comments on commit af0b7d8

Please sign in to comment.