Skip to content
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

๐Ÿš€ 2๋‹จ๊ณ„ - ๋ฆฌํŒฉํ„ฐ๋ง(๋ฉ”๋‰ด) #101

Open
wants to merge 26 commits into
base: dacapolife87
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
54fc7db
refactor : Request, Response ๊ฐ์ฒด ์ƒ์„ฑ
dacapolife87 Apr 13, 2022
23fd6cd
refactor : domain ๋ฆฌํŒฉํ† ๋ง
dacapolife87 Apr 13, 2022
5aba3a1
test : ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
dacapolife87 Apr 13, 2022
f5f8269
refactor : Package ๋ณ€๊ฒฝ ๋ฐ ๋ถˆํ•„์š” ์ž„ํฌํŠธ ์ œ๊ฑฐ
dacapolife87 Apr 13, 2022
67170c2
refactor : Controller์—์„œ Entity ๋ถ„๋ฆฌ
dacapolife87 Apr 13, 2022
64dfd9c
test : Dto ์‚ฌ์šฉ์— ๋”ฐ๋ฅธ ํ…Œ์ŠคํŠธ์ฝ”๋“œ ์ˆ˜์ •
dacapolife87 Apr 13, 2022
5c159c0
test : setter ์ œ๊ฑฐํ›„ ์ƒ์„ฑ์ž ์‚ฌ์šฉ
dacapolife87 Apr 13, 2022
1de0bdb
refactor : ๊ฐ’๊ฐ์ฒด๋‚ด์—์„œ ์ฒ˜๋ฆฌ๊ฐ€๋Šฅํ•œ ๋กœ์ง ์ด๋™
dacapolife87 Apr 13, 2022
23058a2
refactor : Price ๊ณตํ†ต ๋„๋ฉ”์ธ์œผ๋กœ ์ถ”์ถœ
dacapolife87 Apr 17, 2022
5279b6f
refactor : MenuProduct setter ์ œ๊ฑฐ
dacapolife87 Apr 17, 2022
1ce2bf9
refactor : MenuProduct ๊ฐ€๊ฒฉ์ฒดํฌ ๋กœ์ง ์ƒ์œ„๋กœ ์ด๋™
dacapolife87 Apr 17, 2022
79a7593
refactor : MenuProducts ์ผ๊ธ‰์ปฌ๋ ‰์…˜์ƒ์„ฑ
dacapolife87 Apr 17, 2022
ec823ac
refactor : MenuProductsRequest์ƒ์„ฑ ๋ฐ Entity๋ถ„๋ฆฌ
dacapolife87 Apr 17, 2022
19a1ed1
refactor : formatting ๋ฐ ํŒจํ‚ค์ง€ ๋ณ€๊ฒฝ
dacapolife87 Apr 20, 2022
97ada58
refactor : Price ๊ณตํ†ต ๋„๋ฉ”์ธ์œผ๋กœ ์ด๋™ ๋ฐ MenuPrice & ProductPrice ํ†ตํ•ฉ
dacapolife87 Apr 20, 2022
742c136
feat : request ๊ฐ์ฒด ์ƒ์„ฑ ๋ฐ ์ปจํŠธ๋กค๋Ÿฌ ๋ถ„๋ฆฌ
dacapolife87 Apr 21, 2022
cd7e080
feat : ํŒจํ‚ค์ง€ ์ด๋™ ๋ฐ ๋„๋ฉ”์ธ ๊ธฐ๋Šฅ ๊ตฌํ˜„
dacapolife87 Apr 21, 2022
f32cc8a
feat : ๊ฐ„์ ‘์ฐธ์กฐ๋กœ ๋ณ€๊ฒฝ
dacapolife87 Apr 21, 2022
134c1c4
refactor : ๋„๋ฉ”์ธ์œผ๋กœ ๋กœ์ง ์ด๋™
dacapolife87 Apr 21, 2022
fc0ffb0
test : ํ…Œ์ŠคํŠธ๋กœ์ง ์ˆ˜์ • ๋ฐ ์‹ ๊ทœ์ž‘์„ฑ
dacapolife87 Apr 21, 2022
4408754
refactor : ์‘๋‹ต๊ทœ๊ฒฉ ํ™•์ธ๋ถˆ๊ฐ€๋กœ response ๊ฐ์ฒด๋Š” ์ผ๋‹จ ์ œ๊ฑฐ
dacapolife87 Apr 21, 2022
eec9f36
refactor : validation ์ œ๊ฑฐ
dacapolife87 May 1, 2022
743a4da
refactor : request ๊ฐ์ฒด์™€ dto๊ฐ์ฒด ๋ถ„๋ฆฌ
dacapolife87 May 1, 2022
075b342
refactor : equals, hashcode์ถ”๊ฐ€
dacapolife87 May 1, 2022
0f60d64
test : request๊ฐ์ฒด dto๊ฐ์ฒด๋กœ ๋ณ€๊ฒฝ
dacapolife87 May 1, 2022
489c1c2
refactor : ๊ฐ€๊ฒฉ๋น„๊ต๋กœ์ง MenuProducts๋กœ ์ด๋™
dacapolife87 May 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import kitchenpos.deliveryorders.infra.KitchenridersClient;
import kitchenpos.eatinorders.domain.*;
import kitchenpos.menus.domain.Menu;
import kitchenpos.menus.tobe.domain.Menu;
import kitchenpos.menus.domain.MenuRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kitchenpos.eatinorders.domain;

