diff --git a/src/main/java/com/team6/onandthefarmsnsservice/controller/YwController.java b/src/main/java/com/team6/onandthefarmsnsservice/controller/FeedContentController.java similarity index 74% rename from src/main/java/com/team6/onandthefarmsnsservice/controller/YwController.java rename to src/main/java/com/team6/onandthefarmsnsservice/controller/FeedContentController.java index 5e93131..68dcb01 100644 --- a/src/main/java/com/team6/onandthefarmsnsservice/controller/YwController.java +++ b/src/main/java/com/team6/onandthefarmsnsservice/controller/FeedContentController.java @@ -1,8 +1,10 @@ package com.team6.onandthefarmsnsservice.controller; import com.team6.onandthefarmsnsservice.dto.FeedInfoDto; +import com.team6.onandthefarmsnsservice.feignclient.ProductServiceClient; import com.team6.onandthefarmsnsservice.service.FeedService; import com.team6.onandthefarmsnsservice.utils.BaseResponse; +import com.team6.onandthefarmsnsservice.vo.feed.AddableProductResponse; import com.team6.onandthefarmsnsservice.vo.feed.FeedDetailResponse; import com.team6.onandthefarmsnsservice.vo.feed.FeedUploadProductRequest; import com.team6.onandthefarmsnsservice.vo.feed.FeedUploadRequest; @@ -19,12 +21,12 @@ @RestController @RequestMapping("/api/user/sns") -public class YwController { +public class FeedContentController { private final FeedService feedService; @Autowired - public YwController(FeedService feedService){ + public FeedContentController(FeedService feedService){ this.feedService = feedService; } @@ -88,5 +90,29 @@ public ResponseEntity> findFeedDetail(@RequestP return new ResponseEntity(baseResponse, HttpStatus.OK); } + @GetMapping("/product") + @ApiOperation("sns 피드에 등록 가능한 상품 목록 조회") + public ResponseEntity>> findAddableProduct(@ApiIgnore Principal principal){ + + Long memberId = null; + String memberRole = null; + + List addableProductList = feedService.findAddableProducts(memberId, memberRole); + + BaseResponse baseResponse = BaseResponse.builder() + .httpStatus(HttpStatus.OK) + .message("find product success") + .data(addableProductList) + .build(); + if(addableProductList == null){ + baseResponse = BaseResponse.builder() + .httpStatus(HttpStatus.BAD_REQUEST) + .message("find product fail") + .build(); + return new ResponseEntity(baseResponse, HttpStatus.BAD_REQUEST); + } + + return new ResponseEntity(baseResponse, HttpStatus.OK); + } } diff --git a/src/main/java/com/team6/onandthefarmsnsservice/feignclient/OrderServiceClient.java b/src/main/java/com/team6/onandthefarmsnsservice/feignclient/OrderServiceClient.java new file mode 100644 index 0000000..719cab5 --- /dev/null +++ b/src/main/java/com/team6/onandthefarmsnsservice/feignclient/OrderServiceClient.java @@ -0,0 +1,15 @@ +package com.team6.onandthefarmsnsservice.feignclient; + +import com.team6.onandthefarmsnsservice.vo.feed.AddableProductResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +import java.util.List; + +@FeignClient(name = "order-service") +public interface OrderServiceClient { + + @GetMapping("/api/user/order-service/list/add/{user-no}") + public List findAddableProductList(@PathVariable("user-no") Long memberId); +} diff --git a/src/main/java/com/team6/onandthefarmsnsservice/feignclient/ProductServiceClient.java b/src/main/java/com/team6/onandthefarmsnsservice/feignclient/ProductServiceClient.java index fb74be8..48b53ff 100644 --- a/src/main/java/com/team6/onandthefarmsnsservice/feignclient/ProductServiceClient.java +++ b/src/main/java/com/team6/onandthefarmsnsservice/feignclient/ProductServiceClient.java @@ -2,6 +2,7 @@ import java.util.List; +import com.team6.onandthefarmsnsservice.vo.feed.AddableProductResponse; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -13,4 +14,7 @@ public interface ProductServiceClient { @GetMapping("/api/user/product-service/product/{user-no}") public List findWishProductListByMember(@PathVariable("user-no") Long memberId); + + @GetMapping("/api/user/product-service/list/add/{seller-no}") + public List findAddableProductList(@PathVariable("seller-no") Long memberId); } diff --git a/src/main/java/com/team6/onandthefarmsnsservice/service/FeedService.java b/src/main/java/com/team6/onandthefarmsnsservice/service/FeedService.java index f18c7b0..8ddd4f8 100644 --- a/src/main/java/com/team6/onandthefarmsnsservice/service/FeedService.java +++ b/src/main/java/com/team6/onandthefarmsnsservice/service/FeedService.java @@ -6,13 +6,13 @@ import com.team6.onandthefarmsnsservice.dto.profile.ProfileMainFeedDto; import com.team6.onandthefarmsnsservice.dto.profile.ProfileMainScrapDto; import com.team6.onandthefarmsnsservice.dto.profile.ProfileMainWishDto; +import com.team6.onandthefarmsnsservice.vo.feed.AddableProductResponse; import com.team6.onandthefarmsnsservice.vo.feed.FeedDetailResponse; import com.team6.onandthefarmsnsservice.vo.FeedResponse; import com.team6.onandthefarmsnsservice.dto.FeedInfoDto; import com.team6.onandthefarmsnsservice.vo.profile.ProfileMainFeedResponse; import com.team6.onandthefarmsnsservice.vo.profile.ProfileMainScrapResponse; import com.team6.onandthefarmsnsservice.vo.profile.ProfileMainWishResponse; -import com.team6.onandthefarmsnsservice.vo.profile.product.ProductWishResponse; import com.team6.onandthefarmsnsservice.vo.profile.product.WishProductListResponse; import java.util.List; @@ -33,6 +33,8 @@ public interface FeedService { Long uploadFeed(Long memberId, String memberRole, FeedInfoDto feedInfoDto); + List findAddableProducts(Long memberId, String memberRole); + FeedDetailResponse findFeedDetail(Long feedId); Boolean upViewCount(Long feedId); diff --git a/src/main/java/com/team6/onandthefarmsnsservice/service/FeedServiceImpl.java b/src/main/java/com/team6/onandthefarmsnsservice/service/FeedServiceImpl.java index d7e3e27..361fbe4 100644 --- a/src/main/java/com/team6/onandthefarmsnsservice/service/FeedServiceImpl.java +++ b/src/main/java/com/team6/onandthefarmsnsservice/service/FeedServiceImpl.java @@ -8,8 +8,10 @@ import com.team6.onandthefarmsnsservice.dto.profile.ProfileMainWishDto; import com.team6.onandthefarmsnsservice.entity.*; import com.team6.onandthefarmsnsservice.feignclient.MemberServiceClient; +import com.team6.onandthefarmsnsservice.feignclient.OrderServiceClient; import com.team6.onandthefarmsnsservice.feignclient.ProductServiceClient; import com.team6.onandthefarmsnsservice.repository.*; +import com.team6.onandthefarmsnsservice.vo.feed.AddableProductResponse; import com.team6.onandthefarmsnsservice.vo.feed.FeedDetailResponse; import com.team6.onandthefarmsnsservice.vo.FeedResponse; import com.team6.onandthefarmsnsservice.vo.feed.imageProduct.ImageInfo; @@ -48,6 +50,8 @@ public class FeedServiceImpl implements FeedService { private final ProductServiceClient productServiceClient; + private final OrderServiceClient orderServiceClient; + private final FeedImageRepository feedImageRepository; private final FeedLikeRepository feedLikeRepository; @@ -66,6 +70,7 @@ public class FeedServiceImpl implements FeedService { public FeedServiceImpl(FeedRepository feedRepository, MemberServiceClient memberServiceClient, ProductServiceClient productServiceClient, + OrderServiceClient orderServiceClient, FeedImageRepository feedImageRepository, FeedLikeRepository feedLikeRepository, ScrapRepository scrapRepository, @@ -79,6 +84,7 @@ public FeedServiceImpl(FeedRepository feedRepository, this.feedRepository = feedRepository; this.memberServiceClient = memberServiceClient; this.productServiceClient = productServiceClient; + this.orderServiceClient = orderServiceClient; this.feedImageRepository = feedImageRepository; this.feedImageProductRepository = feedImageProductRepository; this.feedTagRepository = feedTagRepository; @@ -326,6 +332,26 @@ public Long uploadFeed(Long memberId, String memberRole, FeedInfoDto feedInfoDto return savedFeed.getFeedId(); } + /** + * 피드 업로드할 때 추가 가능한 상품을 조회하는 메서드 + * @param memberId, memberRole + * @return List + */ + @Override + public List findAddableProducts(Long memberId, String memberRole) { + + List addableProductList = new ArrayList<>(); + + if(memberRole.equals("user")){ + addableProductList = orderServiceClient.findAddableProductList(memberId); + } + else if(memberRole.equals("seller")){ + addableProductList = productServiceClient.findAddableProductList(memberId); + } + + return addableProductList; + } + /** * 피드 상세 페이지 조회하는 메서드 * @param feedId diff --git a/src/main/java/com/team6/onandthefarmsnsservice/vo/feed/AddableProductResponse.java b/src/main/java/com/team6/onandthefarmsnsservice/vo/feed/AddableProductResponse.java new file mode 100644 index 0000000..70e732a --- /dev/null +++ b/src/main/java/com/team6/onandthefarmsnsservice/vo/feed/AddableProductResponse.java @@ -0,0 +1,16 @@ +package com.team6.onandthefarmsnsservice.vo.feed; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class AddableProductResponse { + + private Long productId; + private String productName; + private String productMainImgSrc; + private Integer productPrice; + private String sellerShopName; + +}