Skip to content

Commit

Permalink
Merge pull request #189 from lemonssoju/develop-v2
Browse files Browse the repository at this point in the history
[develop-v2] main merge
  • Loading branch information
JoongHyun-Kim authored Jun 6, 2024
2 parents a6f1bba + a8cd5c2 commit f148618
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -47,23 +48,32 @@ public BaseResponse<AlbumDetailResponse> 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<String> memberList = album.getPuzzle().getPuzzleMembers().stream()
.map(puzzleMember -> puzzleMember.getUser().getProfile().getNickname()).toList();

List<CommentDto> commentList = album.getComments().stream()
.filter(comment -> "active".equals(comment.getStatus()))
.map(comment -> new CommentDto(
comment.getCommentIdx(),
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<String> getMemberList(Album album) {
List<String> 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));
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.lesso.neverland.album.domain.Album;

import java.util.ArrayList;
import java.util.List;

public record AlbumByTimeDto(Long albumIdx,
Expand All @@ -11,16 +12,26 @@ public record AlbumByTimeDto(Long albumIdx,
String puzzleDate,
Integer puzzlerCount,
List<String> puzzlerImageList) {


public static AlbumByTimeDto from(Album album) {
List<String> 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(),
album.getContent(),
album.getAlbumImage(),
album.getPuzzle().getPuzzleDate().toString(),
album.getPuzzle().getPuzzleMembers().size(),
album.getPuzzle().getPuzzleMembers().stream()
.map(puzzleMember -> puzzleMember.getUser().getProfile().getProfileImage()).toList()
puzzlerImageList
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ private List<String> getMemberImageList(Team group) {

List<String> 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<GroupEditViewResponse> getGroupEditView(Long groupIdx) {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public BaseResponse<CreatePuzzleResponse> 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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f148618

Please sign in to comment.