diff --git a/src/main/java/com/guttery/madii/domain/albums/domain/repository/AlbumQueryDslRepository.java b/src/main/java/com/guttery/madii/domain/albums/domain/repository/AlbumQueryDslRepository.java index 4f784fc..650ac68 100644 --- a/src/main/java/com/guttery/madii/domain/albums/domain/repository/AlbumQueryDslRepository.java +++ b/src/main/java/com/guttery/madii/domain/albums/domain/repository/AlbumQueryDslRepository.java @@ -17,6 +17,7 @@ public interface AlbumQueryDslRepository { List getMyAlbumsInfo(Long userId); List getMyBookmarksInfo(Long userId); + List getMyAlbumsCreated(Long userId); List getMyJoyAllAlbums(Long joyId, Long userId); diff --git a/src/main/java/com/guttery/madii/domain/joy/application/dto/JoyGetRecommendResponse.java b/src/main/java/com/guttery/madii/domain/joy/application/dto/JoyGetRecommendResponse.java index aa5e70d..740b737 100644 --- a/src/main/java/com/guttery/madii/domain/joy/application/dto/JoyGetRecommendResponse.java +++ b/src/main/java/com/guttery/madii/domain/joy/application/dto/JoyGetRecommendResponse.java @@ -9,6 +9,8 @@ public record JoyGetRecommendResponse( @Schema(description = "소확행 썸네일 아이콘 번호", example = "3") Integer joyIconNum, @Schema(description = "소확행 내용", example = "낮잠자기") - String contents + String contents, + @Schema(description = "소확행 저장 여부", example = "true(1)") + Boolean isJoySaved ) { } 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 6f543fd..2e804d0 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 @@ -158,7 +158,8 @@ public void deleteMyJoy(Long joyId, UserPrincipal userPrincipal) { @Transactional(readOnly = true) public List getJoyRecommend(JoyGetRecommendRequest joyGetRecommendRequest, UserPrincipal userPrincipal) { - List joyGetRecommendResponseList = joyQueryDslRepository.getJoyRecommend(joyGetRecommendRequest); + final User user = UserServiceHelper.findExistingUser(userRepository, userPrincipal); + List joyGetRecommendResponseList = joyQueryDslRepository.getJoyRecommend(joyGetRecommendRequest, user.getUserId()); return joyGetRecommendResponseList; } diff --git a/src/main/java/com/guttery/madii/domain/joy/domain/repository/JoyQueryDslRepository.java b/src/main/java/com/guttery/madii/domain/joy/domain/repository/JoyQueryDslRepository.java index 08faa9f..ad4e011 100644 --- a/src/main/java/com/guttery/madii/domain/joy/domain/repository/JoyQueryDslRepository.java +++ b/src/main/java/com/guttery/madii/domain/joy/domain/repository/JoyQueryDslRepository.java @@ -12,5 +12,5 @@ public interface JoyQueryDslRepository { List getRandomOfficialJoys(int amount); - List getJoyRecommend(JoyGetRecommendRequest joyGetRecommendRequest); + List getJoyRecommend(JoyGetRecommendRequest joyGetRecommendRequest, Long userId); } diff --git a/src/main/java/com/guttery/madii/domain/joy/infrastructure/JoyRepositoryImpl.java b/src/main/java/com/guttery/madii/domain/joy/infrastructure/JoyRepositoryImpl.java index 748de61..2e6b8b3 100644 --- a/src/main/java/com/guttery/madii/domain/joy/infrastructure/JoyRepositoryImpl.java +++ b/src/main/java/com/guttery/madii/domain/joy/infrastructure/JoyRepositoryImpl.java @@ -14,6 +14,7 @@ import com.querydsl.core.types.dsl.Expressions; import com.querydsl.core.types.dsl.StringTemplate; import com.querydsl.jpa.JPAExpressions; +import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -25,6 +26,7 @@ import java.util.Set; import java.util.stream.Collectors; +import static com.guttery.madii.domain.albums.domain.model.QSavingJoy.savingJoy; import static com.guttery.madii.domain.joy.domain.model.QJoy.joy; import static com.guttery.madii.domain.joytag.domain.model.QJoyTag.joyTag; import static com.guttery.madii.domain.tag.domain.model.QTag.tag; @@ -80,7 +82,7 @@ public List getRandomOfficialJoys(int amount) { } @Override - public List getJoyRecommend(JoyGetRecommendRequest request) { + public List getJoyRecommend(JoyGetRecommendRequest request, Long userId) { Set resultJoyIds = new HashSet<>(); @@ -122,9 +124,27 @@ public List getJoyRecommend(JoyGetRecommendRequest requ Collections.shuffle(allRecommendations); // 최대 3개의 항목만 선택하여 DTO로 변환 +// return allRecommendations.stream() +// .limit(3) +// .map(joy -> new JoyGetRecommendResponse(joy.getJoyId(), joy.getJoyIconNum(), joy.getContents(), ??)) +// .collect(Collectors.toList()); + return allRecommendations.stream() .limit(3) - .map(joy -> new JoyGetRecommendResponse(joy.getJoyId(), joy.getJoyIconNum(), joy.getContents())) + .map(joy -> { + Boolean isSaved = queryFactory + .select(savingJoy.isNotNull()) + .from(savingJoy) + .where(savingJoy.joy.joyId.eq(joy.getJoyId()), + savingJoy.album.user.userId.eq(userId)) + .fetchOne(); + + // isSaved 값이 null인 경우 false로 처리 + Boolean isJoySaved = isSaved != null && isSaved; + + // joy 객체를 JoyGetRecommendResponse로 매핑하여 반환 + return new JoyGetRecommendResponse(joy.getJoyId(), joy.getJoyIconNum(), joy.getContents(), isJoySaved); + }) .collect(Collectors.toList()); }