From 1b8f90c0b9c97a842a822ed7d435a64a6565aa6a Mon Sep 17 00:00:00 2001 From: "mingeun.kim" Date: Sun, 15 Sep 2024 16:11:07 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=86=8C=ED=99=95=ED=96=89=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20API=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/albums/application/service/AlbumService.java | 3 +-- .../albums/domain/repository/SavingJoyRepository.java | 2 +- .../madii/domain/joy/application/service/JoyService.java | 9 ++++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/guttery/madii/domain/albums/application/service/AlbumService.java b/src/main/java/com/guttery/madii/domain/albums/application/service/AlbumService.java index 0eeb3c3..8abd16f 100644 --- a/src/main/java/com/guttery/madii/domain/albums/application/service/AlbumService.java +++ b/src/main/java/com/guttery/madii/domain/albums/application/service/AlbumService.java @@ -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); } diff --git a/src/main/java/com/guttery/madii/domain/albums/domain/repository/SavingJoyRepository.java b/src/main/java/com/guttery/madii/domain/albums/domain/repository/SavingJoyRepository.java index cb08766..2914bf6 100644 --- a/src/main/java/com/guttery/madii/domain/albums/domain/repository/SavingJoyRepository.java +++ b/src/main/java/com/guttery/madii/domain/albums/domain/repository/SavingJoyRepository.java @@ -14,7 +14,7 @@ public interface SavingJoyRepository extends JpaRepository { void deleteByAlbumAlbumId(Long albumId); - Integer findMaxOrderByAlbum(Album album); + Optional findTopByAlbumOrderByJoyOrderDesc(Album album); void deleteAllByJoyJoyIdIn(List deletedJoyIds); diff --git a/src/main/java/com/guttery/madii/domain/joy/application/service/JoyService.java b/src/main/java/com/guttery/madii/domain/joy/application/service/JoyService.java index 149c1a9..3a33b2e 100644 --- a/src/main/java/com/guttery/madii/domain/joy/application/service/JoyService.java +++ b/src/main/java/com/guttery/madii/domain/joy/application/service/JoyService.java @@ -79,13 +79,12 @@ public void addToSavingJoy(Long joyId, List 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(); } }