Skip to content

Commit

Permalink
Merge pull request #180 from lemonssoju/develop-v2
Browse files Browse the repository at this point in the history
[develop-v2] main merge
  • Loading branch information
JoongHyun-Kim committed Jun 3, 2024
2 parents 6c72b01 + 341cbb3 commit 97fcea3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Comparator;
import java.util.List;

import static com.lesso.neverland.common.base.BaseResponseStatus.*;
import static com.lesso.neverland.common.constants.Constants.ACTIVE;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -65,10 +67,14 @@ public BaseResponse<AlbumDetailResponse> getAlbumDetail(Long groupIdx, Long albu
// 앨범 목록 조회(sortType="time", "location")
public BaseResponse<?> getAlbumList(Long groupIdx, String sortType) {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
List<Album> albumList = albumRepository.findByTeamOrderByCreatedDateDesc(group);

List<Album> albumList = albumRepository.findByTeamAndStatusEquals(group, ACTIVE);
List<Album> sortedAlbums = albumList.stream()
.sorted(Comparator.comparing(album -> album.getPuzzle().getPuzzleDate(), Comparator.reverseOrder()))
.toList();

if (sortType.equals("time")) {
List<AlbumByTimeDto> albumDtoList = albumList.stream().map(AlbumByTimeDto::from).toList();
List<AlbumByTimeDto> albumDtoList = sortedAlbums.stream().map(AlbumByTimeDto::from).toList();
return new BaseResponse<>(new AlbumListByTimeResponse(albumDtoList));
} else {
List<AlbumByLocationDto> albumDtoList = albumList.stream().map(AlbumByLocationDto::from).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
import java.util.List;

public interface AlbumRepository extends JpaRepository<Album, Long> {
List<Album> findByTeamOrderByCreatedDateDesc(Team team);
List<Album> findByTeamAndStatusEquals(Team team, String status);
boolean existsByPuzzle(Puzzle puzzle);
}

0 comments on commit 97fcea3

Please sign in to comment.