Skip to content

Commit

Permalink
🐛 fix(api): cannot find user items filtered by location
Browse files Browse the repository at this point in the history
  • Loading branch information
siyeonSon committed Dec 29, 2024
1 parent 364d49c commit d30f7d1
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
@RequiredArgsConstructor
public class ItemRepositoryImpl implements QueryDslItemRepository {


private final JPAQueryFactory queryFactory;

@Override
Expand All @@ -41,7 +40,7 @@ public List<ItemDao> findByUserId(Long userId, long lastCursor, ItemOrderType or
var isLikedSubQuery = JPAExpressions.select(itemLike.id)
.from(itemLike)
.where(itemLike.item.id.eq(item.id)
.and(itemLike.user.id.eq(userId)));
.and(itemLike.user.id.eq(userId)));

var query = queryFactory.select(
Projections.constructor(
Expand Down Expand Up @@ -78,10 +77,15 @@ public List<ItemDao> findByUserIdAndState(Long userId, long lastCursor, ItemOrde
DateExpression<Date> currentWeekExpr = currentDate();
DateTimePath<LocalDateTime> createdAtExpr = item.createdAt;

var isLikedSubQuery = JPAExpressions.select(itemLike.id)
.from(itemLike)
.where(itemLike.item.id.eq(item.id)
.and(itemLike.user.id.eq(userId)));

var query = queryFactory.select(
Projections.constructor(
ItemDao.class,
orderType == ItemOrderType.MOST_LIKED ? Expressions.constant(1): createdAtExpr.week().subtract(currentWeekExpr.week()).abs().as("weekAgo"),
orderType == ItemOrderType.MOST_LIKED ? Expressions.constant(1) : createdAtExpr.week().subtract(currentWeekExpr.week()).abs().as("weekAgo"),
item.id,
item.content,
item.createdAt,
Expand All @@ -91,7 +95,7 @@ public List<ItemDao> findByUserIdAndState(Long userId, long lastCursor, ItemOrde
artist.name.as("artistName"),
albumCover.albumThumbnail.as("albumThumbnail"),
itemLike.count().as("itemCount"),
itemLike.user.id.eq(userId).as("isLiked")
isLikedSubQuery.exists().as("isLiked")
)
).from(item)
.join(itemLocation).on(item.id.eq(itemLocation.item.id))
Expand All @@ -115,6 +119,11 @@ public List<ItemDao> findByUserIdAndCity(Long userId, long lastCursor, ItemOrder
DateExpression<Date> currentWeekExpr = currentDate();
DateTimePath<LocalDateTime> createdAtExpr = item.createdAt;

var isLikedSubQuery = JPAExpressions.select(itemLike.id)
.from(itemLike)
.where(itemLike.item.id.eq(item.id)
.and(itemLike.user.id.eq(userId)));

var query = queryFactory.select(
Projections.constructor(
ItemDao.class,
Expand All @@ -128,7 +137,7 @@ public List<ItemDao> findByUserIdAndCity(Long userId, long lastCursor, ItemOrder
artist.name.as("artistName"),
albumCover.albumThumbnail.as("albumThumbnail"),
itemLike.count().as("itemCount"),
itemLike.user.id.eq(userId).as("isLiked")
isLikedSubQuery.exists().as("isLiked")
)
).from(item)
.join(itemLocation).on(item.id.eq(itemLocation.item.id))
Expand Down

0 comments on commit d30f7d1

Please sign in to comment.