Skip to content

Commit

Permalink
Merge pull request #203 from 9uttery/feat/get-albums-#202
Browse files Browse the repository at this point in the history
[Feature] 전체 앨범 조회 시 정렬 조건 변경
  • Loading branch information
hojeong2747 authored Jul 14, 2024
2 parents 5fab44e + 1837f28 commit e2b3882
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum ErrorDetails {
ALREADY_EXIST_BOOKMARK("A002", HttpStatus.BAD_REQUEST.value(), "이미 저장한 앨범입니다."),
NOT_FOUND_BOOKMARK("A003", HttpStatus.BAD_REQUEST.value(), "저장한 앨범이 아닙니다."),
NOT_MY_ALBUM("A004", HttpStatus.BAD_REQUEST.value(), "내가 만든 앨범이 아닙니다."),
ALREADY_OFFICIAL("A005", HttpStatus.BAD_REQUEST.value(), "이미 공개된 앨범입니다."),

ACHIEVEMENT_NOT_FOUND("P001", HttpStatus.NOT_FOUND.value(), "오늘의 플레이리스트에서 해당 실천을 찾을 수 없습니다."),
INVALID_SATISFACTION_ENUM("P002", HttpStatus.BAD_REQUEST.value(), "만족도 ENUM이 유효하지 않습니다. BAD, SO_SO, GOOD, GREAT, EXCELLENT 중 하나여야 합니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ public void putMyAlbumStatus(Long albumId, UserPrincipal userPrincipal) {
final Album album = albumRepository.findById(albumId)
.orElseThrow(() -> CustomException.of(ErrorDetails.ALBUM_NOT_FOUND));

if (album.getAlbumStatus().getIsOfficial()) {
album.makePersonal();
} else {
album.makeOfficial();
}
if (album.getAlbumStatus().getIsOfficial()) throw CustomException.of(ErrorDetails.ALREADY_OFFICIAL);

album.makeOfficial();
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.LastModifiedDate;

import java.time.LocalDateTime;
import java.util.List;

@Getter
Expand All @@ -46,6 +48,7 @@ public class Album extends BaseTimeEntity {
private List<SavingAlbum> savingAlbums;
@OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true)
private List<SavingJoy> savingJoys;
private LocalDateTime officialSetAt;

public Album(User user, String name, String description, AlbumStatus albumStatus, AlbumInfo albumInfo) {
this.user = user;
Expand All @@ -66,14 +69,9 @@ public void modifyNameAndDes(String name, String description) {
this.description = description;
}

public void modifyInfo(AlbumInfo albumInfo) { this.albumInfo = albumInfo; }

public void makeOfficial() {
this.albumStatus = this.albumStatus.withOfficial(true);
}

public void makePersonal() {
this.albumStatus = this.albumStatus.withOfficial(false);
this.officialSetAt = LocalDateTime.now();
}

public void makeBlocked() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public List<AlbumGetAllResponse> getAllAlbums(Long cursorId, int size) {
album.name))
.from(album)
.where(album.albumStatus.isOfficial.eq(true).and(predicate))
.orderBy(album.albumId.desc())
.orderBy(album.officialSetAt.desc())
.limit(size + 1)
.fetch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ public List<AlbumGetJoyAllResponse> getMyJoyAllAlbums(@PathVariable Long joyId,
}
)
@Operation(summary = "전체 앨범 조회 API", description = "전체 앨범 조회 API입니다.")
// public List<AlbumGetAllResponse> getAllAlbums() {
// return albumService.getAllIsOfficialAlbums();
// }
public Slice<AlbumGetAllResponse> getAllAlbums(@RequestParam(required = false) Long albumId,
@RequestParam int size) {
return albumService.getAllAlbums(albumId, size);
Expand Down

0 comments on commit e2b3882

Please sign in to comment.