-
Notifications
You must be signed in to change notification settings - Fork 177
๐ 2๋จ๊ณ - ๋ฆฌํฉํฐ๋ง(๋ฉ๋ด) #372
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
Open
AlbertImKr
wants to merge
6
commits into
next-step:albertimkr
Choose a base branch
from
AlbertImKr:step2
base: albertimkr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ded1486
refactor: ProductName์ infra ํด๋์ค ์ฐธ์กฐ ์ ๊ฑฐ
AlbertImKr 3d5e505
refactor: ๋ฉ๋ด ๋ฆฌํฉํฐ๋ง
AlbertImKr ec4ce24
refactor: ProductName ๋ฆฌํฉํฐ๋ง
AlbertImKr ed8b06d
refactor: PurgomalumClient ๋ฆฌํฉํฐ๋ง
AlbertImKr 7407c96
refactor: Menu name ์์ค ๊ฒ์ฆ ๋ก์ง ๋ฆฌํฉํฐ๋ง
AlbertImKr 1485f63
refactor: ํผ๋๋ฐฑ ๋ฐ์
AlbertImKr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/kitchenpos/menus/tobe/application/DefaultProfanityChecker.java
This file contains hidden or 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,19 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| import kitchenpos.menus.tobe.domain.ProfanityChecker; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component("tobeMenuContextProfanityChecker") | ||
| public class DefaultProfanityChecker implements ProfanityChecker { | ||
|
|
||
| private final PurgomalumClient purgomalumClient; | ||
|
|
||
| public DefaultProfanityChecker(final PurgomalumClient purgomalumClient) { | ||
| this.purgomalumClient = purgomalumClient; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean containsProfanity(final String text) { | ||
| return purgomalumClient.containsProfanity(text); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/kitchenpos/menus/tobe/application/MenuCreateRequest.java
This file contains hidden or 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,19 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| public record MenuCreateRequest( | ||
| BigDecimal price, | ||
| String name, | ||
| boolean displayed, | ||
| UUID menuGroupId, | ||
| List<MenuProductRequest> menuProducts | ||
| ) { | ||
| public List<UUID> productIds() { | ||
| return menuProducts.stream() | ||
| .map(MenuProductRequest::productId) | ||
| .toList(); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/main/java/kitchenpos/menus/tobe/application/MenuFacade.java
This file contains hidden or 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,48 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| import kitchenpos.menus.tobe.domain.*; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Component | ||
| public class MenuFacade { | ||
| private final MenuService menuService; | ||
| private final MenuGroupService menuGroupService; | ||
| private final ProductClient productClient; | ||
| private final ProfanityChecker profanityChecker; | ||
|
|
||
|
|
||
| public MenuFacade(MenuService menuService, MenuGroupService menuGroupService, ProductClient productClient, ProfanityChecker profanityChecker) { | ||
| this.menuService = menuService; | ||
| this.menuGroupService = menuGroupService; | ||
| this.productClient = productClient; | ||
| this.profanityChecker = profanityChecker; | ||
| } | ||
|
|
||
| @Transactional | ||
| public Menu create(MenuCreateRequest request) { | ||
| final MenuName name = new MenuName(request.name(), profanityChecker); | ||
| final MenuPrice price = new MenuPrice(request.price()); | ||
| final MenuGroup menuGroup = menuGroupService.findById(request.menuGroupId()); | ||
| final ProductInfos productInfos = productClient.listByIds(request.productIds()); | ||
| final MenuProductCatalog menuProductCatalog = new MenuProductCatalog(request.menuProducts(), productInfos); | ||
| return menuService.create(name, price, menuGroup, request.displayed(), menuProductCatalog); | ||
| } | ||
|
|
||
| @Transactional | ||
| public Menu changePrice(UUID menuId, MenuPriceChangeRequest request) { | ||
| final MenuPrice price = new MenuPrice(request.price()); | ||
| final Menu menu = menuService.findById(menuId); | ||
| final ProductInfos productInfos = productClient.listByIds(menu.findProductIds()); | ||
| return menuService.changePrice(menuId, price, productInfos); | ||
| } | ||
|
|
||
| @Transactional | ||
| public Menu display(UUID menuId) { | ||
| final Menu menu = menuService.findById(menuId); | ||
| final ProductInfos productInfos = productClient.listByIds(menu.findProductIds()); | ||
| return menuService.display(menuId, productInfos); | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
src/main/java/kitchenpos/menus/tobe/application/MenuGroupCreateRequest.java
This file contains hidden or 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,4 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| public record MenuGroupCreateRequest(String name) { | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/kitchenpos/menus/tobe/application/MenuGroupService.java
This file contains hidden or 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 kitchenpos.menus.tobe.application; | ||
|
|
||
| import kitchenpos.menus.tobe.domain.MenuGroup; | ||
| import kitchenpos.menus.tobe.domain.MenuGroupName; | ||
| import kitchenpos.menus.tobe.domain.MenuGroupRepository; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
| import java.util.NoSuchElementException; | ||
| import java.util.UUID; | ||
|
|
||
| @Service("tobeMenuGroupService") | ||
| public class MenuGroupService { | ||
| private final MenuGroupRepository menuGroupRepository; | ||
|
|
||
| public MenuGroupService(final MenuGroupRepository menuGroupRepository) { | ||
| this.menuGroupRepository = menuGroupRepository; | ||
| } | ||
|
|
||
| @Transactional | ||
| public MenuGroup create(final MenuGroupCreateRequest request) { | ||
| final MenuGroupName name = new MenuGroupName(request.name()); | ||
| final MenuGroup menuGroup = new MenuGroup(UUID.randomUUID(), name); | ||
| return menuGroupRepository.save(menuGroup); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<MenuGroup> findAll() { | ||
| return menuGroupRepository.findAll(); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public MenuGroup findById(UUID menuGroupId) { | ||
| return menuGroupRepository.findById(menuGroupId) | ||
| .orElseThrow(NoSuchElementException::new); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/kitchenpos/menus/tobe/application/MenuPriceChangeRequest.java
This file contains hidden or 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,6 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public record MenuPriceChangeRequest(BigDecimal price) { | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/kitchenpos/menus/tobe/application/MenuProductRequest.java
This file contains hidden or 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,7 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record MenuProductRequest(UUID productId, long quantity) { | ||
|
|
||
| } |
60 changes: 60 additions & 0 deletions
60
src/main/java/kitchenpos/menus/tobe/application/MenuService.java
This file contains hidden or 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,60 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| import kitchenpos.menus.tobe.domain.*; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
| import java.util.NoSuchElementException; | ||
| import java.util.UUID; | ||
|
|
||
| @Service("tobeMenuService") | ||
| public class MenuService { | ||
|
|
||
| private final MenuRepository menuRepository; | ||
|
|
||
| public MenuService(final MenuRepository menuRepository) { | ||
| this.menuRepository = menuRepository; | ||
| } | ||
|
|
||
| @Transactional | ||
| public Menu create(final MenuName name, final MenuPrice price, final MenuGroup menuGroup, final boolean displayed, final MenuProductCatalog menuProductCatalog) { | ||
| final Menu menu = new Menu(UUID.randomUUID(), name, price, menuGroup, displayed, menuProductCatalog); | ||
| return menuRepository.save(menu); | ||
| } | ||
|
|
||
| @Transactional | ||
| public Menu changePrice(final UUID menuId, final MenuPrice price, final ProductInfos productInfos) { | ||
| final Menu menu = menuRepository.findById(menuId) | ||
| .orElseThrow(NoSuchElementException::new); | ||
| menu.changePrice(price, productInfos); | ||
| return menu; | ||
| } | ||
|
|
||
| @Transactional | ||
| public Menu display(final UUID menuId, final ProductInfos productInfos) { | ||
| final Menu menu = menuRepository.findById(menuId) | ||
| .orElseThrow(NoSuchElementException::new); | ||
| menu.display(productInfos); | ||
| return menu; | ||
| } | ||
|
|
||
| @Transactional | ||
| public Menu hide(final UUID menuId) { | ||
| final Menu menu = menuRepository.findById(menuId) | ||
| .orElseThrow(NoSuchElementException::new); | ||
| menu.hide(); | ||
| return menu; | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<Menu> findAll() { | ||
| return menuRepository.findAll(); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public Menu findById(UUID menuId) { | ||
| return menuRepository.findById(menuId) | ||
| .orElseThrow(NoSuchElementException::new); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/kitchenpos/menus/tobe/application/ProductClient.java
This file contains hidden or 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,10 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| import kitchenpos.menus.tobe.domain.ProductInfos; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| public interface ProductClient { | ||
| ProductInfos listByIds(List<UUID> productIds); | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/kitchenpos/menus/tobe/application/PurgomalumClient.java
This file contains hidden or 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,6 @@ | ||
| package kitchenpos.menus.tobe.application; | ||
|
|
||
| public interface PurgomalumClient { | ||
|
|
||
| boolean containsProfanity(String text); | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/kitchenpos/menus/tobe/domain/JpaMenuGroupRepository.java
This file contains hidden or 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,10 @@ | ||
| package kitchenpos.menus.tobe.domain; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Repository("menuGroupToBeRepository") | ||
| public interface JpaMenuGroupRepository extends MenuGroupRepository, JpaRepository<MenuGroup, UUID> { | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/kitchenpos/menus/tobe/domain/JpaMenuRepository.java
This file contains hidden or 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,16 @@ | ||
| package kitchenpos.menus.tobe.domain; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @Repository("menuToBeRepository") | ||
| public interface JpaMenuRepository extends MenuRepository, JpaRepository<Menu, UUID> { | ||
| @Query("select m from Menu m join m.menuProducts mp where mp.product.id = :productId") | ||
| @Override | ||
| List<Menu> findAllByProductId(@Param("productId") UUID productId); | ||
| } |
This file contains hidden or 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,83 @@ | ||
| package kitchenpos.menus.tobe.domain; | ||
|
|
||
| import jakarta.persistence.*; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @Table(name = "menu") | ||
| @Entity(name = "tobeMenu") | ||
| public class Menu { | ||
| @Column(name = "id", columnDefinition = "binary(16)") | ||
| @Id | ||
| private UUID id; | ||
|
|
||
| @Embedded | ||
| private MenuName name; | ||
|
|
||
| @Embedded | ||
| private MenuPrice price; | ||
|
|
||
| @ManyToOne(optional = false) | ||
| @JoinColumn( | ||
| name = "menu_group_id", | ||
| columnDefinition = "binary(16)", | ||
| foreignKey = @ForeignKey(name = "fk_menu_to_menu_group") | ||
| ) | ||
| private MenuGroup menuGroup; | ||
|
|
||
| @Column(name = "displayed", nullable = false) | ||
| private boolean displayed; | ||
|
|
||
| @Embedded | ||
| private MenuProducts menuProducts; | ||
|
|
||
| @Transient | ||
| private UUID menuGroupId; | ||
|
|
||
| protected Menu() { | ||
| } | ||
|
|
||
| public Menu(UUID id, MenuName name, MenuPrice price, MenuGroup menuGroup, boolean displayed, MenuProductCatalog menuProductCatalog) { | ||
| validatePrice(price, menuProductCatalog.calculateTotalPrice()); | ||
| this.id = id; | ||
| this.name = name; | ||
| this.price = price; | ||
| this.menuGroup = menuGroup; | ||
| this.displayed = displayed; | ||
| this.menuProducts = new MenuProducts(menuProductCatalog); | ||
| } | ||
|
|
||
| private void validatePrice(MenuPrice price, BigDecimal total) { | ||
| if (!price.isGreaterThan(total)) { | ||
| throw new IllegalArgumentException("๋ฉ๋ด ๊ฐ๊ฒฉ์ด ์ ์ฒด ๋ฉ๋ด ์ํ์ ๊ฐ๊ฒฉ ํฉ๋ณด๋ค ๊ฐ๊ฑฐ๋ ์์์ผ ํ๋ค"); | ||
| } | ||
| } | ||
|
|
||
| public UUID getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void changePrice(MenuPrice price, ProductInfos productInfos) { | ||
| validatePrice(price, menuProducts.calculateTotalPrice(productInfos)); | ||
| this.price = price; | ||
| } | ||
|
|
||
| public List<UUID> findProductIds() { | ||
| return menuProducts.getProductIds(); | ||
| } | ||
|
|
||
| public void display(ProductInfos productInfos) { | ||
| validatePrice(price, menuProducts.calculateTotalPrice(productInfos)); | ||
| this.displayed = true; | ||
| } | ||
|
|
||
| public void hide() { | ||
| this.displayed = false; | ||
| } | ||
|
|
||
| public MenuPrice getPrice() { | ||
| return price; | ||
| } | ||
| } | ||
This file contains hidden or 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,28 @@ | ||
| package kitchenpos.menus.tobe.domain; | ||
|
|
||
| import jakarta.persistence.*; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Table(name = "menu_group") | ||
| @Entity(name = "tobeMenuGroup") | ||
| public class MenuGroup { | ||
| @Column(name = "id", columnDefinition = "binary(16)") | ||
| @Id | ||
| private UUID id; | ||
|
|
||
| @Embedded | ||
| private MenuGroupName name; | ||
|
|
||
| protected MenuGroup() { | ||
| } | ||
|
|
||
| public MenuGroup(final UUID id, final MenuGroupName name) { | ||
| this.id = id; | ||
| this.name = name; | ||
| } | ||
|
|
||
| public UUID getId() { | ||
| return id; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/kitchenpos/menus/tobe/domain/MenuGroupName.java
This file contains hidden or 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,25 @@ | ||
| package kitchenpos.menus.tobe.domain; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Embeddable; | ||
|
|
||
| @Embeddable | ||
| public class MenuGroupName { | ||
|
|
||
| @Column(name = "name", nullable = false) | ||
| private String name; | ||
|
|
||
| protected MenuGroupName() { | ||
| } | ||
|
|
||
| public MenuGroupName(final String name) { | ||
| if (name == null || name.isEmpty()) { | ||
| throw new IllegalArgumentException("๋ฉ๋ด ๊ทธ๋ฃน ์ด๋ฆ์ ํ์๋ก ์ ๋ ฅํด์ผ ํฉ๋๋ค."); | ||
| } | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String value() { | ||
| return name; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
MenuGroup์ ์ง์ ์ฐธ์กฐ๋ก ๊ตฌํํด์ฃผ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค ๐
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.
ํ Context์์ ์กด์ฌํ์ฌ ๋ง์ฝ์ Id๋ก ์ฐธ์กฐํ๋ฉด ์คํ๋ ค ๋ ๋ณต์กํ ๊ตฌ์กฐ๊ฐ ๋ ์ ์๋ค๊ณ ์๊ฐํ์ด์,