-
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
3f30f76
commit 001dc06
Showing
5 changed files
with
52 additions
and
33 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
14 changes: 11 additions & 3 deletions
14
...t-order-service/src/main/java/com/example/productorderservice/payment/PaymentService.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,22 +1,30 @@ | ||
package com.example.productorderservice.payment; | ||
|
||
import com.example.productorderservice.order.Order; | ||
import org.springframework.stereotype.Component; | ||
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("/payments") | ||
class PaymentService { | ||
private final PaymentPort paymentPort; | ||
|
||
PaymentService(final PaymentPort paymentPort) { | ||
this.paymentPort = paymentPort; | ||
} | ||
|
||
public void payment(final PaymentRequest request) { | ||
@PostMapping | ||
public ResponseEntity<Void> payment(@RequestBody final PaymentRequest request) { | ||
Order order = paymentPort.getOrder(request.orderId()); | ||
|
||
final Payment payment = new Payment(order, request.cardNumber()); | ||
|
||
paymentPort.pay(payment.getPrice(), payment.getCardNumber()); | ||
paymentPort.save(payment); | ||
|
||
return ResponseEntity.ok().build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...t-order-service/src/test/java/com/example/productorderservice/payment/PaymentApiTest.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.example.productorderservice.payment; | ||
|
||
import com.example.productorderservice.order.OrderSteps; | ||
import com.example.productorderservice.product.ApiTest; | ||
import com.example.productorderservice.product.ProductSteps; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class PaymentApiTest extends ApiTest { | ||
|
||
@Test | ||
void 상품주문() { | ||
ProductSteps.requestAddProduct(ProductSteps.getAddProductRequest()); | ||
OrderSteps.requestCreateOrder(OrderSteps.getCreateOrderRequest()); | ||
final var request = PaymentSteps.getPaymentRequest(); | ||
|
||
final var response = PaymentSteps.requestPayment(request); | ||
|
||
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); | ||
} | ||
|
||
} |
30 changes: 0 additions & 30 deletions
30
...der-service/src/test/java/com/example/productorderservice/payment/PaymentServiceTest.java
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
...uct-order-service/src/test/java/com/example/productorderservice/payment/PaymentSteps.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,9 +1,24 @@ | ||
package com.example.productorderservice.payment; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import org.springframework.http.MediaType; | ||
|
||
public class PaymentSteps { | ||
public static PaymentRequest getPaymentRequest() { | ||
final long orderId = 1L; | ||
final String cardNumber = "1234-1234-1234"; | ||
return new PaymentRequest(orderId, cardNumber); | ||
} | ||
|
||
static ExtractableResponse<Response> requestPayment(final PaymentRequest request) { | ||
return RestAssured.given().log().all() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(request) | ||
.when() | ||
.post("/payments") | ||
.then().log().all() | ||
.extract(); | ||
} | ||
} |