Skip to content

Commit

Permalink
Merge pull request #56 from kea-dpang/develop
Browse files Browse the repository at this point in the history
Feat: 상품 리스트 조회 API 구현
  • Loading branch information
namsh1125 authored Feb 5, 2024
2 parents 9c766f7 + e1a8233 commit 27e4a4c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
7 changes: 5 additions & 2 deletions src/main/java/kea/dpang/item/controller/ItemController.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ public ResponseEntity<SuccessResponse<Page<ItemDetailDto>>> getItemList(
public ResponseEntity<SuccessResponse<List<ItemDto>>> getItemList(
@RequestBody GetItemListRequestDto dto
) {
// Todo: 상품 리스트로 조회
List<ItemDto> itemList = itemService.getItemList(dto.getItemIds());

return null;
return new ResponseEntity<>(
new SuccessResponse<>(HttpStatus.OK.value(), "상품 리스트가 조회되었습니다.", itemList),
HttpStatus.OK
);
}


Expand Down
20 changes: 10 additions & 10 deletions src/main/java/kea/dpang/item/dto/item/ItemDetailDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@
@NoArgsConstructor
@AllArgsConstructor
public class ItemDetailDto {
private Long itemId;
private String itemName;
private Long id;
private String name;
private Long sellerId;
private String sellerName;
private Category category;
private SubCategory subCategory;
private int itemPrice;
private int price;
private float averageRating;
private int discountRate;
private int discountPrice;
private String description;
private int stockQuantity;
private String itemImage;
private List<String> images;
private String thumbnailImage;
private List<String> informationImages;

public ItemDetailDto(Item item, String sellerName) {
this.itemId = item.getId();
this.itemName = item.getName();
this.id = item.getId();
this.name = item.getName();
this.sellerId = item.getSellerId();
this.sellerName = sellerName;
this.category = item.getCategory();
this.subCategory = item.getSubCategory();
this.itemPrice = item.getPrice();
this.price = item.getPrice();
this.averageRating = item.getAverageRating();
this.discountRate = item.getDiscountRate();
this.discountPrice = item.getDiscountPrice();
this.description = item.getDescription();
this.stockQuantity = item.getStockQuantity();
this.itemImage = item.getThumbnailImage();
this.images = item.getInformationImages();
this.thumbnailImage = item.getThumbnailImage();
this.informationImages = item.getInformationImages();
}
}

15 changes: 13 additions & 2 deletions src/main/java/kea/dpang/item/dto/item/ItemDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kea.dpang.item.dto.item;

import kea.dpang.item.entity.Item;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -8,11 +9,21 @@
@AllArgsConstructor
@NoArgsConstructor
public class ItemDto {
private Long itemId; // 상품 ID
private String image; // 상품 이미지 URL
private Long id; // 상품 ID
private String thumbnailImage; // 상품 이미지 URL
private String name; // 상품 이름
private int price; // 상품 정가
private int quantity; // 상품 재고 수량
private int discountRate; // 할인율
private int discountPrice; // 상품 판매가

public ItemDto(Item item) {
this.id = item.getId();
this.thumbnailImage = item.getThumbnailImage();
this.name = item.getName();
this.price = item.getPrice();
this.quantity = item.getStockQuantity();
this.discountRate = item.getDiscountRate();
this.discountPrice = item.getDiscountPrice();
}
}
12 changes: 5 additions & 7 deletions src/main/java/kea/dpang/item/service/ItemService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package kea.dpang.item.service;

import kea.dpang.item.dto.item.CreateItemRequestDto;
import kea.dpang.item.dto.item.ItemDetailDto;
import kea.dpang.item.dto.item.UpdateItemRequestDto;
import kea.dpang.item.dto.item.UpdateStockRequestDto;
import kea.dpang.item.dto.item.*;
import kea.dpang.item.entity.Category;
import kea.dpang.item.entity.SubCategory;
import org.springframework.data.domain.Page;
Expand All @@ -28,7 +25,8 @@ public interface ItemService {
*/
ItemDetailDto getItem(Long itemId);

// Todo: 필터링 상품 리스트 조회
List<ItemDto> getItemList(List<Long> itemIds);

Page<ItemDetailDto> getItemList(
Category category,
SubCategory subCategory,
Expand All @@ -44,8 +42,8 @@ Page<ItemDetailDto> getItemList(
/**
* 상품의 정보를 업데이트합니다.
*
* @param itemId 업데이트할 상품의 ID
* @param dto 업데이트할 상품의 정보가 담긴 DTO
* @param itemId 업데이트할 상품의 ID
* @param dto 업데이트할 상품의 정보가 담긴 DTO
*/
void updateItem(Long itemId, UpdateItemRequestDto dto);

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/kea/dpang/item/service/ItemServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package kea.dpang.item.service;

import kea.dpang.item.dto.item.CreateItemRequestDto;
import kea.dpang.item.dto.item.ItemDetailDto;
import kea.dpang.item.dto.item.UpdateItemRequestDto;
import kea.dpang.item.dto.item.UpdateStockRequestDto;
import kea.dpang.item.dto.item.*;
import kea.dpang.item.entity.Category;
import kea.dpang.item.entity.Item;
import kea.dpang.item.entity.SubCategory;
Expand Down Expand Up @@ -47,6 +44,15 @@ public void createItem(CreateItemRequestDto dto) {
}
}

@Override
public List<ItemDto> getItemList(List<Long> itemIds) {
log.info("item ID 리스트로부터 아이템 리스트 조회를 시작합니다 : {}", itemIds);
return itemRepository.findAllById(itemIds)
.stream()
.map(ItemDto::new)
.toList();
}

// 상품 상세 정보 조회
@Override
@Transactional(readOnly = true)
Expand Down

0 comments on commit 27e4a4c

Please sign in to comment.