-
Notifications
You must be signed in to change notification settings - Fork 177
๐ 1๋จ๊ณ - ๋ฆฌํฉํฐ๋ง(์ํ) #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: nomoreft
Are you sure you want to change the base?
Changes from 6 commits
1ce635f
7f3a747
28bb200
6626e1a
54e1cce
ef2b0b9
4696cff
5bd913b
956a3f4
4061ecb
893b1e9
a8f25d6
5d63264
cae28ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| mysql: | ||
| image: mysql:8.0 | ||
| container_name: kitchenpos-mysql | ||
| restart: always | ||
| environment: | ||
| MYSQL_ROOT_PASSWORD: root | ||
| MYSQL_DATABASE: kitchenpos | ||
| MYSQL_USER: user | ||
| MYSQL_PASSWORD: password | ||
| ports: | ||
| - "33306:3306" | ||
| command: --default-authentication-plugin=mysql_native_password | ||
| volumes: | ||
| - mysql_data:/var/lib/mysql | ||
|
|
||
| volumes: | ||
| mysql_data: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| import kitchenpos.menus.domain.MenuRepository; | ||
| import kitchenpos.products.domain.Product; | ||
| import kitchenpos.products.domain.ProductRepository; | ||
| import kitchenpos.products.infra.PurgomalumClient; | ||
| import kitchenpos.shared.domain.ProfanityChecker; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
|
|
@@ -19,16 +19,16 @@ | |
| public class ProductService { | ||
| private final ProductRepository productRepository; | ||
| private final MenuRepository menuRepository; | ||
| private final PurgomalumClient purgomalumClient; | ||
| private final ProfanityChecker profanityChecker; | ||
|
|
||
| public ProductService( | ||
| final ProductRepository productRepository, | ||
| final MenuRepository menuRepository, | ||
| final PurgomalumClient purgomalumClient | ||
| final ProfanityChecker profanityChecker | ||
| ) { | ||
| this.productRepository = productRepository; | ||
| this.menuRepository = menuRepository; | ||
| this.purgomalumClient = purgomalumClient; | ||
| this.profanityChecker = profanityChecker; | ||
| } | ||
|
|
||
| @Transactional | ||
|
|
@@ -38,7 +38,7 @@ public Product create(final Product request) { | |
| throw new IllegalArgumentException(); | ||
| } | ||
| final String name = request.getName(); | ||
| if (Objects.isNull(name) || purgomalumClient.containsProfanity(name)) { | ||
| if (Objects.isNull(name) || profanityChecker.containsProfanity(name)) { | ||
|
||
| throw new IllegalArgumentException(); | ||
| } | ||
| final Product product = new Product(); | ||
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package kitchenpos.products.infra; | ||
|
|
||
| import kitchenpos.products.tobe.domain.Product; | ||
| import kitchenpos.products.tobe.domain.ProductId; | ||
| import kitchenpos.products.tobe.domain.TobeProductRepository; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface TobeJpaProductRepository extends TobeProductRepository, JpaRepository<Product, ProductId> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package kitchenpos.products.tobe.domain; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import kitchenpos.shared.domain.DomainEntity; | ||
| import kitchenpos.shared.domain.Money; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Objects; | ||
| import java.util.UUID; | ||
|
|
||
| @Table(name = "product_tobe") | ||
| @Entity(name = "ProductTobe") | ||
| public class Product extends DomainEntity<Product, ProductId> { | ||
|
|
||
| @EmbeddedId | ||
| @AttributeOverride(name = "value", column = @Column(name = "id")) | ||
| private ProductId id; | ||
|
|
||
| @Embedded | ||
| @AttributeOverride(name = "name", column = @Column(name = "name", nullable = false)) | ||
| private ProductName name; | ||
|
|
||
| @Embedded | ||
| @AttributeOverride(name = "price", column = @Column(name = "price", nullable = false)) | ||
| private ProductPrice price; | ||
|
|
||
| @SuppressWarnings("unused") | ||
| protected Product() {} | ||
|
|
||
| private Product(ProductId id, ProductName name, ProductPrice price) { | ||
| this.id = Objects.requireNonNull(id, "id must not be null"); | ||
| this.name = Objects.requireNonNull(name, "name must not be null"); | ||
| this.price = Objects.requireNonNull(price, "price must not be null"); | ||
| } | ||
|
|
||
| public static Product create(ProductId id, ProductName name, ProductPrice price) { | ||
| return new Product(id, name, price); | ||
| } | ||
|
|
||
| /** | ||
| * getter | ||
| */ | ||
| @Override | ||
| public ProductId getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public ProductName getName() { return name; } | ||
|
|
||
| public ProductPrice getPrice() { return price; } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package kitchenpos.products.tobe.domain; | ||
|
|
||
| import jakarta.persistence.Embeddable; | ||
| import kitchenpos.products.tobe.domain.exception.InvalidProductIdException; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| @Embeddable | ||
| public class ProductId implements Serializable { | ||
|
|
||
| private String value; | ||
|
|
||
| @SuppressWarnings("unused") | ||
| protected ProductId() {} | ||
|
|
||
| private ProductId(String value) { | ||
| if (value == null || value.isBlank()) { | ||
| throw new InvalidProductIdException("Product ID ๋ null ์ด๊ฑฐ๋ ๋น ๊ฐ์ด ๋ ์ ์์ต๋๋ค."); | ||
| } | ||
| this.value = value.strip(); | ||
| } | ||
|
|
||
| public static ProductId of(String value) { | ||
| return new ProductId(value); | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package kitchenpos.products.tobe.domain; | ||
|
|
||
| public interface ProductIdGenerator { | ||
| ProductId generateId(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package kitchenpos.products.tobe.domain; | ||
|
|
||
| import jakarta.persistence.Embeddable; | ||
| import jakarta.persistence.Transient; | ||
| import kitchenpos.products.tobe.domain.exception.InvalidProductNameException; | ||
| import kitchenpos.shared.domain.ProfanityChecker; | ||
| import kitchenpos.shared.domain.ValueObject; | ||
|
|
||
| @Embeddable | ||
| public class ProductName extends ValueObject<ProductName> { | ||
|
|
||
| private String name; | ||
|
|
||
| @SuppressWarnings("unused") | ||
| protected ProductName() {} | ||
|
|
||
| // ์ธ๋ถ์์ ์ง์ ํธ์ถํ ์ ์๋ private ์์ฑ์: ๊ฒ์ฆ๋ ์ด๋ฆ๋ง ๋ฐ์ | ||
| private ProductName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public static ProductName create(ProfanityChecker profanityChecker, String name) { | ||
|
||
| if (name == null || name.isBlank()) { | ||
| throw new InvalidProductNameException("Product name ์ null ์ด๊ฑฐ๋ ๋น ๊ฐ์ด ๋ ์ ์์ต๋๋ค."); | ||
| } | ||
|
|
||
| if (profanityChecker.containsProfanity(name)) { | ||
| throw new InvalidProductNameException("Product name ์ ๋น์์ด๊ฐ ํฌํจ๋ ์ ์์ต๋๋ค."); | ||
| } | ||
| return new ProductName(name.strip()); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| @Transient | ||
| protected Object[] getEqualityFields() { | ||
| return new Object[] { name }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package kitchenpos.products.tobe.domain; | ||
|
|
||
| import kitchenpos.products.tobe.domain.exception.InvalidProductPriceException; | ||
| import kitchenpos.shared.domain.Money; | ||
| import kitchenpos.shared.domain.ValueObject; | ||
|
|
||
| public class ProductPrice extends ValueObject<ProductPrice> { | ||
| private Money price; | ||
|
|
||
| private ProductPrice(Money price) { | ||
| if (price == null || price.isLessThan(Money.ZERO)) { | ||
| throw new InvalidProductPriceException("์ํ ๊ฐ๊ฒฉ์ null ์ด๊ฑฐ๋ 0๋ณด๋ค ์์ ์ ์์ต๋๋ค."); | ||
| } | ||
|
|
||
| this.price = price; | ||
| } | ||
|
|
||
| public static ProductPrice of(Money price) { | ||
| return new ProductPrice(price); | ||
| } | ||
|
|
||
| public Money getPrice() { | ||
| return price; | ||
| } | ||
|
|
||
| @Override | ||
| protected Object[] getEqualityFields() { | ||
| return new Object[] { price }; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package kitchenpos.products.tobe.domain; | ||
|
|
||
| import org.springframework.stereotype.Repository; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| @Repository | ||
| @Transactional | ||
| public interface TobeProductRepository { | ||
| Product save(Product product); | ||
|
|
||
| Optional<Product> findById(ProductId id); | ||
|
|
||
| List<Product> findAll(); | ||
|
|
||
| List<Product> findAllByIdIn(List<ProductId> ids); | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package kitchenpos.products.tobe.domain.exception; | ||
|
|
||
| public class InvalidProductIdException extends IllegalArgumentException { | ||
| public InvalidProductIdException(String s) { | ||
| super(s); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package kitchenpos.products.tobe.domain.exception; | ||
|
|
||
| public class InvalidProductNameException extends IllegalArgumentException { | ||
| public InvalidProductNameException(String s) { | ||
| super(s); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package kitchenpos.products.tobe.domain.exception; | ||
|
|
||
| public class InvalidProductPriceException extends IllegalArgumentException { | ||
| public InvalidProductPriceException(String s) { | ||
| super(s); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package kitchenpos.products.tobe.domain.support; | ||
|
||
|
|
||
| import kitchenpos.products.tobe.domain.ProductId; | ||
| import kitchenpos.products.tobe.domain.ProductIdGenerator; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Component | ||
| public class UUIDBasedProductIdGenerator implements ProductIdGenerator { | ||
| @Override | ||
| public ProductId generateId() { | ||
| return ProductId.of(UUID.randomUUID().toString()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||||||||||||||
| package kitchenpos.shared.domain; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import java.io.Serializable; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public abstract class DomainEntity<T extends DomainEntity<T, TID>, TID> implements Serializable { | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AggregateRoot๋ ์ถ๊ฐํ์ต๋๋ค. |
||||||||||||||||||||||
| @Override | ||||||||||||||||||||||
| public boolean equals(Object other) { | ||||||||||||||||||||||
| if (other == null) { | ||||||||||||||||||||||
| return false; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return equals((T)other); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public boolean equals(T other) { | ||||||||||||||||||||||
| if (other == null) { | ||||||||||||||||||||||
| return false; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (getId() == null) { | ||||||||||||||||||||||
| return false; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ฌ์ํ์ง๋ง ์๋์ฒ๋ผ ๋ณ๊ฒฝํด๋ณผ ์๋ ์์ ๊ฒ ๊ฐ๋ค์.
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (other.getClass().equals(getClass())) { | ||||||||||||||||||||||
| return getId().equals(other.getId()); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return super.equals(other); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Override | ||||||||||||||||||||||
| public int hashCode() { | ||||||||||||||||||||||
| return getId() == null ? 0 : getId().hashCode(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| abstract public TID getId(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docker-compose ํ์ผ์ด docker ๋๋ ํ ๋ฆฌ์ ์ด๋ฏธ ์๋๊ฑธ๋ก ์๊ณ ์๋๋ฐ, docker-compose file์ ๋ฐ์ ๋ฐ๋ก ๋์ ์ด์ ๊ฐ ์์ผ์ ๊ฐ์? ๐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ์๋์ค ๋ชฐ๋๋ค์ ใ ใ ์ญ์ ํ์ต๋๋ค.