-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from lotteon2/O2F-476/feat/OOTD-feign
- Loading branch information
Showing
7 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/com/dailyon/productservice/product/controller/ProductFeignController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.dailyon.productservice.product.controller; | ||
|
||
import com.dailyon.productservice.product.dto.response.ReadOOTDProductListResponse; | ||
import com.dailyon.productservice.product.service.ProductService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/clients") | ||
@RequiredArgsConstructor | ||
public class ProductFeignController { | ||
private final ProductService productService; | ||
|
||
@GetMapping("/post-image/products") | ||
ResponseEntity<ReadOOTDProductListResponse> readOOTDProductDetail(@RequestParam List<Long> id) { | ||
return ResponseEntity.status(HttpStatus.OK).body(productService.readOOTDProductDetails(id)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ain/java/com/dailyon/productservice/product/dto/response/ReadOOTDProductListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.dailyon.productservice.product.dto.response; | ||
|
||
import com.dailyon.productservice.product.entity.Product; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@Builder | ||
public class ReadOOTDProductListResponse { | ||
private List<ReadOOTDProductResponse> productInfos; | ||
|
||
public static ReadOOTDProductListResponse fromEntity(List<Product> products) { | ||
return ReadOOTDProductListResponse.builder() | ||
.productInfos(products.stream() | ||
.map(ReadOOTDProductResponse::fromEntity) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/dailyon/productservice/product/dto/response/ReadOOTDProductResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.dailyon.productservice.product.dto.response; | ||
|
||
import com.dailyon.productservice.product.entity.Product; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class ReadOOTDProductResponse { | ||
private Long id; | ||
private String name; | ||
private String brandName; | ||
private String imgUrl; | ||
private Integer price; | ||
|
||
public static ReadOOTDProductResponse fromEntity(Product product) { | ||
return ReadOOTDProductResponse.builder() | ||
.id(product.getId()) | ||
.brandName(product.getBrand().getName()) | ||
.imgUrl(product.getImgUrl()) | ||
.price(product.getPrice()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/com/dailyon/productservice/controller/product/ProductFeignControllerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.dailyon.productservice.controller.product; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
@AutoConfigureMockMvc | ||
@ActiveProfiles(value = {"test"}) | ||
public class ProductFeignControllerTests { | ||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@Test | ||
@DisplayName("query parameter를 반드시 입력해야 한다") | ||
void readOOTDProductDetailFail() throws Exception { | ||
// given, when | ||
ResultActions resultActions = mockMvc.perform( | ||
get("/clients/post-image/products") | ||
); | ||
|
||
// then | ||
resultActions.andExpect(MockMvcResultMatchers.status().isBadRequest()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters