-
Notifications
You must be signed in to change notification settings - Fork 227
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
π 3λ¨κ³ - ν μ€νΈλ₯Ό ν΅ν μ½λ λ³΄νΈ #698
base: jinan159
Are you sure you want to change the base?
Changes from 22 commits
afc8aaa
a3065e9
82e9539
3cab8d9
fe24fc3
fcf6b5c
e605b79
fc5a00d
d0e4fd7
115417b
a534738
b3aa8aa
874ef87
2e17fcf
fc50bd3
6758d85
f6cfba7
173035d
c7c105e
442b945
6cbd2b6
cee895c
d846ca9
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,8 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface JpaMenuGroupRepository extends MenuGroupRepository, JpaRepository<MenuGroup, UUID> { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kitchenpos.domain; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface JpaMenuRepository extends MenuRepository, JpaRepository<Menu, UUID> { | ||
@Nonnull | ||
@Override | ||
List<Menu> findAllByIdIn(@Nonnull List<UUID> ids); | ||
|
||
@Nonnull | ||
@Override | ||
@Query("select m from Menu m join m.menuProducts mp where mp.product.id = :productId") | ||
List<Menu> findAllByProductId(@Nonnull @Param("productId") UUID productId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kitchenpos.domain; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface JpaOrderRepository extends OrderRepository, JpaRepository<Order, UUID> { | ||
@Override | ||
boolean existsByOrderTableAndStatusNot(@Nonnull OrderTable orderTable, @Nonnull OrderStatus status); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface JpaOrderTableRepository extends OrderTableRepository, JpaRepository<OrderTable, UUID> { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package kitchenpos.domain; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public interface JpaProductRepository extends ProductRepository, JpaRepository<Product, UUID> { | ||
@Nonnull | ||
List<Product> findAllByIdIn(@Nonnull List<UUID> ids); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface MenuGroupRepository extends JpaRepository<MenuGroup, UUID> { | ||
public interface MenuGroupRepository { | ||
Comment on lines
-7
to
+8
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. JpaRepositoryμ λλ©μΈμ λ νμ§ν 리λ₯Ό μ λλμ΄μ£Όμ ¨λ€μ π |
||
@Nonnull | ||
MenuGroup save(@Nonnull MenuGroup menuGroup); | ||
|
||
@Nonnull | ||
List<MenuGroup> findAll(); | ||
|
||
@Nonnull | ||
Optional<MenuGroup> findById(@Nonnull UUID menuGroupId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface MenuRepository extends JpaRepository<Menu, UUID> { | ||
List<Menu> findAllByIdIn(List<UUID> ids); | ||
public interface MenuRepository { | ||
@Nonnull | ||
Menu save(@Nonnull Menu menu); | ||
|
||
@Nonnull | ||
List<Menu> findAll(); | ||
|
||
@Nonnull | ||
List<Menu> findAllByIdIn(@Nonnull List<UUID> list); | ||
|
||
@Nonnull | ||
List<Menu> findAllByProductId(@Nonnull UUID productId); | ||
|
||
@Query("select m from Menu m join m.menuProducts mp where mp.product.id = :productId") | ||
List<Menu> findAllByProductId(@Param("productId") UUID productId); | ||
@Nonnull | ||
Optional<Menu> findById(@Nonnull UUID menuId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface OrderRepository extends JpaRepository<Order, UUID> { | ||
boolean existsByOrderTableAndStatusNot(OrderTable orderTable, OrderStatus status); | ||
public interface OrderRepository { | ||
@Nonnull | ||
Order save(@Nonnull Order order); | ||
|
||
@Nonnull | ||
Optional<Order> findById(@Nonnull UUID orderId); | ||
|
||
boolean existsByOrderTableAndStatusNot(@Nonnull OrderTable orderTable, @Nonnull OrderStatus orderStatus); | ||
|
||
@Nonnull | ||
List<Order> findAll(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface OrderTableRepository extends JpaRepository<OrderTable, UUID> { | ||
public interface OrderTableRepository { | ||
@Nonnull | ||
Optional<OrderTable> findById(@Nonnull UUID orderTableId); | ||
|
||
@Nonnull | ||
OrderTable save(@Nonnull OrderTable orderTable); | ||
|
||
@Nonnull | ||
List<OrderTable> findAll(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
package kitchenpos.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface ProductRepository extends JpaRepository<Product, UUID> { | ||
List<Product> findAllByIdIn(List<UUID> ids); | ||
public interface ProductRepository { | ||
@Nonnull | ||
List<Product> findAllByIdIn(@Nonnull List<UUID> list); | ||
|
||
@Nonnull | ||
Optional<Product> findById(@Nonnull UUID productId); | ||
|
||
@Nonnull | ||
List<Product> findAll(); | ||
|
||
@Nonnull | ||
Product save(@Nonnull Product product); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package kitchenpos.application | ||
|
||
import io.kotest.assertions.throwables.shouldThrowAny | ||
import io.kotest.core.spec.style.ShouldSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.types.shouldBeTypeOf | ||
import java.util.UUID | ||
import kitchenpos.domain.MenuGroup | ||
import kitchenpos.testsupport.FakeMenuGroupRepository | ||
|
||
class MenuGroupServiceCreateTest : ShouldSpec({ | ||
lateinit var service: MenuGroupService | ||
|
||
beforeTest { | ||
service = MenuGroupService( | ||
FakeMenuGroupRepository() | ||
) | ||
} | ||
|
||
context("λ©λ΄ κ·Έλ£Ή μμ±") { | ||
should("μ±κ³΅") { | ||
// given | ||
val request = createRequest( | ||
id = null | ||
) | ||
|
||
// when | ||
val result = service.create(request) | ||
|
||
// then | ||
result.name shouldBe request.name | ||
} | ||
|
||
should("μ€ν¨ - λ©λ΄ κ·Έλ£Ήλͺ μ΄ μ λ ₯λμ§ μμ κ²½μ°") { | ||
// given | ||
val request = createRequest( | ||
id = null, | ||
name = null | ||
) | ||
|
||
// when | ||
val result = shouldThrowAny { | ||
service.create(request) | ||
} | ||
|
||
// then | ||
result.shouldBeTypeOf<IllegalArgumentException>() | ||
} | ||
|
||
should("μ€ν¨ - λ©λ΄ κ·Έλ£Ήλͺ μ΄ λΉμ΄μλ κ²½μ°") { | ||
// given | ||
val request = createRequest( | ||
id = null, | ||
name = "" | ||
) | ||
|
||
// when | ||
val result = shouldThrowAny { | ||
service.create(request) | ||
} | ||
|
||
// then | ||
result.shouldBeTypeOf<IllegalArgumentException>() | ||
} | ||
} | ||
}) { | ||
companion object { | ||
private fun createRequest( | ||
id: UUID? = UUID.randomUUID(), | ||
name: String? = "test-menu-group-name" | ||
): MenuGroup { | ||
return MenuGroup().apply { | ||
this.id = id | ||
this.name = name | ||
|
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package kitchenpos.application | ||
|
||
import io.kotest.core.spec.style.ShouldSpec | ||
import io.kotest.matchers.collections.shouldNotBeEmpty | ||
import io.kotest.matchers.should | ||
import io.kotest.matchers.shouldBe | ||
import kitchenpos.domain.MenuGroupRepository | ||
import kitchenpos.testsupport.FakeMenuGroupRepository | ||
import kitchenpos.testsupport.MenuGroupFixtures.createMenuGroup | ||
|
||
class MenuGroupServiceFindAllTest : ShouldSpec({ | ||
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. FindAllμ΄λ Createμ κ°μ λ©μλ λ¨μλ‘ λλκ² λλ κ²½μ° μ΄ν λ§μ λ©μλκ° μκΈ°λ©΄ ν μ€νΈ ν΄λμ€κ° λ무 λ§μμ§ κ² κ°μμ. μ‘°ν / μμ / μμ μ κ°μ λ¨μλ‘ λλκ±°λ νΉμ 볡μ‘λκ° λμμ§λ μμ μ ν΄λμ€ μ체λ₯Ό λλλ κ²λ λ°©λ²μΌ κ² κ°μ΅λλ€. 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. μ‘°ν / μμ / μμ λ¨μλ‘ λλκ±°λ, νλλ‘ μμ±νλ€ λ³΅μ‘λκ° λμμ§λ μμ μ λΆλ¦¬νλ λ°©λ²λ μ’λ€κ³ μκ°ν©λλ€! μ΄μ²λΌ ν΄λμ€λ₯Ό λ§μ΄ λλκ² λλ©΄ λ°μν μ μλ λ¨μ μ μκ°ν΄λ³΄λ©΄,, νΉμ ν μ€νΈ ν΄λμ€κ° λ무 λ§μΌλ©΄ λ μ΄λ€ λ¨μ μ΄ μμκΉμ? |
||
lateinit var menuGroupRepository: MenuGroupRepository | ||
lateinit var service: MenuGroupService | ||
|
||
beforeTest { | ||
menuGroupRepository = FakeMenuGroupRepository() | ||
|
||
service = MenuGroupService( | ||
menuGroupRepository | ||
) | ||
} | ||
|
||
context("λ©λ΄ κ·Έλ£Ή λͺ©λ‘ μ‘°ν") { | ||
should("μ±κ³΅") { | ||
// given | ||
val savedMenuGroup = menuGroupRepository.save( | ||
createMenuGroup() | ||
) | ||
|
||
// when | ||
val result = service.findAll() | ||
|
||
// then | ||
result.shouldNotBeEmpty() | ||
result.first() should { menuGroup -> | ||
menuGroup.id shouldBe savedMenuGroup.id | ||
menuGroup.name shouldBe savedMenuGroup.name | ||
} | ||
} | ||
} | ||
}) |
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.
ProductRepositoryμ κ°μ λ νμ§ν 리λ€μ΄ λλ©μΈ ν¨ν€μ§μ μλ κ²μ μ΄ν΄κ° κ°λλ°μ, μΈν°νμ΄μ€κΈ΄ νμ§λ§ μ¬μ€μ Jpaμ μ§μ μ°κ΄λμ΄ μκΈ° λλ¬Έμ domain μμμ΄ μλλΌκ³ λ³Ό μ μμ κ² κ°μμ. μ΄μ λν΄ μ΄λ»κ² μκ°νμλμ?
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.
λ§μνμ λλ‘, Jpa κ΄λ ¨ κΈ°λ₯μ΄λ€ 보λ domain 보λ€λ infra μμμ μλκ² μ΄μΈλ¦΄ κ² κ°μ΅λλ€!