Skip to content

Commit

Permalink
[Fix]: 컴파일 에러 해결.
Browse files Browse the repository at this point in the history
  • Loading branch information
young970 committed Mar 10, 2024
1 parent 1411b5d commit 32060be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ public Space getById(Long spaceId) {
.orElseThrow(() -> new DataNotFoundException("해당 spaceId를 가진 Space를 찾을 수 없습니다."));
}

@Override
public Space getByIdWhitLock(Long spaceId) {
return spaceJpaRepository.findByIdWithLock(spaceId)
.orElseThrow(() -> new DataNotFoundException("해당 spaceId를 가진 Space를 찾을 수 없습니다."));
}

@Override
public Space getSpaceJoinSpaceMemberById(Long spaceId) {
return spaceJpaRepository.findSpaceJoinSpaceMemberById(spaceId)
Expand All @@ -60,6 +54,11 @@ public Slice<SpaceAndSpaceImageOwnerNickName> findMemberSpacesJoinSpaceImageByQu
return spaceQueryDslRepository.findMemberSpacesJoinSpaceImageByCondition(queryCondition);
}

@Override
public Slice<SpaceAndSpaceImageOwnerNickName> findPublicSpacesJoinSpaceImageByLikeQuery(QueryCondition queryCondition) {
return spaceQueryDslRepository.findPublicSpacesJoinSpaceImageByConditionWithLikeQuery(queryCondition);
}

@Override
public void increaseScrapCount(Long spaceId) {
spaceJpaRepository.increaseScrapCount(spaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public interface SpaceRepository {

Slice<SpaceAndSpaceImageOwnerNickName> findMemberSpacesJoinSpaceImageByQuery(MemberSpacesQueryCondition queryCondition);

Slice<SpaceAndSpaceImageOwnerNickName> findPublicSpacesJoinSpaceImageByLikeQuery(QueryCondition queryCondition);

void increaseScrapCount(Long spaceId);

Space getByIdWithPessimisticLock(Long spaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Slice<SpaceAndSpaceImageOwnerNickName> searchPublicSpacesJoinSpaceImageBy
.leftJoin(member).on(space.memberId.eq(member.id))
.where(space.isDeleted.eq(false),
space.isVisible.eq(true),
dynamicQueryFactory.eqSpaceNameWithPlus(condition.keyWord()),
dynamicQueryFactory.eqSpaceName(condition.keyWord()),
dynamicQueryFactory.eqCategory(condition.filter())
)
.orderBy(dynamicQueryFactory.spaceSort(condition.pageable().getSort()))
Expand Down Expand Up @@ -110,7 +110,7 @@ public Slice<SpaceAndSpaceImageOwnerNickName> findMemberSpacesJoinSpaceImageByCo
.where(spaceMember.memberId.eq(condition.memberId()),
space.isDeleted.eq(false),
dynamicQueryFactory.eqIsVisible(condition.isMySpace()),
dynamicQueryFactory.eqSpaceNameWithPlus(condition.keyWord()),
dynamicQueryFactory.eqSpaceName(condition.keyWord()),
dynamicQueryFactory.eqCategory(condition.filter())
)
.orderBy(space.id.desc())
Expand All @@ -133,21 +133,6 @@ public Slice<SpaceAndSpaceImageOwnerNickName> findMemberSpacesJoinSpaceImageByCo
return new SliceImpl<>(contents, condition.pageable(), hasNext);
}

private List<SpaceImage> findSpaceImagesBySpaceIds(List<Long> spaceIds) {
return queryFactory
.selectFrom(spaceImage)
.where(spaceImage.space.id.in(spaceIds),
spaceImage.isDeleted.eq(false))
.fetch();
}

private static List<Long> getSpaceIds(List<SpaceAndOwnerNickName> spaceAndOwnerNickNames) {
return spaceAndOwnerNickNames
.stream()
.map(s -> s.space().getId())
.toList();
}

public Slice<SpaceAndSpaceImageOwnerNickName> findPublicSpacesJoinSpaceImageByConditionWithLikeQuery(QueryCondition condition) {
List<SpaceAndOwnerNickName> spaceAndOwnerNickNames = queryFactory
.select(new QSpaceAndOwnerNickName(
Expand All @@ -161,18 +146,16 @@ public Slice<SpaceAndSpaceImageOwnerNickName> findPublicSpacesJoinSpaceImageByCo
dynamicQueryFactory.eqSpaceNameWithLikeQuery(condition.keyWord()),
dynamicQueryFactory.eqCategory(condition.filter())
)
.orderBy(dynamicQueryFactory.spaceSort(condition.pageable()))
.orderBy(space.createdAt.desc())
.offset(condition.pageable().getOffset())
.limit(condition.pageable().getPageSize() + 1)
.fetch();

List<Long> spaceIds = getSpaceIds(spaceAndOwnerNickNames);

List<SpaceImage> spaceImages = findSpaceImagesBySpaceIds(spaceIds);

SpaceAndSpaceImageOwnerNickNames spaceAndSpaceImageOwnerNickNames = SpaceAndSpaceImageOwnerNickNames.of(spaceAndOwnerNickNames, spaceImages);

List<SpaceAndSpaceImageOwnerNickName> contents = spaceAndSpaceImageOwnerNickNames.contents();
List<SpaceAndSpaceImageOwnerNickName> contents = mapper.toSpaceAndSpaceImageOwnerNickNames(spaceAndOwnerNickNames, spaceImages);
;
boolean hasNext = false;

if (contents.size() > condition.pageable().getPageSize()) {
Expand All @@ -182,4 +165,20 @@ public Slice<SpaceAndSpaceImageOwnerNickName> findPublicSpacesJoinSpaceImageByCo

return new SliceImpl<>(contents, condition.pageable(), hasNext);
}
}

private List<SpaceImage> findSpaceImagesBySpaceIds(List<Long> spaceIds) {
return queryFactory
.selectFrom(spaceImage)
.where(spaceImage.space.id.in(spaceIds),
spaceImage.isDeleted.eq(false))
.fetch();
}

private static List<Long> getSpaceIds(List<SpaceAndOwnerNickName> spaceAndOwnerNickNames) {
return spaceAndOwnerNickNames
.stream()
.map(s -> s.space().getId())
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SpaceRegisterInFavoriteResponse createFavorite(Long spaceId, Long memberI

@Transactional
public SpaceRegisterInFavoriteResponse createFavoriteWithLock(Long spaceId, Long memberId) {
Space space = spaceRepository.getByIdWhitLock(spaceId);
Space space = spaceRepository.getByIdWithPessimisticLock(spaceId);

Favorite favorite = mapper.toFavorite(space, memberId);
Favorite savedFavorite = favoriteRepository.save(favorite);
Expand Down

0 comments on commit 32060be

Please sign in to comment.