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 21 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
44 changes: 44 additions & 0 deletions src/main/java/kitchenpos/common/domain/Price.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package kitchenpos.common.domain;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.math.BigDecimal;
import java.util.Objects;

@Embeddable
public class Price {
Copy link

Choose a reason for hiding this comment

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

Value Ojbect์˜ ๋ถˆ๋ณ€์„ฑ, ๊ฐ’ ๋™๋“ฑ์„ฑ์„ ์œ„ํ•ด Equals & HashCode ๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š” ?


@Column(name = "price", nullable = false)
private BigDecimal price;

protected Price() {
}

public Price(BigDecimal price) {
validation(price);
this.price = price;
}

private void validation(BigDecimal price) {
if (Objects.isNull(price)) {
throw new IllegalArgumentException("๊ฐ€๊ฒฉ์€ ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค.");
}

if (price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException("๊ฐ€๊ฒฉ์€ 0์› ์ด์ƒ์ด์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}
}

public BigDecimal getPrice() {
return price;
}

public static Price add(Price totalPrice, Price addPrice) {
return new Price(totalPrice.price.add(addPrice.price));
}
Copy link

Choose a reason for hiding this comment

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

Suggested change
public static Price add(Price totalPrice, Price addPrice) {
return new Price(totalPrice.price.add(addPrice.price));
}
public Price add(Price addPrice) {
return new Price(this.price.add(addPrice.price));
}

static ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ๋ณด๋‹ค๋Š” ๊ฐ์ฒด์— ๋ฉ”์‹œ์ง€๋ฅผ ๋˜์งˆ์ˆ˜ ์žˆ๋„๋ก ์ƒํƒœ๊ฐ’์„ ์ด์šฉํ•˜๋Š”๊ฒƒ์ด ์ข‹์•„๋ณด์—ฌ์š” ๐Ÿ˜„


public int compareTo(Price totalPrice) {
return price.compareTo(totalPrice.price);
}

}
34 changes: 17 additions & 17 deletions src/main/java/kitchenpos/eatinorders/application/OrderService.java
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 All @@ -20,10 +20,10 @@ public class OrderService {
private final KitchenridersClient kitchenridersClient;

public OrderService(
final OrderRepository orderRepository,
final MenuRepository menuRepository,
final OrderTableRepository orderTableRepository,
final KitchenridersClient kitchenridersClient
final OrderRepository orderRepository,
final MenuRepository menuRepository,
final OrderTableRepository orderTableRepository,
final KitchenridersClient kitchenridersClient
) {
this.orderRepository = orderRepository;
this.menuRepository = menuRepository;
Expand All @@ -42,9 +42,9 @@ public Order create(final Order request) {
throw new IllegalArgumentException();
}
final List<Menu> menus = menuRepository.findAllByIdIn(
orderLineItemRequests.stream()
.map(OrderLineItem::getMenuId)
.collect(Collectors.toList())
orderLineItemRequests.stream()
.map(OrderLineItem::getMenuId)
.collect(Collectors.toList())
);
if (menus.size() != orderLineItemRequests.size()) {
throw new IllegalArgumentException();
Expand All @@ -58,7 +58,7 @@ public Order create(final Order request) {
}
}
final Menu menu = menuRepository.findById(orderLineItemRequest.getMenuId())
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
if (!menu.isDisplayed()) {
throw new IllegalStateException();
}
Expand All @@ -85,7 +85,7 @@ public Order create(final Order request) {
}
if (type == OrderType.EAT_IN) {
final OrderTable orderTable = orderTableRepository.findById(request.getOrderTableId())
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
if (orderTable.isEmpty()) {
throw new IllegalStateException();
}
Expand All @@ -97,16 +97,16 @@ public Order create(final Order request) {
@Transactional
public Order accept(final UUID orderId) {
final Order order = orderRepository.findById(orderId)
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
if (order.getStatus() != OrderStatus.WAITING) {
throw new IllegalStateException();
}
if (order.getType() == OrderType.DELIVERY) {
BigDecimal sum = BigDecimal.ZERO;
for (final OrderLineItem orderLineItem : order.getOrderLineItems()) {
sum = orderLineItem.getMenu()
.getPrice()
.multiply(BigDecimal.valueOf(orderLineItem.getQuantity()));
.getPrice()
.multiply(BigDecimal.valueOf(orderLineItem.getQuantity()));
}
kitchenridersClient.requestDelivery(orderId, sum, order.getDeliveryAddress());
}
Expand All @@ -117,7 +117,7 @@ public Order accept(final UUID orderId) {
@Transactional
public Order serve(final UUID orderId) {
final Order order = orderRepository.findById(orderId)
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
if (order.getStatus() != OrderStatus.ACCEPTED) {
throw new IllegalStateException();
}
Expand All @@ -128,7 +128,7 @@ public Order serve(final UUID orderId) {
@Transactional
public Order startDelivery(final UUID orderId) {
final Order order = orderRepository.findById(orderId)
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
if (order.getType() != OrderType.DELIVERY) {
throw new IllegalStateException();
}
Expand All @@ -142,7 +142,7 @@ public Order startDelivery(final UUID orderId) {
@Transactional
public Order completeDelivery(final UUID orderId) {
final Order order = orderRepository.findById(orderId)
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
if (order.getStatus() != OrderStatus.DELIVERING) {
throw new IllegalStateException();
}
Expand All @@ -153,7 +153,7 @@ public Order completeDelivery(final UUID orderId) {
@Transactional
public Order complete(final UUID orderId) {
final Order order = orderRepository.findById(orderId)
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
final OrderType type = order.getType();
final OrderStatus status = order.getStatus();
if (type == OrderType.DELIVERY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public OrderTable create(final OrderTable request) {
@Transactional
public OrderTable sit(final UUID orderTableId) {
final OrderTable orderTable = orderTableRepository.findById(orderTableId)
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
orderTable.setEmpty(false);
return orderTable;
}

@Transactional
public OrderTable clear(final UUID orderTableId) {
final OrderTable orderTable = orderTableRepository.findById(orderTableId)
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
if (orderRepository.existsByOrderTableAndStatusNot(orderTable, OrderStatus.COMPLETED)) {
throw new IllegalStateException();
}
Expand All @@ -63,7 +63,7 @@ public OrderTable changeNumberOfGuests(final UUID orderTableId, final OrderTable
throw new IllegalArgumentException();
}
final OrderTable orderTable = orderTableRepository.findById(orderTableId)
.orElseThrow(NoSuchElementException::new);
.orElseThrow(NoSuchElementException::new);
if (orderTable.isEmpty()) {
throw new IllegalStateException();
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/kitchenpos/eatinorders/domain/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class Order {

@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(
name = "order_id",
nullable = false,
columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_order_line_item_to_orders")
name = "order_id",
nullable = false,
columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_order_line_item_to_orders")
)
private List<OrderLineItem> orderLineItems;

Expand All @@ -37,9 +37,9 @@ public class Order {

@ManyToOne
@JoinColumn(
name = "order_table_id",
columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_orders_to_order_table")
name = "order_table_id",
columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_orders_to_order_table")
)
private OrderTable orderTable;

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 All @@ -16,9 +16,9 @@ public class OrderLineItem {

@ManyToOne(optional = false)
@JoinColumn(
name = "menu_id",
columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_order_line_item_to_menu")
name = "menu_id",
columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_order_line_item_to_menu")
)
private Menu menu;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public OrderRestController(final OrderService orderService) {
public ResponseEntity<Order> create(@RequestBody final Order request) {
final Order response = orderService.create(request);
return ResponseEntity.created(URI.create("/api/orders/" + response.getId()))
.body(response);
.body(response);
}

@PutMapping("/{orderId}/accept")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public OrderTableRestController(final OrderTableService orderTableService) {
public ResponseEntity<OrderTable> create(@RequestBody final OrderTable request) {
final OrderTable response = orderTableService.create(request);
return ResponseEntity.created(URI.create("/api/order-tables/" + response.getId()))
.body(response);
.body(response);
}

@PutMapping("/{orderTableId}/sit")
Expand All @@ -37,8 +37,8 @@ public ResponseEntity<OrderTable> clear(@PathVariable final UUID orderTableId) {

@PutMapping("/{orderTableId}/number-of-guests")
public ResponseEntity<OrderTable> changeNumberOfGuests(
@PathVariable final UUID orderTableId,
@RequestBody final OrderTable request
@PathVariable final UUID orderTableId,
@RequestBody final OrderTable request
) {
return ResponseEntity.ok(orderTableService.changeNumberOfGuests(orderTableId, request));
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/kitchenpos/menus/application/MenuGroupService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
Expand All @@ -18,14 +18,9 @@ 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);
public MenuGroup create(final MenuGroupRequest request) {
final MenuGroup menuGroup = new MenuGroup(UUID.randomUUID(), request.getName());

return menuGroupRepository.save(menuGroup);
}

Expand Down
Loading