Skip to content

Commit

Permalink
fix: 소확행 수정 API 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mingeun.kim authored and mingeun0507 committed Sep 15, 2024
1 parent a788569 commit 1b8f90c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public void addJoyToAlbum(Long joyId, AlbumSaveJoyRequest albumSaveJoyRequest, U
.orElseThrow(() -> CustomException.of(ErrorDetails.ALBUM_NOT_FOUND));

// 앨범 내에서 가장 높은 order 값을 조회하여 1을 더해줌
Integer maxOrder = savingJoyRepository.findMaxOrderByAlbum(album);
Integer joyOrder = (maxOrder == null) ? 1 : maxOrder + 1;
final Integer joyOrder = savingJoyRepository.findTopByAlbumOrderByJoyOrderDesc(album).map(SavingJoy::getJoyOrder).orElse(0) + 1;
final SavingJoy savingJoy = SavingJoy.createSavingJoy(joy, album, joyOrder);
savingJoyRepository.save(savingJoy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface SavingJoyRepository extends JpaRepository<SavingJoy, Long> {

void deleteByAlbumAlbumId(Long albumId);

Integer findMaxOrderByAlbum(Album album);
Optional<SavingJoy> findTopByAlbumOrderByJoyOrderDesc(Album album);

void deleteAllByJoyJoyIdIn(List<Long> deletedJoyIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ public void addToSavingJoy(Long joyId, List<Long> afterAlbumIds) {
.orElseThrow(() -> CustomException.of(ErrorDetails.ALBUM_NOT_FOUND));

// 앨범 내에서 가장 높은 order 값을 조회하여 1을 더해줌
Integer maxOrder = savingJoyRepository.findMaxOrderByAlbum(album);
Integer joyOrder = (maxOrder == null) ? 1 : maxOrder + 1;
final SavingJoy savingJoy = SavingJoy.createSavingJoy(joy, album, joyOrder);
savingJoyRepository.save(savingJoy);
final Integer joyOrder = savingJoyRepository.findTopByAlbumOrderByJoyOrderDesc(album).map(SavingJoy::getJoyOrder).orElse(0) + 1;
final SavingJoy savingJoy = SavingJoy.createSavingJoy(joy, album, joyOrder);
savingJoyRepository.save(savingJoy);

// 앨범은 공개, 소확행은 비공개일 때 -> 소확행 공개로 변경
if (album.getAlbumStatus().getIsOfficial() && joy.getJoyType().equals(JoyType.PERSONAL)) {
if (Boolean.TRUE.equals(album.getAlbumStatus().getIsOfficial()) && joy.getJoyType().equals(JoyType.PERSONAL)) {
joy.makeOfficial();
}
}
Expand Down

0 comments on commit 1b8f90c

Please sign in to comment.