-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6f496f
commit 1a5ce7a
Showing
4 changed files
with
52 additions
and
34 deletions.
There are no files selected for viewing
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
15 changes: 12 additions & 3 deletions
15
product-order-service/src/main/java/com/example/productorderservice/order/OrderService.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 |
---|---|---|
@@ -1,21 +1,30 @@ | ||
package com.example.productorderservice.order; | ||
|
||
import com.example.productorderservice.product.Product; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Component | ||
@RestController | ||
@RequestMapping("/orders") | ||
class OrderService { | ||
private final OrderPort orderPort; | ||
|
||
OrderService(final OrderPort orderPort) { | ||
this.orderPort = orderPort; | ||
} | ||
|
||
public void createOrder(final CreateOrderRequest request) { | ||
@PostMapping | ||
public ResponseEntity<Void> createOrder(@RequestBody final CreateOrderRequest request) { | ||
final Product product = orderPort.getProductById(request.productId()); | ||
|
||
final Order order = new Order(product, request.quantity()); | ||
|
||
orderPort.save(order); | ||
|
||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
product-order-service/src/test/java/com/example/productorderservice/order/OrderApiTest.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,38 @@ | ||
package com.example.productorderservice.order; | ||
|
||
import com.example.productorderservice.product.ApiTest; | ||
import com.example.productorderservice.product.ProductSteps; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class OrderApiTest extends ApiTest { | ||
|
||
@Test | ||
void 상품주문() { | ||
ProductSteps.requestAddProduct(ProductSteps.getAddProductRequest()); | ||
final CreateOrderRequest request = getCreateOrderRequest(); | ||
|
||
final ExtractableResponse<Response> response = RestAssured.given().log().all() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(request) | ||
.when() | ||
.post("/orders") | ||
.then() | ||
.log().all().extract(); | ||
|
||
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value()); | ||
} | ||
|
||
private static CreateOrderRequest getCreateOrderRequest() { | ||
final long productId = 1L; | ||
final int quantity = 2; | ||
return new CreateOrderRequest(productId, quantity); | ||
} | ||
|
||
} |
31 changes: 0 additions & 31 deletions
31
...t-order-service/src/test/java/com/example/productorderservice/order/OrderServiceTest.java
This file was deleted.
Oops, something went wrong.