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단계 - 리팩터링(메뉴) #169

Open
wants to merge 35 commits into
base: chr0m3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bde7ea3
Price에 multiply() 추가
chr0m3 Oct 22, 2022
86b5760
MenuGroup entity 추가
chr0m3 Oct 22, 2022
4022276
MenuGroupEntity 추가
chr0m3 Oct 22, 2022
8382a9b
MenuGroupEntityConverter 추가
chr0m3 Oct 22, 2022
a1644b4
MenuGroupRepository 추가
chr0m3 Oct 22, 2022
b84cfe6
JpaMenuGroupRepository, JpaMenuGroupDao 추가
chr0m3 Oct 22, 2022
eb121a6
Price.multiply() 테스트 추가
chr0m3 Oct 22, 2022
4e44a8f
Price에 add() 추가
chr0m3 Oct 22, 2022
2c52931
Price가 Comparable을 구현하도록 수정
chr0m3 Oct 22, 2022
0146904
MenuProductQuantity VO 추가
chr0m3 Oct 22, 2022
a968bc6
MenuProduct VO 추가
chr0m3 Oct 23, 2022
7ff9973
MenuGroup VO 추가
chr0m3 Oct 23, 2022
3621adb
Menu entity 추가
chr0m3 Oct 23, 2022
5aab011
MenuDisplayPolicy 추가
chr0m3 Oct 23, 2022
58bd527
MenuRepository 추가
chr0m3 Oct 23, 2022
0701e17
Menu의 isVisible을 displayed로 변경
chr0m3 Oct 23, 2022
bf9bfb1
MenuEntity 추가
chr0m3 Oct 23, 2022
44adb96
MenuGroup VO 삭제
chr0m3 Oct 24, 2022
2d16e74
MenuProductEntity 추가
chr0m3 Oct 24, 2022
218f580
MenuProductEntityConverter 추가
chr0m3 Oct 24, 2022
c346395
누락된 final 추가
chr0m3 Oct 24, 2022
26aa5e7
MenuEntityConverter 추가
chr0m3 Oct 24, 2022
ac684f6
JpaMenuRepository 추가
chr0m3 Oct 24, 2022
748ee71
JpaMenuRepository 리팩터링 - 중복 코드 제거
chr0m3 Oct 24, 2022
96fe49a
메뉴 노출 정책을 위반하는 가격 변경이 불가능하도록 수정
chr0m3 Oct 24, 2022
f795b5c
새로운 도메인 모델을 사용하도록 Menu 컨텍스트 수정
chr0m3 Oct 24, 2022
2c7035e
불필요해진 과거 코드 제거
chr0m3 Oct 24, 2022
a662282
CreateMenuGroupCommand DTO 추가
chr0m3 Oct 24, 2022
a753755
ChangeMenuPriceCommand DTO 추가
chr0m3 Oct 24, 2022
86dc9e6
CreateMenuCommand DTO 추가
chr0m3 Oct 24, 2022
81afbbc
메뉴 노출 정책을 위반하는 메뉴 생성이 불가능하도록 수정
chr0m3 Oct 24, 2022
bd08ccb
메뉴 생성시 정확한 상품 가격을 반영하도록 개선
chr0m3 Oct 24, 2022
71f200a
DB 마이그레이션
chr0m3 Oct 24, 2022
139c6f8
도메인 모델 수정
chr0m3 Oct 24, 2022
1c460a0
Converter 인터페이스 제거
chr0m3 Oct 24, 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 @@ -3,6 +3,7 @@
import java.net.URI;
import java.util.List;
import kitchenpos.menu.application.MenuGroupService;
import kitchenpos.menu.tobe.application.dto.CreateMenuGroupCommand;
import kitchenpos.menu.tobe.domain.entity.MenuGroup;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -21,7 +22,7 @@ public MenuGroupRestController(final MenuGroupService menuGroupService) {
}

