-
Notifications
You must be signed in to change notification settings - Fork 177
🚀 2단계 - 리팩터링(메뉴) #225
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: jordy-torvalds
Are you sure you want to change the base?
🚀 2단계 - 리팩터링(메뉴) #225
Changes from all commits
7e635b3
d7dcb5a
2ec3c6b
9468aeb
a740671
51089c9
66cfe66
693182c
2d0c25a
1102fec
aae4bd0
716390f
cdcde36
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,17 @@ | ||
| package kitchenpos.common.annotation; | ||
|
|
||
| import org.springframework.core.annotation.AliasFor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.lang.annotation.*; | ||
|
|
||
| @Target(ElementType.TYPE) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Documented | ||
| @Component | ||
| public @interface Validator { | ||
|
|
||
| @AliasFor(annotation = Component.class) | ||
| String value() default ""; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package kitchenpos.common.domain; | ||
|
|
||
| import org.springframework.data.domain.AfterDomainEventPublication; | ||
| import org.springframework.data.domain.DomainEvents; | ||
|
|
||
| import javax.persistence.Transient; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public interface AggregateRoot { | ||
|
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. 애그리거트 루트를 직접 인터페이스를 통해 이벤트 발행까지 만들어주셨네요 👍 👍 |
||
|
|
||
| @Transient | ||
| ThreadLocal<List<Object>> threadLocal = ThreadLocal.withInitial(ArrayList::new); | ||
|
|
||
| default Object register(Object event) { | ||
|
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. 인터페이스의 default 메서드가 추가된 배경은 무엇일까요? |
||
| if (event == null) { | ||
| return event; | ||
| } | ||
| threadLocal.get().add(event); | ||
| return event; | ||
| } | ||
|
|
||
| @AfterDomainEventPublication | ||
| default void clear() { | ||
| threadLocal.get().clear(); | ||
| } | ||
|
|
||
| @DomainEvents | ||
| default List<Object> domainEvents() { | ||
| return new ArrayList<>(threadLocal.get()); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package kitchenpos.common.util; | ||
|
|
||
| import kitchenpos.common.exception.KitchenPosException; | ||
| import org.springframework.lang.Nullable; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| public class CollectionUtils { | ||
|
|
||
| private CollectionUtils() { | ||
| } | ||
|
|
||
| public static void requireNonEmpty(@Nullable Collection<?> collection, KitchenPosException exception) { | ||
| if (collection == null || collection.isEmpty()) { | ||
| throw exception; | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package kitchenpos.common; | ||
| package kitchenpos.common.util; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package kitchenpos.common.values; | ||
|
|
||
| import kitchenpos.common.exception.KitchenPosException; | ||
| import kitchenpos.common.exception.KitchenPosExceptionType; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Embeddable; | ||
| import java.util.Objects; | ||
|
|
||
| @Embeddable | ||
| public class Quantity { | ||
|
|
||
| @Column(name = "quantity", nullable = false) | ||
| private Long value; | ||
|
|
||
| protected Quantity() { | ||
| } | ||
|
|
||
| public Quantity(final Long value) { | ||
| if (value < 0) { | ||
| String message = String.format("수량이 %s 이므로", value); | ||
| throw new KitchenPosException(message, KitchenPosExceptionType.BAD_REQUEST); | ||
| } | ||
| this.value = value; | ||
| } | ||
|
|
||
| public Long getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public boolean equalValue(Long value) { | ||
| return this.value.equals(value); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Quantity quantity = (Quantity) o; | ||
| return Objects.equals(value, quantity.value); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(value); | ||
| } | ||
| } |
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.
지속적으로 요구사항 수정 👍 👍
요구사항에 변경됨에 따라 모델링도 수정해보는 것은 어떤가요?
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.
미션 진행하시면서 지속적으로 모델링 업데이트도 부탁드려요
지금까지 미션 진행하시면서 도메인 지식이 많이 쌓이셨을 것 같은데요~
구현하신 코드와 모델링 싱크 확인 부탁드려요