Skip to content

Commit

Permalink
feat : 피드에 추가 가능한 상품 검색 기능 구현 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jikimomo committed Oct 11, 2022
1 parent 8972229 commit a429f46
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -88,5 +90,29 @@ public ResponseEntity<BaseResponse<FeedDetailResponse>> findFeedDetail(@RequestP
return new ResponseEntity(baseResponse, HttpStatus.OK);
}

@GetMapping("/product")
@ApiOperation("sns 피드에 등록 가능한 상품 목록 조회")
public ResponseEntity<BaseResponse<List<AddableProductResponse>>> findAddableProduct(@ApiIgnore Principal principal){

Long memberId = null;
String memberRole = null;

List<AddableProductResponse> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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<AddableProductResponse> findAddableProductList(@PathVariable("user-no") Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,4 +14,7 @@ public interface ProductServiceClient {

@GetMapping("/api/user/product-service/product/{user-no}")
public List<WishProductListResponse> findWishProductListByMember(@PathVariable("user-no") Long memberId);

@GetMapping("/api/user/product-service/list/add/{seller-no}")
public List<AddableProductResponse> findAddableProductList(@PathVariable("seller-no") Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +33,8 @@ public interface FeedService {

Long uploadFeed(Long memberId, String memberRole, FeedInfoDto feedInfoDto);

List<AddableProductResponse> findAddableProducts(Long memberId, String memberRole);

FeedDetailResponse findFeedDetail(Long feedId);

Boolean upViewCount(Long feedId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -326,6 +332,26 @@ public Long uploadFeed(Long memberId, String memberRole, FeedInfoDto feedInfoDto
return savedFeed.getFeedId();
}

/**
* 피드 업로드할 때 추가 가능한 상품을 조회하는 메서드
* @param memberId, memberRole
* @return List<AddableProductResponse>
*/
@Override
public List<AddableProductResponse> findAddableProducts(Long memberId, String memberRole) {

List<AddableProductResponse> addableProductList = new ArrayList<>();

if(memberRole.equals("user")){
addableProductList = orderServiceClient.findAddableProductList(memberId);
}
else if(memberRole.equals("seller")){
addableProductList = productServiceClient.findAddableProductList(memberId);
}

return addableProductList;
}

/**
* 피드 상세 페이지 조회하는 메서드
* @param feedId
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}

0 comments on commit a429f46

Please sign in to comment.