@PostMapping
public ResponseEntity<MenuGroup> create(@RequestBody final MenuGroup request) {
public ResponseEntity<MenuGroup> create(@RequestBody final CreateMenuGroupCommand request) {
Copy link
Author

Choose a reason for hiding this comment

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

도메인 모델을 그대로 받는 대신 요청하는 행위에 맞는 DTO를 도입해야 할 필요성이 느껴져 DTO를 추가했습니다.

Copy link

Choose a reason for hiding this comment

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

DTO 도입 좋습니다 ㅎㅎ 😄

final MenuGroup response = menuGroupService.create(request);
return ResponseEntity.created(URI.create("/api/menu-groups/" + response.id))
.body(response);
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/kitchenpos/menu/application/MenuGroupService.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package kitchenpos.menu.application;

import java.util.List;
import java.util.Objects;
import java.util.UUID;
import kitchenpos.common.name.Name;
import kitchenpos.common.name.NameFactory;
import kitchenpos.menu.tobe.application.dto.CreateMenuGroupCommand;
import kitchenpos.menu.tobe.domain.entity.MenuGroup;
import kitchenpos.menu.tobe.domain.repository.MenuGroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class MenuGroupService {

private final MenuGroupRepository menuGroupRepository;

public MenuGroupService(final MenuGroupRepository menuGroupRepository) {
private final NameFactory nameFactory;

@Autowired
public MenuGroupService(MenuGroupRepository menuGroupRepository, NameFactory nameFactory) {
this.menuGroupRepository = menuGroupRepository;
this.nameFactory = nameFactory;
}

@Transactional
public MenuGroup create(final MenuGroup request) {
final Name name = request.name;
if (Objects.isNull(name)) {
throw new IllegalArgumentException();
}
public MenuGroup create(final CreateMenuGroupCommand request) {
final Name name = this.nameFactory.create(request.name);
Copy link
Author

Choose a reason for hiding this comment

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

이제 DTO를 받은 뒤 제대로 NameFactory를 사용해 Name을 생성하게 됩니다.

final MenuGroup menuGroup = new MenuGroup(UUID.randomUUID(), name);
return menuGroupRepository.save(menuGroup);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kitchenpos.menu.tobe.application.dto;

public class CreateMenuGroupCommand {

public final String name;

public CreateMenuGroupCommand(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import kitchenpos.common.profanity.FakeProfanityDetectService;
import kitchenpos.common.profanity.domain.ProfanityDetectService;
import kitchenpos.menu.InMemoryMenuGroupRepository;
import kitchenpos.menu.tobe.application.dto.CreateMenuGroupCommand;
import kitchenpos.menu.tobe.domain.entity.MenuGroup;
import kitchenpos.menu.tobe.domain.repository.MenuGroupRepository;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -21,25 +22,23 @@ class MenuGroupServiceTest {

private MenuGroupService menuGroupService;

private NameFactory nameFactory;

@BeforeEach
void setUp() {
menuGroupRepository = new InMemoryMenuGroupRepository();
menuGroupService = new MenuGroupService(menuGroupRepository);
final ProfanityDetectService profanityDetectService = new FakeProfanityDetectService();
nameFactory = new NameFactory(profanityDetectService);
final NameFactory nameFactory = new NameFactory(profanityDetectService);
menuGroupService = new MenuGroupService(menuGroupRepository, nameFactory);
}

@DisplayName("메뉴 그룹을 등록할 수 있다.")
@Test
void create() {
final MenuGroup expected = createMenuGroupRequest("두마리메뉴");
final MenuGroup actual = menuGroupService.create(expected);
final CreateMenuGroupCommand command = createMenuGroupCommand("두마리메뉴");
final MenuGroup actual = menuGroupService.create(command);
assertThat(actual).isNotNull();
assertAll(
() -> assertThat(actual.id).isNotNull(),
() -> assertThat(actual.name).isEqualTo(expected.name)
() -> assertThat(actual.name.value).isEqualTo(command.name)
);
}

Expand All @@ -51,7 +50,7 @@ void findAll() {
assertThat(actual).hasSize(1);
}

private MenuGroup createMenuGroupRequest(final String name) {
return new MenuGroup(null, this.nameFactory.create(name));
private CreateMenuGroupCommand createMenuGroupCommand(final String name) {
return new CreateMenuGroupCommand(name);
}
}