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 0fa84db..87d232a 100644 --- a/src/main/java/com/lesso/neverland/album/application/AlbumService.java +++ b/src/main/java/com/lesso/neverland/album/application/AlbumService.java @@ -1,8 +1,7 @@ package com.lesso.neverland.album.application; import com.lesso.neverland.album.domain.Album; -import com.lesso.neverland.album.dto.AlbumDetailResponse; -import com.lesso.neverland.album.dto.AlbumImageRequest; +import com.lesso.neverland.album.dto.*; import com.lesso.neverland.album.repository.AlbumRepository; import com.lesso.neverland.comment.dto.CommentDto; import com.lesso.neverland.common.base.BaseException; @@ -51,7 +50,21 @@ public BaseResponse getAlbumDetail(Long groupIdx, Long albu comment.getContent())).toList(); AlbumDetailResponse albumDetailResponse = new AlbumDetailResponse(album.getPuzzle().getTitle(), album.getPuzzle().getPuzzleDate().toString(), - album.getPuzzle().getLocation(), memberList, album.getAlbumImage(), album.getContent(), album.getPuzzle().getPuzzleIdx(), commentList); + album.getPuzzle().getLocation().getLocation(), memberList, album.getAlbumImage(), album.getContent(), album.getPuzzle().getPuzzleIdx(), commentList); return new BaseResponse<>(albumDetailResponse); } + + // 앨범 목록 조회(sortType="time", "location") + public BaseResponse getAlbumList(Long groupIdx, String sortType) { + Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX)); + List albumList = albumRepository.findByTeamOrderByCreatedDateDesc(group); + + if (sortType.equals("time")) { + List albumDtoList = albumList.stream().map(AlbumByTimeDto::from).toList(); + return new BaseResponse<>(new AlbumListByTimeResponse(albumDtoList)); + } else { + List albumDtoList = albumList.stream().map(AlbumByLocationDto::from).toList(); + return new BaseResponse<>(new AlbumListByLocationResponse(albumDtoList)); + } + } } diff --git a/src/main/java/com/lesso/neverland/album/domain/Album.java b/src/main/java/com/lesso/neverland/album/domain/Album.java index e70904e..4868954 100644 --- a/src/main/java/com/lesso/neverland/album/domain/Album.java +++ b/src/main/java/com/lesso/neverland/album/domain/Album.java @@ -2,6 +2,7 @@ import com.lesso.neverland.comment.domain.Comment; import com.lesso.neverland.common.base.BaseEntity; +import com.lesso.neverland.group.domain.Team; import com.lesso.neverland.puzzle.domain.Puzzle; import jakarta.persistence.*; import lombok.AccessLevel; @@ -26,6 +27,11 @@ public class Album extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "puzzle") private Puzzle puzzle; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team") + private Team team; + private String albumImage; @Column(nullable = false) diff --git a/src/main/java/com/lesso/neverland/album/dto/AlbumByLocationDto.java b/src/main/java/com/lesso/neverland/album/dto/AlbumByLocationDto.java new file mode 100644 index 0000000..9c8bb8a --- /dev/null +++ b/src/main/java/com/lesso/neverland/album/dto/AlbumByLocationDto.java @@ -0,0 +1,16 @@ +package com.lesso.neverland.album.dto; + +import com.lesso.neverland.album.domain.Album; + +public record AlbumByLocationDto(Long albumIdx, + String albumImage, + String x, + String y) { + public static AlbumByLocationDto from(Album album) { + return new AlbumByLocationDto( + album.getAlbumIdx(), + album.getAlbumImage(), + album.getPuzzle().getLocation().getX(), + album.getPuzzle().getLocation().getY()); + } +} diff --git a/src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java b/src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java new file mode 100644 index 0000000..f08502a --- /dev/null +++ b/src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java @@ -0,0 +1,26 @@ +package com.lesso.neverland.album.dto; + +import com.lesso.neverland.album.domain.Album; + +import java.util.List; + +public record AlbumByTimeDto(Long albumIdx, + String title, + String content, + String albumImage, + String puzzleDate, + Integer puzzlerCount, + List puzzlerImageList) { + public static AlbumByTimeDto from(Album album) { + 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() + ); + } +} diff --git a/src/main/java/com/lesso/neverland/album/dto/AlbumListByLocationResponse.java b/src/main/java/com/lesso/neverland/album/dto/AlbumListByLocationResponse.java new file mode 100644 index 0000000..0d8190f --- /dev/null +++ b/src/main/java/com/lesso/neverland/album/dto/AlbumListByLocationResponse.java @@ -0,0 +1,5 @@ +package com.lesso.neverland.album.dto; + +import java.util.List; + +public record AlbumListByLocationResponse(List albumList) {} diff --git a/src/main/java/com/lesso/neverland/album/dto/AlbumListByTimeResponse.java b/src/main/java/com/lesso/neverland/album/dto/AlbumListByTimeResponse.java new file mode 100644 index 0000000..7b3c7f8 --- /dev/null +++ b/src/main/java/com/lesso/neverland/album/dto/AlbumListByTimeResponse.java @@ -0,0 +1,5 @@ +package com.lesso.neverland.album.dto; + +import java.util.List; + +public record AlbumListByTimeResponse(List albumList) {} diff --git a/src/main/java/com/lesso/neverland/album/presentation/AlbumController.java b/src/main/java/com/lesso/neverland/album/presentation/AlbumController.java index 9ce2026..4ba7339 100644 --- a/src/main/java/com/lesso/neverland/album/presentation/AlbumController.java +++ b/src/main/java/com/lesso/neverland/album/presentation/AlbumController.java @@ -27,4 +27,10 @@ public BaseResponse uploadAlbumImage(@PathVariable("groupIdx") Long grou public BaseResponse getAlbumDetail(@PathVariable("groupIdx") Long groupIdx, @PathVariable("albumIdx") Long albumIdx) { return albumService.getAlbumDetail(groupIdx, albumIdx); } + + // 앨범 목록 조회 + @GetMapping("") + public BaseResponse getAlbumList(@PathVariable("groupIdx") Long groupIdx, @RequestParam String sortType) { + return albumService.getAlbumList(groupIdx, sortType); + } } diff --git a/src/main/java/com/lesso/neverland/album/repository/AlbumRepository.java b/src/main/java/com/lesso/neverland/album/repository/AlbumRepository.java index de329d8..cc7cbd1 100644 --- a/src/main/java/com/lesso/neverland/album/repository/AlbumRepository.java +++ b/src/main/java/com/lesso/neverland/album/repository/AlbumRepository.java @@ -1,7 +1,11 @@ package com.lesso.neverland.album.repository; import com.lesso.neverland.album.domain.Album; +import com.lesso.neverland.group.domain.Team; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface AlbumRepository extends JpaRepository { + List findByTeamOrderByCreatedDateDesc(Team team); } 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 1754756..aa6e074 100644 --- a/src/main/java/com/lesso/neverland/group/application/GroupService.java +++ b/src/main/java/com/lesso/neverland/group/application/GroupService.java @@ -55,7 +55,7 @@ public BaseResponse getGroupList() { private String calculateRecentUpdate(Team group) { Puzzle recentPuzzle = puzzleRepository.findTopByTeamAndStatusEqualsOrderByCreatedDateDesc(group, ACTIVE); - + if (recentPuzzle == null) return ""; LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul")); LocalDate puzzleCreatedDate = recentPuzzle.getCreatedDate(); long daysBetween = ChronoUnit.DAYS.between(puzzleCreatedDate, today); 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 ed42786..9376528 100644 --- a/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java +++ b/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java @@ -7,6 +7,7 @@ import com.lesso.neverland.common.image.ImageService; import com.lesso.neverland.gpt.application.GptService; import com.lesso.neverland.gpt.dto.GptResponseDto; +import com.lesso.neverland.puzzle.domain.PuzzleLocation; import com.lesso.neverland.puzzle.dto.CompletePuzzleRequest; import com.lesso.neverland.puzzle.dto.CompletePuzzleResponse; import com.lesso.neverland.gpt.dto.GptResponse; @@ -73,7 +74,7 @@ private static List getGroupPuzzleDtos(List groupPuzzleL puzzle.getPuzzleImage(), puzzle.getUser().getProfile().getNickname(), puzzle.getCreatedDate().toString(), - puzzle.getLocation())).toList(); + puzzle.getLocation().getLocation())).toList(); } // 퍼즐 상세 조회 @@ -88,7 +89,7 @@ public BaseResponse getPuzzleDetail(Long groupIdx, Long pu boolean isWriter = puzzle.getUser().equals(user); boolean hasWrite = puzzlePieceRepository.existsByPuzzleAndUser(puzzle, user); - PuzzleDetailResponse puzzleDetail = new PuzzleDetailResponse(puzzle.getLocation(), puzzle.getPuzzleImage(), + PuzzleDetailResponse puzzleDetail = new PuzzleDetailResponse(puzzle.getLocation().getLocation(), puzzle.getPuzzleImage(), puzzle.getPuzzleDate().toString(), puzzle.getUser().getProfile().getNickname(), puzzle.getTitle(), puzzle.getContent(), getMemberImageList(puzzle), puzzle.getPuzzleMembers().size(), puzzle.getPuzzlePieces().size()+1, isWriter, hasWrite, getPuzzlePieceList(puzzle)); @@ -159,12 +160,13 @@ private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group, .content(createPuzzleRequest.content()) .puzzleImage(imagePath) .puzzleDate(puzzleDate) - .location(createPuzzleRequest.location()).build(); + .location(new PuzzleLocation(createPuzzleRequest.location())).build(); puzzleRepository.save(puzzle); - return puzzle; } + //TODO: 퍼즐 생성 시, String으로 받은 location값을 x, y 좌표로 변환해 함께 저장 + // [작성자] 퍼즐 수정 public BaseResponse editPuzzle(Long groupIdx, Long puzzleIdx, MultipartFile newImage, EditPuzzleRequest editPuzzleRequest) { User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); 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 293ab88..34d483e 100644 --- a/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java +++ b/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java @@ -45,8 +45,8 @@ public class Puzzle extends BaseEntity { @Column(nullable = false) private LocalDate puzzleDate; // 추억 날짜 - @Column(nullable = false) - private String location; // 추억 장소 + @Embedded + private PuzzleLocation location; // 추억 장소 @OneToMany(mappedBy = "puzzle") private List puzzlePieces = new ArrayList<>(); @@ -55,7 +55,7 @@ public class Puzzle extends BaseEntity { private List puzzleMembers = new ArrayList<>(); // 해당 퍼즐에 참여한 멤버 목록 @Builder - public Puzzle(User user, Team team, String title, String content, String puzzleImage, LocalDate puzzleDate, String location, String backgroundMusic, String backgroundMusicUrl) { + public Puzzle(User user, Team team, String title, String content, String puzzleImage, LocalDate puzzleDate, PuzzleLocation location) { this.user = user; this.team = team; this.title = title; diff --git a/src/main/java/com/lesso/neverland/puzzle/domain/PuzzleLocation.java b/src/main/java/com/lesso/neverland/puzzle/domain/PuzzleLocation.java new file mode 100644 index 0000000..5cf2f08 --- /dev/null +++ b/src/main/java/com/lesso/neverland/puzzle/domain/PuzzleLocation.java @@ -0,0 +1,23 @@ +package com.lesso.neverland.puzzle.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Embeddable +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class PuzzleLocation { + + @Column(nullable = false) + private String location; + + private String x; + private String y; + + @Builder + public PuzzleLocation(String location) {this.location = location;} +}