forked from Exagonal-Study/est-delivery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from this-is-spear/port
�유스케이스를 작성한다.
- Loading branch information
Showing
55 changed files
with
1,178 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/example/estdelivery/application/HandoutCouponService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.estdelivery.application | ||
|
||
import com.example.estdelivery.application.port.`in`.HandoutCouponUseCase | ||
import com.example.estdelivery.application.port.`in`.command.HandoutCouponCommand | ||
import com.example.estdelivery.application.port.out.CreateCouponStatePort | ||
import com.example.estdelivery.application.port.out.LoadCouponStatePort | ||
import com.example.estdelivery.application.port.out.LoadShopOwnerStatePort | ||
import com.example.estdelivery.application.port.out.UpdateShopOwnerStatePort | ||
import com.example.estdelivery.application.port.out.state.CouponState | ||
import com.example.estdelivery.application.port.out.state.ShopOwnerState | ||
import com.example.estdelivery.domain.coupon.Coupon | ||
|
||
class HandoutCouponService( | ||
private val loadShopOwnerStatePort: LoadShopOwnerStatePort, | ||
private val loadCouponStatePort: LoadCouponStatePort, | ||
private val updateShopOwnerStatePort: UpdateShopOwnerStatePort, | ||
private val createCouponStatePort: CreateCouponStatePort, | ||
) : HandoutCouponUseCase { | ||
/** | ||
* 1. 가게 주인 정보를 조회한다. | ||
* 2. 가게 정보를 조회한다. | ||
* 3. 단골들 중 동일한 쿠폰을 아직 받지 않은 사용자에게 쿠폰을 뿌린다. | ||
* | ||
* @param handoutCouponCommand 나눠줄 쿠폰 정보와 가게 주인 정보 | ||
*/ | ||
override fun handoutCoupon(handoutCouponCommand: HandoutCouponCommand) { | ||
val shopOwner = loadShopOwnerStatePort.findById(handoutCouponCommand.shopOwnerId).toShopOwner() | ||
val handoutCoupon: Coupon = getHandoutCoupon(handoutCouponCommand) | ||
shopOwner.handOutCouponToRoyalCustomersInShop(handoutCoupon) | ||
updateShopOwnerStatePort.update(ShopOwnerState.from(shopOwner)) | ||
} | ||
|
||
private fun getHandoutCoupon(handoutCouponCommand: HandoutCouponCommand): Coupon { | ||
val id = handoutCouponCommand.coupon.id | ||
if (id == null || loadCouponStatePort.exists(id).not()) { | ||
val handoutCoupon = createCouponStatePort.create(CouponState.from(handoutCouponCommand.coupon)).toCoupon() | ||
return handoutCoupon | ||
} | ||
|
||
val handoutCoupon: Coupon = loadCouponStatePort.findById(id).toCoupon() | ||
return handoutCoupon | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/com/example/estdelivery/application/IssuePublishedCouponService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.example.estdelivery.application | ||
|
||
import com.example.estdelivery.application.port.`in`.IssuePublishedCouponUseCase | ||
import com.example.estdelivery.application.port.`in`.command.IssuePublishedCouponCommand | ||
import com.example.estdelivery.application.port.out.* | ||
import com.example.estdelivery.application.port.out.state.MemberState | ||
import com.example.estdelivery.application.port.out.state.ShopOwnerState | ||
import com.example.estdelivery.domain.member.Member | ||
import com.example.estdelivery.domain.shop.ShopOwner | ||
|
||
class IssuePublishedCouponService( | ||
private val loadMemberStatePort: LoadMemberStatePort, | ||
private val loadCouponStatePort: LoadCouponStatePort, | ||
private val loadShopOwnerStatePort: LoadShopOwnerStatePort, | ||
private val updateMemberStatePort: UpdateMemberStatePort, | ||
private val updateShopOwnerStatePort: UpdateShopOwnerStatePort, | ||
) : IssuePublishedCouponUseCase { | ||
/** | ||
* 1. 회원 정보를 조회한다. | ||
* 2. 쿠폰정보를 조회한다. | ||
* 3. 가게가 가진 게시된 쿠폰 북에서 쿠폰을 발행한다. | ||
* 4. 발급된 쿠폰을 사용자의 쿠폰북에 추가한다. | ||
* 5. 가게 단골 손님으로 등록한다. | ||
* | ||
* @param issuePublishedCouponCommand 발행된 쿠폰을 사용자에게 발급하는 명령 | ||
*/ | ||
override fun issuePublishedCoupon(issuePublishedCouponCommand: IssuePublishedCouponCommand) { | ||
val member = getMember(issuePublishedCouponCommand) | ||
val shopOwner = getShopOwner(issuePublishedCouponCommand) | ||
val coupon = getCoupon(issuePublishedCouponCommand) | ||
member.receiveCoupon(shopOwner.issuePublishedCouponInShop(coupon)) | ||
updateMember(member) | ||
addRoyalCustomers(shopOwner, member) | ||
} | ||
|
||
private fun addRoyalCustomers( | ||
shopOwner: ShopOwner, | ||
member: Member | ||
) { | ||
if (!shopOwner.showRoyalCustomersInShop().contains(member)) { | ||
shopOwner.addRoyalCustomersInShop(member) | ||
updateShopOwnerStatePort.update(ShopOwnerState.from(shopOwner)) | ||
} | ||
} | ||
|
||
private fun updateMember(member: Member) { | ||
updateMemberStatePort.update(MemberState.from(member)) | ||
} | ||
|
||
private fun getShopOwner(issuePublishedCouponCommand: IssuePublishedCouponCommand) = | ||
loadShopOwnerStatePort.findByShopId(issuePublishedCouponCommand.shopId).toShopOwner() | ||
|
||
private fun getCoupon(issuePublishedCouponCommand: IssuePublishedCouponCommand) = | ||
loadCouponStatePort.findByCouponId(issuePublishedCouponCommand.couponId).toCoupon() | ||
|
||
private fun getMember(issuePublishedCouponCommand: IssuePublishedCouponCommand) = | ||
loadMemberStatePort.findById(issuePublishedCouponCommand.memberId).toMember() | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/com/example/estdelivery/application/PublishCouponService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.example.estdelivery.application | ||
|
||
import com.example.estdelivery.application.port.`in`.PublishCouponUseCase | ||
import com.example.estdelivery.application.port.`in`.command.PublishCouponCommand | ||
import com.example.estdelivery.application.port.out.CreateCouponStatePort | ||
import com.example.estdelivery.application.port.out.LoadShopOwnerStatePort | ||
import com.example.estdelivery.application.port.out.UpdateShopOwnerStatePort | ||
import com.example.estdelivery.application.port.out.state.CouponState | ||
import com.example.estdelivery.application.port.out.state.ShopOwnerState | ||
|
||
class PublishCouponService( | ||
private val loadShopOwnerPort: LoadShopOwnerStatePort, | ||
private val createCouponStatePort: CreateCouponStatePort, | ||
private val updateShopOwnerStatePort: UpdateShopOwnerStatePort, | ||
) : PublishCouponUseCase { | ||
/** | ||
* 1. 가게 주인 정보를 조회한다. | ||
* 2. 가게 정보를 조회한다. | ||
* 3. 쿠폰을 생성한다. | ||
* 4. 가게에 게시된 쿠폰북에 게시한다. | ||
* | ||
* @param publishCouponCommand 게시할 쿠폰 정보와 가게 주인 정보 | ||
*/ | ||
override fun publishCoupon(publishCouponCommand: PublishCouponCommand) { | ||
val shopOwner = loadShopOwnerPort.findById(publishCouponCommand.shopOwnerId).toShopOwner() | ||
val publishedCoupon = createCouponStatePort.create(CouponState.from(publishCouponCommand.coupon)).toCoupon() | ||
shopOwner.publishCouponInShop(publishedCoupon) | ||
updateShopOwnerStatePort.update(ShopOwnerState.from(shopOwner)) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/com/example/estdelivery/application/UseCouponService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.example.estdelivery.application | ||
|
||
import com.example.estdelivery.application.port.`in`.UseCouponUseCase | ||
import com.example.estdelivery.application.port.`in`.command.UseCouponCommand | ||
import com.example.estdelivery.application.port.out.* | ||
import com.example.estdelivery.application.port.out.state.MemberState | ||
import com.example.estdelivery.application.port.out.state.ShopOwnerState | ||
|
||
class UseCouponService( | ||
private val loadMemberStatePort: LoadMemberStatePort, | ||
private val loadCouponStatePort: LoadCouponStatePort, | ||
private val loadShopOwnerStatePort: LoadShopOwnerStatePort, | ||
private val updateMemberStatePort: UpdateMemberStatePort, | ||
private val updateShopOwnerStatePort: UpdateShopOwnerStatePort, | ||
) : UseCouponUseCase { | ||
/** | ||
* 1. 회원 정보를 조회한다. | ||
* 2. 쿠폰 정보를 조회한다. | ||
* 3. 회원이 가진 쿠폰북에서 쿠폰을 꺼낸다. | ||
* 4. 가게주인은 사용할 쿠폰을 받는다. | ||
* | ||
* @param useCouponCommand 사용할 쿠폰 정보와 회원 정보 | ||
*/ | ||
override fun useCoupon(useCouponCommand: UseCouponCommand) { | ||
val member = loadMemberStatePort.findById(useCouponCommand.memberId).toMember() | ||
val coupon = loadCouponStatePort.findById(useCouponCommand.couponId).toCoupon() | ||
val shopOwner = loadShopOwnerStatePort.findByShopId(useCouponCommand.shopId).toShopOwner() | ||
|
||
member.useCoupon(coupon) | ||
shopOwner.receiveCoupon(coupon) | ||
|
||
updateMemberStatePort.update(MemberState.from(member)) | ||
updateShopOwnerStatePort.update(ShopOwnerState.from(shopOwner)) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/example/estdelivery/application/port/in/HandoutCouponUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.estdelivery.application.port.`in` | ||
|
||
import com.example.estdelivery.application.port.`in`.command.HandoutCouponCommand | ||
|
||
interface HandoutCouponUseCase { | ||
/** | ||
* 가게 사장은 단골들에게 쿠폰을 나눠줄 수 있다. | ||
* @param handoutCouponCommand 나눠줄 쿠폰 정보와 가게 주인 정보 | ||
*/ | ||
fun handoutCoupon(handoutCouponCommand: HandoutCouponCommand) | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/example/estdelivery/application/port/in/IssuePublishedCouponUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.estdelivery.application.port.`in` | ||
|
||
import com.example.estdelivery.application.port.`in`.command.IssuePublishedCouponCommand | ||
|
||
interface IssuePublishedCouponUseCase { | ||
/** | ||
* 회원은 가게에 게시된 쿠폰을 발생한다. 이미 발행된 쿠폰은 재발행 할 수 없고, 게시되지 않은 쿠폰은 발행할 수 없다. | ||
* @param issuePublishedCouponCommand | ||
*/ | ||
fun issuePublishedCoupon(issuePublishedCouponCommand: IssuePublishedCouponCommand) | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/example/estdelivery/application/port/in/PublishCouponUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.estdelivery.application.port.`in` | ||
|
||
import com.example.estdelivery.application.port.`in`.command.PublishCouponCommand | ||
|
||
interface PublishCouponUseCase { | ||
/** | ||
* 가게 주인은 가게에 쿠폰을 게시한다. | ||
* @param publishCouponCommand 게시할 쿠폰 정보와 가게 주인 정보 | ||
*/ | ||
fun publishCoupon(publishCouponCommand: PublishCouponCommand) | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/example/estdelivery/application/port/in/UseCouponUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.estdelivery.application.port.`in` | ||
|
||
import com.example.estdelivery.application.port.`in`.command.UseCouponCommand | ||
|
||
interface UseCouponUseCase { | ||
fun useCoupon(useCouponCommand: UseCouponCommand) | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/example/estdelivery/application/port/in/command/HandoutCouponCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.example.estdelivery.application.port.`in`.command | ||
|
||
import com.example.estdelivery.domain.coupon.Coupon | ||
|
||
class HandoutCouponCommand(val shopOwnerId: Long, val shopId: Long, val coupon: Coupon) |
7 changes: 7 additions & 0 deletions
7
...kotlin/com/example/estdelivery/application/port/in/command/IssuePublishedCouponCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.estdelivery.application.port.`in`.command | ||
|
||
data class IssuePublishedCouponCommand( | ||
val couponId: Long, | ||
val memberId: Long, | ||
val shopId: Long, | ||
) |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/example/estdelivery/application/port/in/command/PublishCouponCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.estdelivery.application.port.`in`.command | ||
|
||
import com.example.estdelivery.domain.coupon.Coupon | ||
|
||
data class PublishCouponCommand( | ||
val shopOwnerId: Long, | ||
val shopId: Long, | ||
val coupon: Coupon, | ||
) |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/example/estdelivery/application/port/in/command/UseCouponCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.estdelivery.application.port.`in`.command | ||
|
||
class UseCouponCommand( | ||
val memberId: Long, | ||
val couponId: Long, | ||
val shopId: Long | ||
) |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/example/estdelivery/application/port/out/CreateCouponStatePort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.estdelivery.application.port.out | ||
|
||
import com.example.estdelivery.application.port.out.state.CouponState | ||
|
||
interface CreateCouponStatePort { | ||
fun create(couponState: CouponState): CouponState | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/example/estdelivery/application/port/out/LoadCouponStatePort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.estdelivery.application.port.out | ||
|
||
import com.example.estdelivery.application.port.out.state.CouponState | ||
|
||
interface LoadCouponStatePort { | ||
fun findByCouponId(couponId: Long): CouponState | ||
fun exists(couponId: Long): Boolean | ||
fun findById(couponId: Long): CouponState | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/example/estdelivery/application/port/out/LoadMemberStatePort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.estdelivery.application.port.out | ||
|
||
import com.example.estdelivery.application.port.out.state.MemberState | ||
|
||
interface LoadMemberStatePort { | ||
fun findById(memberId: Long): MemberState | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/example/estdelivery/application/port/out/LoadShopOwnerStatePort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.estdelivery.application.port.out | ||
|
||
import com.example.estdelivery.application.port.out.state.ShopOwnerState | ||
|
||
interface LoadShopOwnerStatePort { | ||
fun findById(shopOwnerId: Long): ShopOwnerState | ||
fun findByShopId(shopId: Long): ShopOwnerState | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/example/estdelivery/application/port/out/LoadShopStatePort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.estdelivery.application.port.out | ||
|
||
import com.example.estdelivery.application.port.out.state.ShopState | ||
|
||
interface LoadShopStatePort { | ||
fun findById(shopId: Long): ShopState | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/example/estdelivery/application/port/out/UpdateMemberStatePort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.estdelivery.application.port.out | ||
|
||
import com.example.estdelivery.application.port.out.state.MemberState | ||
|
||
interface UpdateMemberStatePort { | ||
fun update(memberState: MemberState) | ||
} |
Oops, something went wrong.