import kitchenpos.menus.domain.Menu;
import kitchenpos.menus.tobe.domain.Menu;

import javax.persistence.*;
import java.math.BigDecimal;
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/kitchenpos/menus/application/MenuGroupService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package kitchenpos.menus.application;

import kitchenpos.menus.domain.MenuGroup;
import kitchenpos.menus.domain.MenuGroupRepository;
import kitchenpos.menus.tobe.domain.MenuGroup;
import kitchenpos.menus.ui.dto.MenuGroupRequest;
import kitchenpos.menus.ui.dto.MenuGroupResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
public class MenuGroupService {
Expand All @@ -18,19 +19,15 @@ public MenuGroupService(final MenuGroupRepository menuGroupRepository) {
}

@Transactional
public MenuGroup create(final MenuGroup request) {
final String name = request.getName();
if (Objects.isNull(name) || name.isEmpty()) {
throw new IllegalArgumentException();
}
final MenuGroup menuGroup = new MenuGroup();
menuGroup.setId(UUID.randomUUID());
menuGroup.setName(name);
return menuGroupRepository.save(menuGroup);
public MenuGroupResponse create(final MenuGroupRequest request) {
return new MenuGroupResponse(menuGroupRepository.save(request.toEntity()));
}

@Transactional(readOnly = true)
public List<MenuGroup> findAll() {
return menuGroupRepository.findAll();
public List<MenuGroupResponse> findAll() {
List<MenuGroup> menuGroups = menuGroupRepository.findAll();
return menuGroups.stream()
.map(menuGroup -> new MenuGroupResponse(menuGroup))
.collect(Collectors.toList());
}
}
75 changes: 32 additions & 43 deletions src/main/java/kitchenpos/menus/application/MenuService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package kitchenpos.menus.application;

import kitchenpos.menus.domain.*;
import kitchenpos.menus.domain.MenuGroupRepository;
import kitchenpos.menus.tobe.domain.MenuProduct;
import kitchenpos.menus.domain.MenuRepository;
import kitchenpos.menus.tobe.domain.Menu;
import kitchenpos.menus.tobe.domain.MenuGroup;
import kitchenpos.menus.tobe.domain.MenuPrice;
import kitchenpos.menus.ui.dto.MenuRequest;
import kitchenpos.menus.ui.dto.MenuResponse;
import kitchenpos.products.domain.ProductRepository;
import kitchenpos.products.infra.PurgomalumClient;
import kitchenpos.products.tobe.domain.Product;
Expand Down Expand Up @@ -31,11 +38,9 @@ public MenuService(
}

@Transactional
public Menu create(final Menu request) {
final BigDecimal price = request.getPrice();
if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException();
}
public MenuResponse create(final MenuRequest request) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„์ง ์ค‘์š”ํ•œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด ์„œ๋น„์Šค ๋ ˆ์ด์–ด์— ๋…ธ์ถœ๋˜์–ด ์žˆ๋Š”๊ฒƒ ๊ฐ™์•„์š”.
๋งŒ์•ฝ ํ˜„์žฌ ๊ตฌ์กฐ์—์„œ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋ถ„์ด ์„œ๋น„์Šค ๋ ˆ์ด์–ด์— ์žˆ๋Š” ๋กœ์ง์„ ๋ณด์ง€๋ชปํ•˜๊ณ  Menu ๋„๋ฉ”์ธ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค๋ฉด Menu ๊ฐ์ฒด๋Š” ์™„์ „ํ•œ ๊ฐ์ฒด๋ผ๊ณ  ํ• ์ˆ˜ ์—†์„๊ฒƒ ๊ฐ™์•„์š” ๐Ÿ˜ข
๋…ธ์ถœ๋˜์–ด ์žˆ๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๋„๋ฉ”์ธ ๋‚ด๋ถ€๋กœ ์˜ฎ๊ฒจ๋ณด์„ธ์š” ๐Ÿ˜„

MenuPrice menuPrice = new MenuPrice(request.getPrice());

final MenuGroup menuGroup = menuGroupRepository.findById(request.getMenuGroupId())
.orElseThrow(NoSuchElementException::new);
final List<MenuProduct> menuProductRequests = request.getMenuProducts();
Expand Down Expand Up @@ -68,45 +73,25 @@ public Menu create(final Menu request) {
menuProduct.setQuantity(quantity);
menuProducts.add(menuProduct);
}
if (price.compareTo(sum) > 0) {
throw new IllegalArgumentException();
}
final String name = request.getName();
if (Objects.isNull(name) || purgomalumClient.containsProfanity(name)) {
throw new IllegalArgumentException();
}
final Menu menu = new Menu();
menu.setId(UUID.randomUUID());
menu.setName(name);
menu.setPrice(price);
menu.setMenuGroup(menuGroup);
menu.setDisplayed(request.isDisplayed());
menu.setMenuProducts(menuProducts);
return menuRepository.save(menu);

menuPrice.validationTotalPrice(sum);

return new MenuResponse(menuRepository.save(request.toEntity(purgomalumClient, menuGroup)));
}

@Transactional
public Menu changePrice(final UUID menuId, final Menu request) {
public MenuResponse changePrice(final UUID menuId, final MenuRequest request) {
final BigDecimal price = request.getPrice();
if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException();
}

final Menu menu = menuRepository.findById(menuId)
.orElseThrow(NoSuchElementException::new);
for (final MenuProduct menuProduct : menu.getMenuProducts()) {
final BigDecimal sum = menuProduct.getProduct()
.getPrice()
.multiply(BigDecimal.valueOf(menuProduct.getQuantity()));
if (price.compareTo(sum) > 0) {
throw new IllegalArgumentException();
}
}
menu.setPrice(price);
return menu;

menu.changePrice(price);
return new MenuResponse(menu);
}

@Transactional
public Menu display(final UUID menuId) {
public MenuResponse display(final UUID menuId) {
final Menu menu = menuRepository.findById(menuId)
.orElseThrow(NoSuchElementException::new);
for (final MenuProduct menuProduct : menu.getMenuProducts()) {
Expand All @@ -117,20 +102,24 @@ public Menu display(final UUID menuId) {
throw new IllegalStateException();
}
}
menu.setDisplayed(true);
return menu;
menu.show();
return new MenuResponse(menu);
}

@Transactional
public Menu hide(final UUID menuId) {
public MenuResponse hide(final UUID menuId) {
final Menu menu = menuRepository.findById(menuId)
.orElseThrow(NoSuchElementException::new);
menu.setDisplayed(false);
return menu;
menu.hide();
return new MenuResponse(menu);
}

@Transactional(readOnly = true)
public List<Menu> findAll() {
return menuRepository.findAll();
public List<MenuResponse> findAll() {
List<Menu> menus = menuRepository.findAll();

return menus.stream()
.map(menu -> new MenuResponse(menu))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kitchenpos.menus.domain;

import kitchenpos.menus.tobe.domain.MenuGroup;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kitchenpos.menus.domain;

import kitchenpos.menus.tobe.domain.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand Down
102 changes: 0 additions & 102 deletions src/main/java/kitchenpos/menus/domain/Menu.java

This file was deleted.

37 changes: 0 additions & 37 deletions src/main/java/kitchenpos/menus/domain/MenuGroup.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kitchenpos.menus.domain;

import kitchenpos.menus.tobe.domain.MenuGroup;

import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/kitchenpos/menus/domain/MenuRepository.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kitchenpos.menus.domain;

import kitchenpos.menus.tobe.domain.Menu;

import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down
Loading