Skip to content

Commit

Permalink
Merge branch 'PracLee' into PracLee-1
Browse files Browse the repository at this point in the history
  • Loading branch information
PracLee authored Apr 14, 2024
2 parents 4af58f2 + 95e9d78 commit 9801d5a
Show file tree
Hide file tree
Showing 24 changed files with 47 additions and 33 deletions.
Binary file added data/0EM4WYA2J5CQN.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/0EM530M9P227X.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/0EM54PYMJXCJB.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/0EM54TXH2XF1X.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/0EM56D51YF36H.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/0EM57WG3AKNE0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/0EM594V1Q3PQ6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/0EM5AW6MB4KVR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/0EM5HTN2XHN99.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public CreateProductService(ProductRepository productRepository) {

public Product createProduct(String name, Money price, String imageUrl) {
Product product = Product.create(name, price, imageUrl);

productRepository.save(product);

return product;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("products")
@CrossOrigin
Expand All @@ -33,8 +35,10 @@ public ProductListDto list() {

@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void create(@ModelAttribute CreateProductDto dto) {
public void create(@ModelAttribute CreateProductDto dto)
throws IOException {
String name = dto.name().strip();
String imageUrl = imageStorage.save(dto.image());
Money price = new Money(dto.price());
String imageUrl = imageStorage.save(dto.image());
createProductService.createProduct(name, price, imageUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CartDto fetchCartDto(CartId cartId) {
String sql = """
SELECT
*,
products.name AS product_name
products.name AS product_name2
FROM line_items
JOIN products ON line_items.product_id = products.id
WHERE line_items.cart_id = ?
Expand All @@ -31,7 +31,7 @@ public CartDto fetchCartDto(CartId cartId) {
sql,
(ResultSet resultSet, int rowNum) -> new CartDto.LineItemDto(
resultSet.getString("id"),
resultSet.getString("product_name"),
resultSet.getString("product_name2"),
resultSet.getLong("unit_price"),
resultSet.getInt("quantity"),
resultSet.getLong("total_price")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/models/Cart.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Cart {
@UpdateTimestamp
private LocalDateTime updatedAt;

private Cart() {
protected Cart() {
}

public Cart(CartId cartId) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/models/CartId.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class CartId extends EntityId {
// TODO: Delete this! (카트가 하나만 존재한다고 가정)
public static final CartId DEFAULT = new CartId("0BV000000CART");

private CartId() {
protected CartId() {
super();
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/example/demo/models/EntityId.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;

import java.io.Serializable;
import java.util.Objects;

@MappedSuperclass
public abstract class EntityId {
public abstract class EntityId implements Serializable {
@Column(name = "id")
private String value;

protected EntityId() {
public EntityId() {
}

protected EntityId(String value) {
public EntityId(String value) {
this.value = value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/models/LineItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LineItem {
@UpdateTimestamp
private LocalDateTime updatedAt;

private LineItem() {
protected LineItem() {
}

public LineItem(LineItemId id, Product product, int quantity) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/example/demo/models/LineItemId.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.demo.models;

import jakarta.persistence.Embeddable;

@Embeddable
public class LineItemId extends EntityId {
private LineItemId() {
public LineItemId() {
super();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/models/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Money {
@Column(name = "money")
private Long value;

private Money() {
public Money() {

}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/example/demo/models/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public class Product {
@AttributeOverride(name = "value", column = @Column(name = "price"))
private Money price;

private Product() {
public Product() {
}

public Product(ProductId id, String name, Money price, String imageUrl) {
this.id = id;
this.name = name;
this.imageUrl = imageUrl;
this.price = price;
this.imageUrl = imageUrl;
}
Expand All @@ -50,6 +51,9 @@ public String name() {
return name;
}

public String imageUrl() {
return imageUrl;
}
public Money price() {
return price;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/example/demo/models/ProductId.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.demo.models;

import jakarta.persistence.Embeddable;

@Embeddable
public class ProductId extends EntityId {
private ProductId() {
public ProductId() {
super();
}

Expand Down
11 changes: 7 additions & 4 deletions src/test/java/com/example/demo/Fixtures.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ public static Product product() {
public static Product product(int number) {
ProductId productId = new ProductId("012300000000" + number);
return new Product(
productId, "Product #" + number, new Money(123_000L));
productId, "Product #" + number,
"IMAGE_URL",
new Money(123_000L)
);
}

public static Cart cart() {
return cart(List.of());
}
public static Cart cart() {
return cart(List.of());
}

public static Cart cart(List<Product> products) {
CartId cartId = new CartId("0124000000001");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ void setUp() {
@Test
void createProduct() {
String name = "제-품";
String imageUrl = "IMAGE_URL";
Money price = new Money(100_000L);
String imageUrl = "IMAGE_URL";

Product product = createProductService.createProduct(name, price, imageUrl);

assertThat(product.name()).isEqualTo(name);
assertThat(product.imageUrl()).isEqualTo(imageUrl);
assertThat(product.price()).isEqualTo(price);
assertThat(product.imageUrl()).isEqualTo(imageUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
Expand All @@ -20,8 +21,7 @@
import static com.example.demo.controllers.helpers.ResultMatchers.contentContains;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(ProductController.class)
Expand Down Expand Up @@ -59,18 +59,7 @@ void create() throws Exception {
String filename = "src/test/resources/files/test.jpg";
MockMultipartFile file = new MockMultipartFile(
"image", "test.jpg", "image/jpeg",
new FileInputStream(filename)
);

String json = String.format(
"""
{
"name": "멋진 제품",
"price": %d
}
""",
100_000L
);
new FileInputStream(filename));

given(imageStorage.save(file)).willReturn("data/image.jpg");

Expand Down
7 changes: 6 additions & 1 deletion src/test/java/com/example/demo/models/ProductTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
class ProductTest {
@Test
void creation() {
Product product = Product.create("제품명", new Money(123_456L));
Product product = Product.create(
"제품명",
"IMAGE_URL",
new Money(123_456L)
);

assertThat(product.id()).isNotNull();
assertThat(product.name()).isEqualTo("제품명");
assertThat(product.imageUrl()).isEqualTo("IMAGE_URL");
assertThat(product.price()).isEqualTo(new Money(123_456L));
}
}

0 comments on commit 9801d5a

Please sign in to comment.