diff --git a/src/main/java/com/lesso/neverland/album/application/AlbumService.java b/src/main/java/com/lesso/neverland/album/application/AlbumService.java index dfefe53..54e413b 100644 --- a/src/main/java/com/lesso/neverland/album/application/AlbumService.java +++ b/src/main/java/com/lesso/neverland/album/application/AlbumService.java @@ -14,6 +14,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -47,9 +48,6 @@ public BaseResponse getAlbumDetail(Long groupIdx, Long albu Album album = albumRepository.findById(albumIdx).orElseThrow(() -> new BaseException(INVALID_ALBUM_IDX)); if (!album.getPuzzle().getTeam().equals(group)) throw new BaseException(NO_GROUP_ALBUM); - List memberList = album.getPuzzle().getPuzzleMembers().stream() - .map(puzzleMember -> puzzleMember.getUser().getProfile().getNickname()).toList(); - List commentList = album.getComments().stream() .filter(comment -> "active".equals(comment.getStatus())) .map(comment -> new CommentDto( @@ -57,13 +55,25 @@ public BaseResponse getAlbumDetail(Long groupIdx, Long albu comment.getUser().getProfile().getNickname(), comment.getUser().getProfile().getProfileImage(), comment.getCreatedDate().toString(), - comment.getContent())).toList(); + comment.getContent())) + .toList(); AlbumDetailResponse albumDetailResponse = new AlbumDetailResponse(album.getPuzzle().getTitle(), album.getPuzzle().getPuzzleDate().toString(), - album.getPuzzle().getLocation().getLocation(), memberList, album.getAlbumImage(), album.getContent(), album.getPuzzle().getPuzzleIdx(), commentList); + album.getPuzzle().getLocation().getLocation(), getMemberList(album), album.getAlbumImage(), album.getContent(), album.getPuzzle().getPuzzleIdx(), commentList); return new BaseResponse<>(albumDetailResponse); } + private List getMemberList(Album album) { + List memberList = new ArrayList<>(); + memberList.add(album.getPuzzle().getUser().getProfile().getNickname()); + + memberList.addAll( + album.getPuzzle().getPuzzleMembers().stream() + .map(puzzleMember -> puzzleMember.getUser().getProfile().getNickname()) + .toList()); + return memberList; + } + // 앨범 목록 조회(sortType="time", "location") public BaseResponse getAlbumList(Long groupIdx, String sortType) { Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX)); diff --git a/src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java b/src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java index f08502a..c111ea2 100644 --- a/src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java +++ b/src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java @@ -2,6 +2,7 @@ import com.lesso.neverland.album.domain.Album; +import java.util.ArrayList; import java.util.List; public record AlbumByTimeDto(Long albumIdx, @@ -11,7 +12,18 @@ public record AlbumByTimeDto(Long albumIdx, String puzzleDate, Integer puzzlerCount, List puzzlerImageList) { + + public static AlbumByTimeDto from(Album album) { + List puzzlerImageList = new ArrayList<>(); + puzzlerImageList.add(album.getPuzzle().getUser().getProfile().getProfileImage()); + + puzzlerImageList.addAll( + album.getPuzzle().getPuzzleMembers().stream() + .map(puzzleMember -> puzzleMember.getUser().getProfile().getProfileImage()) + .limit(2) + .toList()); + return new AlbumByTimeDto( album.getAlbumIdx(), album.getPuzzle().getTitle(), @@ -19,8 +31,7 @@ public static AlbumByTimeDto from(Album album) { album.getAlbumImage(), album.getPuzzle().getPuzzleDate().toString(), album.getPuzzle().getPuzzleMembers().size(), - album.getPuzzle().getPuzzleMembers().stream() - .map(puzzleMember -> puzzleMember.getUser().getProfile().getProfileImage()).toList() + puzzlerImageList ); } } diff --git a/src/main/java/com/lesso/neverland/group/application/GroupService.java b/src/main/java/com/lesso/neverland/group/application/GroupService.java index c0ba547..7503756 100644 --- a/src/main/java/com/lesso/neverland/group/application/GroupService.java +++ b/src/main/java/com/lesso/neverland/group/application/GroupService.java @@ -112,13 +112,14 @@ private List getMemberImageList(Team group) { List memberImages = group.getUserTeams().stream() .filter(userTeam -> "active".equals(userTeam.getStatus())) + .filter(userTeam -> !userTeam.getUser().equals(group.getAdmin())) .map(userTeam -> userTeam.getUser().getProfile().getProfileImage()) - .limit(2).toList(); + .limit(2) + .toList(); imageList.addAll(memberImages); return imageList; } - // [관리자] 그룹 수정 화면 조회 public BaseResponse getGroupEditView(Long groupIdx) { Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX)); diff --git a/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java b/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java index b1a776d..5c1a110 100644 --- a/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java +++ b/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java @@ -146,7 +146,7 @@ public BaseResponse createPuzzle(Long groupIdx, MultipartF LocalDate puzzleDate = convertToLocalDate(createPuzzleRequest.puzzleDate()); Puzzle newPuzzle = createPuzzle(createPuzzleRequest, group, writer, puzzleDate); - if (!image.isEmpty()) { + if (image != null && !image.isEmpty()) { String imagePath = imageService.uploadImage("puzzle", image); newPuzzle.addPuzzleImage(imagePath); } diff --git a/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java b/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java index 6d1dda8..8864ad6 100644 --- a/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java +++ b/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.List; +import static com.lesso.neverland.common.constants.Constants.ACTIVE; import static com.lesso.neverland.common.constants.Constants.INACTIVE; @Entity @@ -62,6 +63,7 @@ public Puzzle(User user, Team team, String title, String content, LocalDate puzz this.content = content; this.puzzleDate = puzzleDate; this.location = location; + this.setStatus(ACTIVE); } public void setUser(User user) {