Skip to content

Commit

Permalink
Merge pull request #174 from 9uttery/feat/uiux-develop-#166
Browse files Browse the repository at this point in the history
[Feature] 취향저격 소확행 개별 소확행 북마크 추가 구현
  • Loading branch information
hojeong2747 authored Apr 20, 2024
2 parents e953ad1 + b6e1a71 commit 1b252bf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface AlbumQueryDslRepository {
List<AlbumGetMyAllResponse> getMyAlbumsInfo(Long userId);

List<AlbumGetMyAllResponse> getMyBookmarksInfo(Long userId);

List<AlbumGetCreatedResponse> getMyAlbumsCreated(Long userId);

List<AlbumGetJoyAllResponse> getMyJoyAllAlbums(Long joyId, Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public void deleteMyJoy(Long joyId, UserPrincipal userPrincipal) {

@Transactional(readOnly = true)
public List<JoyGetRecommendResponse> getJoyRecommend(JoyGetRecommendRequest joyGetRecommendRequest, UserPrincipal userPrincipal) {
List<JoyGetRecommendResponse> joyGetRecommendResponseList = joyQueryDslRepository.getJoyRecommend(joyGetRecommendRequest);
final User user = UserServiceHelper.findExistingUser(userRepository, userPrincipal);
List<JoyGetRecommendResponse> joyGetRecommendResponseList = joyQueryDslRepository.getJoyRecommend(joyGetRecommendRequest, user.getUserId());
return joyGetRecommendResponseList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface JoyQueryDslRepository {

List<Joy> getRandomOfficialJoys(int amount);

List<JoyGetRecommendResponse> getJoyRecommend(JoyGetRecommendRequest joyGetRecommendRequest);
List<JoyGetRecommendResponse> getJoyRecommend(JoyGetRecommendRequest joyGetRecommendRequest, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -80,7 +82,7 @@ public List<Joy> getRandomOfficialJoys(int amount) {
}

@Override
public List<JoyGetRecommendResponse> getJoyRecommend(JoyGetRecommendRequest request) {
public List<JoyGetRecommendResponse> getJoyRecommend(JoyGetRecommendRequest request, Long userId) {

Set<Long> resultJoyIds = new HashSet<>();

Expand Down Expand Up @@ -122,9 +124,27 @@ public List<JoyGetRecommendResponse> 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());
}

Expand Down

0 comments on commit 1b252bf

Please sign in to comment.