Skip to content

Commit 8df26b2

Browse files
authored
Merge pull request #395 from 7-umc-GrowIT/refactor/#394
[#394] Refactor: 카테고리별 아이템 조회 시 가격 오름차순 정렬
2 parents e30c89a + 653a722 commit 8df26b2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/main/java/umc/GrowIT/Server/repository/ItemRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import java.util.Optional;
1111

1212
public interface ItemRepository extends JpaRepository<Item, Long> {
13-
List<Item> findAllByCategory(ItemCategory category);
13+
// 카테고리별 아이템 조회
14+
@Query("SELECT i FROM Item i WHERE i.category = :category ORDER BY i.price ASC")
15+
List<Item> findAllByCategoryOrderByPriceAtAsc(ItemCategory category);
1416

1517
// UserItem을 통해 현재 사용자의 특정 아이템 구매여부 판별
1618
boolean existsByUserItemsUserIdAndId(Long userId, Long itemId);

src/main/java/umc/GrowIT/Server/service/itemService/ItemQueryServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ItemQueryServiceImpl implements ItemQueryService {
3030
@Override
3131
@Transactional(readOnly = true)
3232
public ItemResponseDTO.ItemListDTO getItemList(ItemCategory category, Long userId) {
33-
List<Item> itemList = itemRepository.findAllByCategory(category);
33+
List<Item> itemList = itemRepository.findAllByCategoryOrderByPriceAtAsc(category);
3434

3535
// status 조회 - null 처리 추가
3636
Map<Long, ItemStatus> itemStatuses = new HashMap<>();

0 commit comments

Comments
 (0)