-
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
1a5ce7a
commit abe8fae
Showing
5 changed files
with
44 additions
and
40 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
23 changes: 13 additions & 10 deletions
23
product-order-service/src/main/java/com/example/productorderservice/order/Order.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,25 +1,28 @@ | ||
package com.example.productorderservice.order; | ||
|
||
import com.example.productorderservice.product.Product; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.util.Assert; | ||
|
||
@Entity | ||
@Table(name = "orders") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
class Order { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private final Product product; | ||
private final int quantity; | ||
@OneToOne | ||
private Product product; | ||
private int quantity; | ||
|
||
public Order(final Product product, final int quantity) { | ||
Assert.notNull(product, "상품은 필수입니다."); | ||
Assert.isTrue(quantity > 0, "수량은 0보다 커야 합니다."); | ||
this.product = product; | ||
this.quantity = quantity; | ||
} | ||
|
||
public void assignId(final Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
} |
15 changes: 2 additions & 13 deletions
15
...ct-order-service/src/main/java/com/example/productorderservice/order/OrderRepository.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,17 +1,6 @@ | ||
package com.example.productorderservice.order; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Repository | ||
class OrderRepository { | ||
private Map<Long, Order> persistence = new HashMap<>(); | ||
private Long sequance = 0L; | ||
|
||
public void save(final Order order) { | ||
order.assignId(++sequance); | ||
persistence.put(order.getId(), order); | ||
} | ||
interface OrderRepository extends JpaRepository<Order, Long> { | ||
} |
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
24 changes: 24 additions & 0 deletions
24
product-order-service/src/test/java/com/example/productorderservice/order/OrderSteps.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.order; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import org.springframework.http.MediaType; | ||
|
||
public class OrderSteps { | ||
public static final ExtractableResponse<Response> requestCreateOrder(final CreateOrderRequest request) { | ||
return RestAssured.given().log().all() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(request) | ||
.when() | ||
.post("/orders") | ||
.then() | ||
.log().all().extract(); | ||
} | ||
|
||
public static final CreateOrderRequest getCreateOrderRequest() { | ||
final long productId = 1L; | ||
final int quantity = 2; | ||
return new CreateOrderRequest(productId, quantity); | ||
} | ||
} |