From 70c31bc24f8b463324b6dedc7e69435ac329851b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 22:43:39 +0900 Subject: [PATCH 01/33] =?UTF-8?q?chore=20:=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=20=EB=AA=A8=EB=8D=B8=EB=A7=81=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac1071b..59ded3f 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,153 @@ 2. fork한 레포지토리를 clone합니다. 3. clone한 레포지토리에서 브랜치를 생성합니다. (브랜치 이름은 자유롭게) 4. 해당 브랜치에서 작업을 진행합니다. -5. 작업이 완료되면 PR을 보냅니다. (PR은 각 이름 브랜치로 보내주세요.) \ No newline at end of file +5. 작업이 완료되면 PR을 보냅니다. (PR은 각 이름 브랜치로 보내주세요.) + +## 설계 과정 + +### 요구사항 정리 + +- 쿠폰은 OOO 대상을 할인하기 위한 목적이다. + - 가게에 진열된 상품 대상 +- 회원은 OOO 행동으로 쿠폰을 발급받는다. + - 가게에 접근해 쿠폰 발급 버튼을 누르는 행동 + - 가게 주인이 가게 쿠폰을 가져갔던 손님들에게 쿠폰을 뿌리는 행동 +- 쿠폰의 할인 정책은 OOO 방법을 적용한다. + - 고정금액을 할인하는 정액제 방법 + - 비율로 할인하는 정률제 방법 + +### 프로그래밍 요구사항 정리 + +- 발급받은 쿠폰 식별자는 시간대별로 순서가 보장되어야 한다. + +> ID는 시간대별 순서가 보장되도록 고민한 이유는 쿠폰은 유효기간이 존재하고 제약 조건도 많아 사용자의 기억속에 휘발성이 많다고 생각해서이다. 그래서 시간 지역성을 띈다고 생각했고 한 번 조회할 때마다 하나의 블록을 읽어오는 InnonDB의 특성을 잘 살릴 수 있어보였다. + +### 도메인 모델링 + +```mermaid +--- +title: 이달의 민족 +--- +classDiagram + Shop *-- CouponBook + Shop *-- RoyalCustomers + RoyalCustomers *-- Member + Member *-- CouponBook + CouponBook *-- Coupon + FixDiscountCoupon --|> Coupon + RateDiscountCoupon --|> Coupon + ShopOwner *-- Shop + + class CouponBook{ + -List~Coupon~ coupons + +existCoupon(Coupon coupon) void + +deleteCoupon(Coupon coupon) void + +addCoupon(Coupon coupon) void + } + + class Coupon{ + -Shop shop + -String name + -String description + -Enum couponType + +isPublished() boolean + +isHandOut() boolean + } + + class FixDiscountCoupon{ + -Int discountAmount + } + + class RateDiscountCoupon{ + -Int discountRate + } + + class Member{ + -String name + -CouponBook unUsedCouponBook + +useCoupon(Coupon Coupon) void + +showMyCouponBook() CouponBook + +receiveCoupon(Coupon coupon) void + } + + class ShopOwner{ + -Shop shop + +handOutCouponToRoyalCustomersInShop(Shop shop) void + +publishCouponInShop(Shop shop, Coupon coupon) void + } + + class Shop{ + -String shopName + -CouponBook publishedCoupons + -CouponBook usedCouponBook + -RoyalCustomers royalCustomers + +publishCoupon(Coupon coupon) void + +alreadyUsedCoupon(Coupon coupon) boolean + +handOutPublishedCoupon(Coupon coupon) Coupon + +handOutCouponToRoyalCustomers(Coupon coupon) void + +showPublishedCoupon() CouponBook + } + + class RoyalCustomers{ + -List~Member~ members + +handOutCoupon(Coupon coupon) void + } + +``` + + +### 데이터 모델링 + +```mermaid +--- +title: 이달의 민족 +--- + +erDiagram + + royal_member { + long shop_id + long member_id + } + + shop { + long id pk + string name + long boss_id + long published_coupon_book_id + } + + member { + long id pk + string name + long members_coupon_book_id + } + + published_coupon_book { + long shop_id + long coupon_id + } + + coupon { + long id pk + long shop_id + string name + string description + string type + int amount + string type + } + + members_coupon_book { + long member_id + long coupon_id + string status + } + + royal_member }o--|| member : contain + royal_member }o--|| shop : manage + members_coupon_book ||--o{ coupon : contains + members_coupon_book ||--o{ member : have + published_coupon_book ||--o{ shop : have + published_coupon_book ||--o{ coupon : contains +``` \ No newline at end of file From 79fa949f0c244f5ea1fa917c7df6fb3f6cdb9f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 22:47:34 +0900 Subject: [PATCH 02/33] =?UTF-8?q?chore=20:=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=20=EB=AA=A8=EB=8D=B8=EB=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59ded3f..72ad4ed 100644 --- a/README.md +++ b/README.md @@ -60,12 +60,13 @@ classDiagram } class Coupon{ - -Shop shop -String name -String description -Enum couponType + -boolean isUsed +isPublished() boolean +isHandOut() boolean + +isUser() boolean } class FixDiscountCoupon{ From 8d4a09b811c3e0b95532db118f49908f0b534b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 22:48:04 +0900 Subject: [PATCH 03/33] =?UTF-8?q?chore=20:=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72ad4ed..5e2bf81 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ classDiagram -boolean isUsed +isPublished() boolean +isHandOut() boolean - +isUser() boolean + +isUsed() boolean } class FixDiscountCoupon{ From 3f2b1676325d1a12ba50193d76a84df131050f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 22:55:27 +0900 Subject: [PATCH 04/33] =?UTF-8?q?chore=20:=20=ED=95=84=EC=9A=94=EC=97=90?= =?UTF-8?q?=20=EB=A7=9E=EB=8A=94=20=ED=96=89=EC=9C=84=EB=A7=8C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=A0=20=EA=B2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 5e2bf81..9810892 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,8 @@ classDiagram -String name -String description -Enum couponType - -boolean isUsed +isPublished() boolean +isHandOut() boolean - +isUsed() boolean } class FixDiscountCoupon{ From b0025d7e1c82b24d93a8e4c30246e4293c8a1e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 22:58:42 +0900 Subject: [PATCH 05/33] =?UTF-8?q?feature=20:=20coupon=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/estdelivery/domain/coupon/Coupon.kt | 15 +++++++++++++++ .../estdelivery/domain/coupon/CouponType.kt | 5 +++++ .../estdelivery/domain/coupon/CouponTest.kt | 17 +++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt create mode 100644 src/main/kotlin/com/example/estdelivery/domain/coupon/CouponType.kt create mode 100644 src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt new file mode 100644 index 0000000..6e1aa55 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt @@ -0,0 +1,15 @@ +package com.example.estdelivery.domain.coupon + +data class Coupon( + val name: String, + val description: String, + private val couponType: CouponType +) { + fun isPublished(): Boolean { + return couponType == CouponType.IS_PUBLISHED + } + + fun isHandOut(): Boolean { + return couponType == CouponType.IS_HAND_OUT + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponType.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponType.kt new file mode 100644 index 0000000..dd6043b --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponType.kt @@ -0,0 +1,5 @@ +package com.example.estdelivery.domain.coupon + +enum class CouponType { + IS_PUBLISHED, IS_HAND_OUT +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt new file mode 100644 index 0000000..2c4df7f --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt @@ -0,0 +1,17 @@ +package com.example.estdelivery.domain.coupon + +import io.kotest.core.spec.style.FreeSpec +import io.kotest.matchers.shouldBe + +class CouponTest : FreeSpec({ + + "게시된 쿠폰인지 확인 할 수 있다." { + val coupon = Coupon("쿠폰", "쿠폰 설명", CouponType.IS_PUBLISHED) + coupon.isPublished() shouldBe true + } + + "발급된 쿠폰인지 확인 할 수 있다." { + val coupon = Coupon("쿠폰", "쿠폰 설명", CouponType.IS_HAND_OUT) + coupon.isHandOut() shouldBe true + } +}) From 20a972a25d0bc5a76da794f173a0a28006dfd4b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:06:53 +0900 Subject: [PATCH 06/33] =?UTF-8?q?feature=20:=20=ED=95=A0=EC=9D=B8=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EC=A2=85=EB=A5=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/estdelivery/domain/coupon/Coupon.kt | 6 +++--- .../domain/coupon/FixDiscountCoupon.kt | 10 ++++++++++ .../domain/coupon/RateDiscountCoupon.kt | 11 +++++++++++ .../estdelivery/domain/coupon/CouponTest.kt | 16 ++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/coupon/FixDiscountCoupon.kt create mode 100644 src/main/kotlin/com/example/estdelivery/domain/coupon/RateDiscountCoupon.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt index 6e1aa55..89caf68 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt @@ -1,8 +1,8 @@ package com.example.estdelivery.domain.coupon -data class Coupon( - val name: String, - val description: String, +open class Coupon( + open val name: String, + open val description: String, private val couponType: CouponType ) { fun isPublished(): Boolean { diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/FixDiscountCoupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/FixDiscountCoupon.kt new file mode 100644 index 0000000..798b212 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/FixDiscountCoupon.kt @@ -0,0 +1,10 @@ +package com.example.estdelivery.domain.coupon + +class FixDiscountCoupon( + val discountAmount: Int, + override val name: String, + override val description: String, + private val couponType: CouponType +) : Coupon(name, description, couponType) { + +} \ No newline at end of file diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/RateDiscountCoupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/RateDiscountCoupon.kt new file mode 100644 index 0000000..bb657e7 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/RateDiscountCoupon.kt @@ -0,0 +1,11 @@ +package com.example.estdelivery.domain.coupon + +class RateDiscountCoupon( + val discountRate: Int, + override val name: String, + override val description: String, + private val couponType: CouponType +): Coupon(name, description, couponType) { + + +} \ No newline at end of file diff --git a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt index 2c4df7f..3a25e8e 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt @@ -4,14 +4,22 @@ import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe class CouponTest : FreeSpec({ + val 나눠준_비율_할인_쿠폰 = RateDiscountCoupon(10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + val 게시된_고정_할인_쿠폰 = FixDiscountCoupon(1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) "게시된 쿠폰인지 확인 할 수 있다." { - val coupon = Coupon("쿠폰", "쿠폰 설명", CouponType.IS_PUBLISHED) - coupon.isPublished() shouldBe true + 게시된_고정_할인_쿠폰.isPublished() shouldBe true } "발급된 쿠폰인지 확인 할 수 있다." { - val coupon = Coupon("쿠폰", "쿠폰 설명", CouponType.IS_HAND_OUT) - coupon.isHandOut() shouldBe true + 나눠준_비율_할인_쿠폰.isHandOut() shouldBe true + } + + "할인율 쿠폰을 생성할 수 있다." { + 나눠준_비율_할인_쿠폰.discountRate shouldBe 10 + } + + "고정 할인 쿠폰을 생성할 수 있다." { + 게시된_고정_할인_쿠폰.discountAmount shouldBe 1000 } }) From 01c526638eac238b84601767af34fe3ddb011ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:09:14 +0900 Subject: [PATCH 07/33] =?UTF-8?q?refactor=20:=20=EC=BF=A0=ED=8F=B0=20?= =?UTF-8?q?=EC=A2=85=EB=A5=98=20=EC=A0=9C=ED=95=9C=EB=90=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/estdelivery/domain/coupon/Coupon.kt | 15 ++++++++++++++- .../domain/coupon/FixDiscountCoupon.kt | 10 ---------- .../domain/coupon/RateDiscountCoupon.kt | 11 ----------- .../estdelivery/domain/coupon/CouponTest.kt | 4 ++-- 4 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 src/main/kotlin/com/example/estdelivery/domain/coupon/FixDiscountCoupon.kt delete mode 100644 src/main/kotlin/com/example/estdelivery/domain/coupon/RateDiscountCoupon.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt index 89caf68..e85c721 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt @@ -1,10 +1,23 @@ package com.example.estdelivery.domain.coupon -open class Coupon( +sealed class Coupon( open val name: String, open val description: String, private val couponType: CouponType ) { + class RateDiscountCoupon( + val discountRate: Int, + override val name: String, + override val description: String, + couponType: CouponType + ) : Coupon(name, description, couponType) + class FixDiscountCoupon( + val discountAmount: Int, + override val name: String, + override val description: String, + couponType: CouponType + ) : Coupon(name, description, couponType) + fun isPublished(): Boolean { return couponType == CouponType.IS_PUBLISHED } diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/FixDiscountCoupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/FixDiscountCoupon.kt deleted file mode 100644 index 798b212..0000000 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/FixDiscountCoupon.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.example.estdelivery.domain.coupon - -class FixDiscountCoupon( - val discountAmount: Int, - override val name: String, - override val description: String, - private val couponType: CouponType -) : Coupon(name, description, couponType) { - -} \ No newline at end of file diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/RateDiscountCoupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/RateDiscountCoupon.kt deleted file mode 100644 index bb657e7..0000000 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/RateDiscountCoupon.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.estdelivery.domain.coupon - -class RateDiscountCoupon( - val discountRate: Int, - override val name: String, - override val description: String, - private val couponType: CouponType -): Coupon(name, description, couponType) { - - -} \ No newline at end of file diff --git a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt index 3a25e8e..8f74403 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt @@ -4,8 +4,8 @@ import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe class CouponTest : FreeSpec({ - val 나눠준_비율_할인_쿠폰 = RateDiscountCoupon(10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) - val 게시된_고정_할인_쿠폰 = FixDiscountCoupon(1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + val 나눠준_비율_할인_쿠폰 = Coupon.RateDiscountCoupon(10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + val 게시된_고정_할인_쿠폰 = Coupon.FixDiscountCoupon(1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) "게시된 쿠폰인지 확인 할 수 있다." { 게시된_고정_할인_쿠폰.isPublished() shouldBe true From a9f4f3a1fcd089eed204a8d405762ead47669c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:22:55 +0900 Subject: [PATCH 08/33] =?UTF-8?q?feature=20:=20coupon=20book=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estdelivery/domain/coupon/Coupon.kt | 20 ++++++++- .../estdelivery/domain/coupon/CouponBook.kt | 19 ++++++++ .../domain/coupon/CouponBookTest.kt | 43 +++++++++++++++++++ .../estdelivery/domain/coupon/CouponTest.kt | 4 +- 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt create mode 100644 src/test/kotlin/com/example/estdelivery/domain/coupon/CouponBookTest.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt index e85c721..04ba8ea 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt @@ -1,22 +1,25 @@ package com.example.estdelivery.domain.coupon sealed class Coupon( + private val id: Long, open val name: String, open val description: String, private val couponType: CouponType ) { class RateDiscountCoupon( + id: Long, val discountRate: Int, override val name: String, override val description: String, couponType: CouponType - ) : Coupon(name, description, couponType) + ) : Coupon(id, name, description, couponType) class FixDiscountCoupon( + id: Long, val discountAmount: Int, override val name: String, override val description: String, couponType: CouponType - ) : Coupon(name, description, couponType) + ) : Coupon(id, name, description, couponType) fun isPublished(): Boolean { return couponType == CouponType.IS_PUBLISHED @@ -25,4 +28,17 @@ sealed class Coupon( fun isHandOut(): Boolean { return couponType == CouponType.IS_HAND_OUT } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Coupon + + return id == other.id + } + + override fun hashCode(): Int { + return id.hashCode() + } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt new file mode 100644 index 0000000..21a2422 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt @@ -0,0 +1,19 @@ +package com.example.estdelivery.domain.coupon + +class CouponBook( + private val coupons: MutableList = mutableListOf() +) { + fun deleteCoupon(coupon: Coupon) { + if (!coupons.contains(coupon)) { + throw IllegalArgumentException("존재하지 않는 쿠폰입니다.") + } + coupons.remove(coupon) + } + + fun addCoupon(coupon: Coupon) { + if (coupons.contains(coupon)) { + throw IllegalArgumentException("이미 존재하는 쿠폰입니다.") + } + coupons.add(coupon) + } +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponBookTest.kt b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponBookTest.kt new file mode 100644 index 0000000..7826e1b --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponBookTest.kt @@ -0,0 +1,43 @@ +package com.example.estdelivery.domain.coupon + +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.FreeSpec +import io.kotest.matchers.shouldBe + +class CouponBookTest : FreeSpec({ + + lateinit var couponBook: CouponBook + val 나눠준_비율_할인_쿠폰 = Coupon.RateDiscountCoupon(1, 10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + val 게시된_고정_할인_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + + beforeTest { + couponBook = CouponBook() + } + + "쿠폰을 추가할 수 있다." { + couponBook.addCoupon(나눠준_비율_할인_쿠폰) + couponBook.addCoupon(게시된_고정_할인_쿠폰) + } + + "쿠폰을 삭제할 수 있다." { + couponBook.addCoupon(나눠준_비율_할인_쿠폰) + couponBook.deleteCoupon(나눠준_비율_할인_쿠폰) + } + + "쿠폰을 중복으로 추가할 수 없다." { + val coupon = 나눠준_비율_할인_쿠폰 + couponBook.addCoupon(coupon) + val exception = shouldThrow { + couponBook.addCoupon(나눠준_비율_할인_쿠폰) + } + exception.message shouldBe "이미 존재하는 쿠폰입니다." + } + + "존재하지 않는 쿠폰을 삭제할 수 없다." { + val 존재하지_않는_쿠폰 = Coupon.RateDiscountCoupon(3, 10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + val exception = shouldThrow { + couponBook.deleteCoupon(존재하지_않는_쿠폰) + } + exception.message shouldBe "존재하지 않는 쿠폰입니다." + } +}) diff --git a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt index 8f74403..47edd37 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt @@ -4,8 +4,8 @@ import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe class CouponTest : FreeSpec({ - val 나눠준_비율_할인_쿠폰 = Coupon.RateDiscountCoupon(10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) - val 게시된_고정_할인_쿠폰 = Coupon.FixDiscountCoupon(1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + val 나눠준_비율_할인_쿠폰 = Coupon.RateDiscountCoupon(1, 10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + val 게시된_고정_할인_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) "게시된 쿠폰인지 확인 할 수 있다." { 게시된_고정_할인_쿠폰.isPublished() shouldBe true From 4ccbefb8132db5840b965a7e9b684fbda5b32d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:28:20 +0900 Subject: [PATCH 09/33] =?UTF-8?q?feature=20:=20=EC=BF=A0=ED=8F=B0=EC=9D=84?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9=20=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estdelivery/domain/coupon/CouponBook.kt | 4 +++ .../estdelivery/domain/member/Member.kt | 21 ++++++++++++++ .../estdelivery/domain/member/MemberTest.kt | 28 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/member/Member.kt create mode 100644 src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt index 21a2422..b70885d 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt @@ -3,6 +3,10 @@ package com.example.estdelivery.domain.coupon class CouponBook( private val coupons: MutableList = mutableListOf() ) { + fun showCoupons(): List { + return coupons.toList() + } + fun deleteCoupon(coupon: Coupon) { if (!coupons.contains(coupon)) { throw IllegalArgumentException("존재하지 않는 쿠폰입니다.") diff --git a/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt b/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt new file mode 100644 index 0000000..9c7c3d5 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt @@ -0,0 +1,21 @@ +package com.example.estdelivery.domain.member + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook + +class Member( + val name: String, + private val unUsedCouponBook: CouponBook +) { + fun useCoupon(coupon: Coupon) { + unUsedCouponBook.deleteCoupon(coupon) + } + + fun showMyCouponBook(): CouponBook { + return unUsedCouponBook + } + + fun receiveCoupon(coupon: Coupon) { + unUsedCouponBook.addCoupon(coupon) + } +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt new file mode 100644 index 0000000..cb2d4f7 --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt @@ -0,0 +1,28 @@ +package com.example.estdelivery.domain.member + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook +import com.example.estdelivery.domain.coupon.CouponType +import io.kotest.core.spec.style.FreeSpec +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class MemberTest : FreeSpec({ + lateinit var member: Member + val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + + beforeTest { + member = Member("홍길동", CouponBook()) + } + + "쿠폰을 추가할 수 있다." { + member.receiveCoupon(coupon) + member.showMyCouponBook().showCoupons().contains(coupon) shouldBe true + } + + "쿠폰을 사용할 수 있다." { + member.receiveCoupon(coupon) + member.useCoupon(coupon) + member.showMyCouponBook().showCoupons().contains(coupon) shouldBe false + } +}) From 637508e60f5a568de266fc3ee5a473cbca7178b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:34:52 +0900 Subject: [PATCH 10/33] =?UTF-8?q?feature=20:=20royal=20customers=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ .../estdelivery/domain/shop/RoyalCustomers.kt | 20 +++++++++++++ .../domain/shop/RoyalCustomersTest.kt | 30 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt create mode 100644 src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt diff --git a/README.md b/README.md index 9810892..f58b659 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ classDiagram class RoyalCustomers{ -List~Member~ members +handOutCoupon(Coupon coupon) void + +addMember(Member member) void + +showRoyalCustomers() List~Member~ } ``` diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt new file mode 100644 index 0000000..561d838 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt @@ -0,0 +1,20 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.member.Member + +class RoyalCustomers( + private val members: MutableList = mutableListOf() +) { + fun handOutCoupon(coupon: Coupon) { + members.forEach { it.receiveCoupon(coupon) } + } + + fun addRoyalCustomers(vararg member: Member) { + members.addAll(member) + } + + fun showRoyalCustomers(): List { + return members.toList() + } +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt new file mode 100644 index 0000000..69f954b --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt @@ -0,0 +1,30 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook +import com.example.estdelivery.domain.coupon.CouponType +import com.example.estdelivery.domain.member.Member +import io.kotest.core.spec.style.FreeSpec +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class RoyalCustomersTest : FreeSpec({ + + "모든 회원에게 쿠폰을 나눠줄 수 있다." { + // given + val 단골_리스트 = RoyalCustomers() + val 홍길동 = Member("홍길동", CouponBook()) + val 김철수 = Member("김철수", CouponBook()) + val 이영희 = Member("이영희", CouponBook()) + 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) + val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + + // when + 단골_리스트.handOutCoupon(coupon) + + // then + for (royalMember in 단골_리스트.showRoyalCustomers()) { + royalMember.showMyCouponBook().showCoupons().contains(coupon) shouldBe true + } + } +}) From ea8217588f91556dfc6a0f304a5b80eddd9e205f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:51:00 +0900 Subject: [PATCH 11/33] =?UTF-8?q?feature=20:=20shop=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- .../example/estdelivery/domain/shop/Shop.kt | 45 +++++++++++++ .../estdelivery/domain/shop/ShopTest.kt | 65 +++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt create mode 100644 src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt diff --git a/README.md b/README.md index f58b659..c47a06e 100644 --- a/README.md +++ b/README.md @@ -92,13 +92,15 @@ classDiagram class Shop{ -String shopName -CouponBook publishedCoupons + -CouponBook handOutCouponBook -CouponBook usedCouponBook -RoyalCustomers royalCustomers +publishCoupon(Coupon coupon) void +alreadyUsedCoupon(Coupon coupon) boolean +handOutPublishedCoupon(Coupon coupon) Coupon +handOutCouponToRoyalCustomers(Coupon coupon) void - +showPublishedCoupon() CouponBook + +showPublishedCoupons() List~Coupon~ + +showRoyalCustomers() List~Member~ } class RoyalCustomers{ diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt new file mode 100644 index 0000000..ab84871 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt @@ -0,0 +1,45 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook +import com.example.estdelivery.domain.member.Member + +class Shop( + private val shopName: String, + private val publishedCoupons: CouponBook, + private val handOutCoupon: CouponBook, + private val usedCouponBook: CouponBook, + private val royalCustomers: RoyalCustomers +) { + fun publishCoupon(coupon: Coupon) { + publishedCoupons.addCoupon(coupon) + } + + fun alreadyUsedCoupon(coupon: Coupon): Boolean { + return usedCouponBook.showCoupons().contains(coupon) + } + + fun useCoupon(coupon: Coupon) { + if (usedCouponBook.showCoupons().contains(coupon)) { + throw IllegalArgumentException("이미 사용한 쿠폰입니다.") + } + + if (!(publishedCoupons.showCoupons().contains(coupon) || handOutCoupon.showCoupons().contains(coupon))) { + throw IllegalArgumentException("게시하지 않은 쿠폰입니다.") + } + + usedCouponBook.addCoupon(coupon) + } + + fun handOutCouponToRoyalCustomers(coupon: Coupon) { + royalCustomers.handOutCoupon(coupon) + } + + fun showPublishedCoupons(): List { + return publishedCoupons.showCoupons() + } + + fun showRoyalCustomers(): List { + return royalCustomers.showRoyalCustomers() + } +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt new file mode 100644 index 0000000..91045f5 --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt @@ -0,0 +1,65 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook +import com.example.estdelivery.domain.coupon.CouponType +import com.example.estdelivery.domain.member.Member +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.FreeSpec +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class ShopTest : FreeSpec({ + + lateinit var 매장: Shop + val 게시할_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + + beforeTest { + val 단골_리스트 = RoyalCustomers() + val 홍길동 = Member("홍길동", CouponBook()) + val 김철수 = Member("김철수", CouponBook()) + val 이영희 = Member("이영희", CouponBook()) + 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) + 매장 = Shop("매장", CouponBook(), CouponBook(), CouponBook(), 단골_리스트) + } + + "쿠폰을 게시할 수 있다." { + 매장.publishCoupon(게시할_쿠폰) + 매장.showPublishedCoupons().contains(게시할_쿠폰) shouldBe true + } + + "이미 사용한 쿠폰인지 확인할 수 있다." { + 매장.publishCoupon(게시할_쿠폰) + 매장.useCoupon(게시할_쿠폰) + 매장.alreadyUsedCoupon(게시할_쿠폰) shouldBe true + } + + "이미 사용한 쿠폰은 재사용 할 수 없다." { + 매장.publishCoupon(게시할_쿠폰) + 매장.useCoupon(게시할_쿠폰) + shouldThrow { 매장.useCoupon(게시할_쿠폰) } + } + + "게시하지 않는 쿠폰인 경우 사용 할 수 없다." { + val 게시되지_않은_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + shouldThrow { 매장.useCoupon(게시되지_않은_쿠폰) } + } + + "나눠준 쿠폰이 아닌 경우 사용 할 수 없다." { + val 나눠주지_않은_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + shouldThrow { 매장.useCoupon(나눠주지_않은_쿠폰) } + } + + "모든 회원에게 쿠폰을 나눠줄 수 있다." { + // given + val 나눠줄_쿠폰_발급 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + + // when + 매장.handOutCouponToRoyalCustomers(나눠줄_쿠폰_발급) + + // then + for (royalMember in 매장.showRoyalCustomers()) { + royalMember.showMyCouponBook().showCoupons().contains(나눠줄_쿠폰_발급) shouldBe true + } + } +}) \ No newline at end of file From 6be0f255085cf3ab2e6f0196f35a8c052fa0d227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:59:54 +0900 Subject: [PATCH 12/33] =?UTF-8?q?feature=20:=20show=20owner=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- .../example/estdelivery/domain/shop/Shop.kt | 5 +++ .../estdelivery/domain/shop/ShopOwner.kt | 23 +++++++++++ .../estdelivery/domain/shop/ShopOwnerTest.kt | 41 +++++++++++++++++++ .../estdelivery/domain/shop/ShopTest.kt | 1 + 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/shop/ShopOwner.kt create mode 100644 src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt diff --git a/README.md b/README.md index c47a06e..36a8259 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ classDiagram class ShopOwner{ -Shop shop - +handOutCouponToRoyalCustomersInShop(Shop shop) void - +publishCouponInShop(Shop shop, Coupon coupon) void + +handOutCouponToRoyalCustomersInShop(Coupon coupon) void + +publishCouponInShop(Coupon coupon) void } class Shop{ diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt index ab84871..040b3bd 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt @@ -32,6 +32,7 @@ class Shop( } fun handOutCouponToRoyalCustomers(coupon: Coupon) { + handOutCoupon.addCoupon(coupon) royalCustomers.handOutCoupon(coupon) } @@ -42,4 +43,8 @@ class Shop( fun showRoyalCustomers(): List { return royalCustomers.showRoyalCustomers() } + + fun showHandOutCoupon(): List { + return handOutCoupon.showCoupons() + } } diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/ShopOwner.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/ShopOwner.kt new file mode 100644 index 0000000..32735f2 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/ShopOwner.kt @@ -0,0 +1,23 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon + +class ShopOwner( + private val shop: Shop +) { + fun handOutCouponToRoyalCustomersInShop(coupon: Coupon) { + shop.handOutCouponToRoyalCustomers(coupon) + } + + fun publishCouponInShop(coupon: Coupon) { + shop.publishCoupon(coupon) + } + + fun showHandOutCouponInShop(): List { + return shop.showHandOutCoupon() + } + + fun showPublishedCouponsInShop(): List { + return shop.showPublishedCoupons() + } +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt new file mode 100644 index 0000000..dab0e65 --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt @@ -0,0 +1,41 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook +import com.example.estdelivery.domain.coupon.CouponType +import com.example.estdelivery.domain.member.Member +import io.kotest.core.spec.style.FreeSpec +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class ShopOwnerTest : FreeSpec({ + + "모든 회원에게 쿠폰을 나눠줄 수 있다." { + // given + val 단골_리스트 = RoyalCustomers() + val 홍길동 = Member("홍길동", CouponBook()) + val 김철수 = Member("김철수", CouponBook()) + 단골_리스트.addRoyalCustomers(홍길동, 김철수) + + val 가게_주인 = ShopOwner(Shop("매장", CouponBook(), CouponBook(), CouponBook(),단골_리스트)) + val 나눠줄_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + + // when + 가게_주인.handOutCouponToRoyalCustomersInShop(나눠줄_쿠폰) + + // then + 가게_주인.showHandOutCouponInShop().contains(나눠줄_쿠폰) shouldBe true + } + + "쿠폰을 가게에 게시한다." { + // given + val 가게_주인 = ShopOwner(Shop("매장", CouponBook(), CouponBook(), CouponBook(), RoyalCustomers())) + val 게시할_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + + // when + 가게_주인.publishCouponInShop(게시할_쿠폰) + + // then + 가게_주인.showPublishedCouponsInShop().contains(게시할_쿠폰) shouldBe true + } +}) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt index 91045f5..4876a6c 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt @@ -58,6 +58,7 @@ class ShopTest : FreeSpec({ 매장.handOutCouponToRoyalCustomers(나눠줄_쿠폰_발급) // then + 매장.showHandOutCoupon().contains(나눠줄_쿠폰_발급) shouldBe true for (royalMember in 매장.showRoyalCustomers()) { royalMember.showMyCouponBook().showCoupons().contains(나눠줄_쿠폰_발급) shouldBe true } From 30e9460bd792a6e18050387f4f07e835792a4eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 00:00:13 +0900 Subject: [PATCH 13/33] =?UTF-8?q?refactor=20:=20=EB=A6=B0=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt index 04ba8ea..f1a85c4 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt @@ -13,6 +13,7 @@ sealed class Coupon( override val description: String, couponType: CouponType ) : Coupon(id, name, description, couponType) + class FixDiscountCoupon( id: Long, val discountAmount: Int, From df4d4e234d2cdf495bf675d16da5f8df3c2c41ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 00:05:06 +0900 Subject: [PATCH 14/33] =?UTF-8?q?refactor=20:=20shop=20=EB=8B=A8=EA=B3=A8?= =?UTF-8?q?=20=EA=B3=A0=EA=B0=9D=20=EC=B6=94=EA=B0=80=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++++ .../estdelivery/domain/member/Member.kt | 18 ++++++++++++++++++ .../example/estdelivery/domain/shop/Shop.kt | 5 ++++- .../estdelivery/domain/member/MemberTest.kt | 2 +- .../domain/shop/RoyalCustomersTest.kt | 6 +++--- .../estdelivery/domain/shop/ShopOwnerTest.kt | 4 ++-- .../estdelivery/domain/shop/ShopTest.kt | 14 +++++++++++--- 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 36a8259..a0bfab5 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,10 @@ classDiagram -Shop shop +handOutCouponToRoyalCustomersInShop(Coupon coupon) void +publishCouponInShop(Coupon coupon) void + +addRoyalCustomer(Member member...) void + +showPublishedCoupons() List~Coupon~ + +showRoyalCustomers() List~Member~ + +showHandOutCouponBook() CouponBook } class Shop{ @@ -99,7 +103,9 @@ classDiagram +alreadyUsedCoupon(Coupon coupon) boolean +handOutPublishedCoupon(Coupon coupon) Coupon +handOutCouponToRoyalCustomers(Coupon coupon) void + +addRoyalCustomer(Member member...) void +showPublishedCoupons() List~Coupon~ + +showRoyalCustomers() List~Member~ +showRoyalCustomers() List~Member~ } diff --git a/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt b/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt index 9c7c3d5..fb650f7 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt @@ -4,6 +4,7 @@ import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.coupon.CouponBook class Member( + val id: Long, val name: String, private val unUsedCouponBook: CouponBook ) { @@ -18,4 +19,21 @@ class Member( fun receiveCoupon(coupon: Coupon) { unUsedCouponBook.addCoupon(coupon) } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Member + + return id == other.id + } + + override fun hashCode(): Int { + return id.hashCode() + } + + override fun toString(): String { + return "Member(id=$id, name='$name', unUsedCouponBook=$unUsedCouponBook)" + } } diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt index 040b3bd..a5d3d3f 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt @@ -5,7 +5,6 @@ import com.example.estdelivery.domain.coupon.CouponBook import com.example.estdelivery.domain.member.Member class Shop( - private val shopName: String, private val publishedCoupons: CouponBook, private val handOutCoupon: CouponBook, private val usedCouponBook: CouponBook, @@ -31,6 +30,10 @@ class Shop( usedCouponBook.addCoupon(coupon) } + fun addRoyalCustomers(vararg members: Member) { + royalCustomers.addRoyalCustomers(*members) + } + fun handOutCouponToRoyalCustomers(coupon: Coupon) { handOutCoupon.addCoupon(coupon) royalCustomers.handOutCoupon(coupon) diff --git a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt index cb2d4f7..33f7348 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt @@ -12,7 +12,7 @@ class MemberTest : FreeSpec({ val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) beforeTest { - member = Member("홍길동", CouponBook()) + member = Member(1, "홍길동", CouponBook()) } "쿠폰을 추가할 수 있다." { diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt index 69f954b..24da29a 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt @@ -13,9 +13,9 @@ class RoyalCustomersTest : FreeSpec({ "모든 회원에게 쿠폰을 나눠줄 수 있다." { // given val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member("홍길동", CouponBook()) - val 김철수 = Member("김철수", CouponBook()) - val 이영희 = Member("이영희", CouponBook()) + val 홍길동 = Member(1, "홍길동", CouponBook()) + val 김철수 = Member(2, "김철수", CouponBook()) + val 이영희 = Member(3, "이영희", CouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt index dab0e65..a39cc05 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt @@ -13,8 +13,8 @@ class ShopOwnerTest : FreeSpec({ "모든 회원에게 쿠폰을 나눠줄 수 있다." { // given val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member("홍길동", CouponBook()) - val 김철수 = Member("김철수", CouponBook()) + val 홍길동 = Member(1, "홍길동", CouponBook()) + val 김철수 = Member(2, "김철수", CouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수) val 가게_주인 = ShopOwner(Shop("매장", CouponBook(), CouponBook(), CouponBook(),단골_리스트)) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt index 4876a6c..77fb9f3 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt @@ -16,9 +16,9 @@ class ShopTest : FreeSpec({ beforeTest { val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member("홍길동", CouponBook()) - val 김철수 = Member("김철수", CouponBook()) - val 이영희 = Member("이영희", CouponBook()) + val 홍길동 = Member(1, "홍길동", CouponBook()) + val 김철수 = Member(2, "김철수", CouponBook()) + val 이영희 = Member(3, "이영희", CouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) 매장 = Shop("매장", CouponBook(), CouponBook(), CouponBook(), 단골_리스트) } @@ -63,4 +63,12 @@ class ShopTest : FreeSpec({ royalMember.showMyCouponBook().showCoupons().contains(나눠줄_쿠폰_발급) shouldBe true } } + + "단골 회원을 추가할 수 있다." { + val 홍길동 = Member(1, "홍길동", CouponBook()) + val 김철수 = Member(2, "김철수", CouponBook()) + 매장.addRoyalCustomers(홍길동, 김철수) + 매장.showRoyalCustomers().contains(홍길동) shouldBe true + 매장.showRoyalCustomers().contains(김철수) shouldBe true + } }) \ No newline at end of file From 40ab010633b036d80f1f24c0e7eed85049b0a72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 00:12:27 +0900 Subject: [PATCH 15/33] =?UTF-8?q?chore=20:=20gitignore=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 144 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 164db2a..48007d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,145 @@ +# Created by https://www.toptal.com/developers/gitignore/api/gradle,intellij+all,kotlin +# Edit at https://www.toptal.com/developers/gitignore?templates=gradle,intellij+all,kotlin + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### Kotlin ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Gradle ### .gradle -build -HELP.md -.DS_Store -.idea -/src/main/.azure \ No newline at end of file +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +### Gradle Patch ### +# Java heap dump +*.hprof + +# End of https://www.toptal.com/developers/gitignore/api/gradle,intellij+all,kotlin \ No newline at end of file From af0feaf91689cfb557859cc39e68e95f465d4247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 00:12:54 +0900 Subject: [PATCH 16/33] =?UTF-8?q?test=20:=20shop=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=A7=80=EC=9A=B4=20=EC=98=81=EC=97=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/estdelivery/domain/shop/ShopTest.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt index 77fb9f3..cd29098 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt @@ -20,7 +20,7 @@ class ShopTest : FreeSpec({ val 김철수 = Member(2, "김철수", CouponBook()) val 이영희 = Member(3, "이영희", CouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) - 매장 = Shop("매장", CouponBook(), CouponBook(), CouponBook(), 단골_리스트) + 매장 = Shop(CouponBook(), CouponBook(), CouponBook(), 단골_리스트) } "쿠폰을 게시할 수 있다." { @@ -65,10 +65,8 @@ class ShopTest : FreeSpec({ } "단골 회원을 추가할 수 있다." { - val 홍길동 = Member(1, "홍길동", CouponBook()) - val 김철수 = Member(2, "김철수", CouponBook()) - 매장.addRoyalCustomers(홍길동, 김철수) - 매장.showRoyalCustomers().contains(홍길동) shouldBe true - 매장.showRoyalCustomers().contains(김철수) shouldBe true + val 새로운_철수 = Member(14, "새로운 철수", CouponBook()) + 매장.addRoyalCustomers(새로운_철수) + 매장.showRoyalCustomers().contains(새로운_철수) shouldBe true } }) \ No newline at end of file From 083ee9b404148305ffc1d0198f42cd260f79d2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 00:13:14 +0900 Subject: [PATCH 17/33] =?UTF-8?q?refactore=20:=20royal=20customers=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estdelivery/domain/shop/RoyalCustomers.kt | 15 ++++++++++----- .../estdelivery/domain/shop/RoyalCustomersTest.kt | 11 +++++++++++ .../estdelivery/domain/shop/ShopOwnerTest.kt | 5 ++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt index 561d838..afb5722 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt @@ -4,17 +4,22 @@ import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.member.Member class RoyalCustomers( - private val members: MutableList = mutableListOf() + private val customers: MutableList = mutableListOf() ) { fun handOutCoupon(coupon: Coupon) { - members.forEach { it.receiveCoupon(coupon) } + customers.forEach { it.receiveCoupon(coupon) } } - fun addRoyalCustomers(vararg member: Member) { - members.addAll(member) + fun addRoyalCustomers(vararg members: Member) { + for (member in members) { + if (customers.contains(member)) { + throw IllegalArgumentException("이미 등록된 회원입니다.") + } + } + customers.addAll(members) } fun showRoyalCustomers(): List { - return members.toList() + return customers.toList() } } diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt index 24da29a..eb7340f 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt @@ -4,6 +4,7 @@ import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.coupon.CouponBook import com.example.estdelivery.domain.coupon.CouponType import com.example.estdelivery.domain.member.Member +import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe @@ -27,4 +28,14 @@ class RoyalCustomersTest : FreeSpec({ royalMember.showMyCouponBook().showCoupons().contains(coupon) shouldBe true } } + + "이미 추가된 회원은 추가할 수 없다." { + // given + val 단골_리스트 = RoyalCustomers() + val 홍길동 = Member(1, "홍길동", CouponBook()) + 단골_리스트.addRoyalCustomers(홍길동) + + // when + shouldThrow { 단골_리스트.addRoyalCustomers(홍길동) } + } }) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt index a39cc05..eeda6b7 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt @@ -5,7 +5,6 @@ import com.example.estdelivery.domain.coupon.CouponBook import com.example.estdelivery.domain.coupon.CouponType import com.example.estdelivery.domain.member.Member import io.kotest.core.spec.style.FreeSpec -import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe class ShopOwnerTest : FreeSpec({ @@ -17,7 +16,7 @@ class ShopOwnerTest : FreeSpec({ val 김철수 = Member(2, "김철수", CouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수) - val 가게_주인 = ShopOwner(Shop("매장", CouponBook(), CouponBook(), CouponBook(),단골_리스트)) + val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), CouponBook(), 단골_리스트)) val 나눠줄_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) // when @@ -29,7 +28,7 @@ class ShopOwnerTest : FreeSpec({ "쿠폰을 가게에 게시한다." { // given - val 가게_주인 = ShopOwner(Shop("매장", CouponBook(), CouponBook(), CouponBook(), RoyalCustomers())) + val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), CouponBook(), RoyalCustomers())) val 게시할_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) // when From d5365a847c7043d49cdaa06d4a82bc5aa05569ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 00:14:34 +0900 Subject: [PATCH 18/33] =?UTF-8?q?refactor=20:=20shop=20owner=20=EB=8A=94?= =?UTF-8?q?=20=EB=8B=A8=EA=B3=A8=EC=9D=84=20=EC=B6=94=EA=B0=80=20=ED=95=A0?= =?UTF-8?q?=20=EC=88=98=20=EC=9E=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/estdelivery/domain/shop/ShopOwner.kt | 9 +++++++++ .../estdelivery/domain/shop/ShopOwnerTest.kt | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/ShopOwner.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/ShopOwner.kt index 32735f2..b6cfeba 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/ShopOwner.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/ShopOwner.kt @@ -1,6 +1,7 @@ package com.example.estdelivery.domain.shop import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.member.Member class ShopOwner( private val shop: Shop @@ -13,6 +14,10 @@ class ShopOwner( shop.publishCoupon(coupon) } + fun addRoyalCustomersInShop(vararg members: Member) { + shop.addRoyalCustomers(*members) + } + fun showHandOutCouponInShop(): List { return shop.showHandOutCoupon() } @@ -20,4 +25,8 @@ class ShopOwner( fun showPublishedCouponsInShop(): List { return shop.showPublishedCoupons() } + + fun showRoyalCustomersInShop(): List { + return shop.showRoyalCustomers() + } } diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt index eeda6b7..f610c5a 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt @@ -37,4 +37,18 @@ class ShopOwnerTest : FreeSpec({ // then 가게_주인.showPublishedCouponsInShop().contains(게시할_쿠폰) shouldBe true } + + "단골 회원을 가게에 추가한다." { + // given + val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), CouponBook(), RoyalCustomers())) + val 홍길동 = Member(1, "홍길동", CouponBook()) + val 김철수 = Member(2, "김철수", CouponBook()) + + // when + 가게_주인.addRoyalCustomersInShop(홍길동, 김철수) + + // then + 가게_주인.showRoyalCustomersInShop().contains(홍길동) shouldBe true + 가게_주인.showRoyalCustomersInShop().contains(김철수) shouldBe true + } }) From 69815d05f0e3261eb674c0564d25737f21f1a6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 00:16:53 +0900 Subject: [PATCH 19/33] =?UTF-8?q?chore=20:=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EB=AA=A8=EB=8D=B8=EB=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index a0bfab5..ad199cb 100644 --- a/README.md +++ b/README.md @@ -83,38 +83,38 @@ classDiagram +receiveCoupon(Coupon coupon) void } - class ShopOwner{ - -Shop shop - +handOutCouponToRoyalCustomersInShop(Coupon coupon) void - +publishCouponInShop(Coupon coupon) void - +addRoyalCustomer(Member member...) void - +showPublishedCoupons() List~Coupon~ - +showRoyalCustomers() List~Member~ - +showHandOutCouponBook() CouponBook - } - - class Shop{ - -String shopName - -CouponBook publishedCoupons - -CouponBook handOutCouponBook - -CouponBook usedCouponBook - -RoyalCustomers royalCustomers - +publishCoupon(Coupon coupon) void - +alreadyUsedCoupon(Coupon coupon) boolean - +handOutPublishedCoupon(Coupon coupon) Coupon - +handOutCouponToRoyalCustomers(Coupon coupon) void - +addRoyalCustomer(Member member...) void - +showPublishedCoupons() List~Coupon~ - +showRoyalCustomers() List~Member~ - +showRoyalCustomers() List~Member~ - } - - class RoyalCustomers{ - -List~Member~ members - +handOutCoupon(Coupon coupon) void - +addMember(Member member) void - +showRoyalCustomers() List~Member~ - } + class ShopOwner{ + -Shop shop + +handOutCouponToRoyalCustomersInShop(Coupon coupon) void + +publishCouponInShop(Coupon coupon) void + +addRoyalCustomerInShop(Member member...) void + +showPublishedCouponsInShop() List~Coupon~ + +showHandOutCouponBookInShop() CouponBook + +showRoyalCustomersInShop() List~Member~ + } + + class Shop{ + -String shopName + -CouponBook publishedCoupons + -CouponBook handOutCouponBook + -CouponBook usedCouponBook + -RoyalCustomers royalCustomers + +publishCoupon(Coupon coupon) void + +handOutCouponToRoyalCustomers(Coupon coupon) void + +alreadyUsedCoupon(Coupon coupon) boolean + +useCoupon(Coupon coupon) Coupon + +addRoyalCustomer(Member member...) void + +showPublishedCoupons() List~Coupon~ + +showHandOutCoupons() List~Coupon~ + +showRoyalCustomers() List~Member~ + } + + class RoyalCustomers{ + -List~Member~ members + +handOutCoupon(Coupon coupon) void + +addMember(Member member) void + +showRoyalCustomers() List~Member~ + } ``` From 11b73af3094c17eac872dd18709fe3e8cfcf47ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:56:22 +0900 Subject: [PATCH 20/33] =?UTF-8?q?refactor=20:=20royal=20customers=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=8D=BC=ED=8B=B0=20immutable=20list=20?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/estdelivery/domain/shop/RoyalCustomers.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt index afb5722..29755fb 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/RoyalCustomers.kt @@ -4,7 +4,7 @@ import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.member.Member class RoyalCustomers( - private val customers: MutableList = mutableListOf() + private var customers: List = listOf() ) { fun handOutCoupon(coupon: Coupon) { customers.forEach { it.receiveCoupon(coupon) } @@ -16,7 +16,7 @@ class RoyalCustomers( throw IllegalArgumentException("이미 등록된 회원입니다.") } } - customers.addAll(members) + customers = customers + members } fun showRoyalCustomers(): List { From e1f1e7b319f24ed68d2277db98821b0f1fd057e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:57:57 +0900 Subject: [PATCH 21/33] =?UTF-8?q?refactor=20:=20coupon=20book=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=8D=BC=ED=8B=B0=20immutable=20list=20=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/estdelivery/domain/coupon/CouponBook.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt index b70885d..9097a69 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt @@ -1,7 +1,7 @@ package com.example.estdelivery.domain.coupon class CouponBook( - private val coupons: MutableList = mutableListOf() + private var coupons: List = listOf() ) { fun showCoupons(): List { return coupons.toList() @@ -11,13 +11,13 @@ class CouponBook( if (!coupons.contains(coupon)) { throw IllegalArgumentException("존재하지 않는 쿠폰입니다.") } - coupons.remove(coupon) + coupons = coupons - coupon } fun addCoupon(coupon: Coupon) { if (coupons.contains(coupon)) { throw IllegalArgumentException("이미 존재하는 쿠폰입니다.") } - coupons.add(coupon) + coupons = coupons + coupon } } From f4ee4d7c590597b643c22c936b8d1d9b39b3cb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <150098998+geon-chang@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:47:54 +0900 Subject: [PATCH 22/33] =?UTF-8?q?feature=20:=20UsedCouponBook=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estdelivery/domain/coupon/CouponBook.kt | 4 +++ .../example/estdelivery/domain/shop/Shop.kt | 16 ++------- .../estdelivery/domain/shop/UsedCouponBook.kt | 20 +++++++++++ .../estdelivery/domain/shop/ShopOwnerTest.kt | 6 ++-- .../estdelivery/domain/shop/ShopTest.kt | 8 +---- .../domain/shop/UsedCouponBookTest.kt | 35 +++++++++++++++++++ 6 files changed, 65 insertions(+), 24 deletions(-) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/shop/UsedCouponBook.kt create mode 100644 src/test/kotlin/com/example/estdelivery/domain/shop/UsedCouponBookTest.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt index 9097a69..a6818bf 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt @@ -20,4 +20,8 @@ class CouponBook( } coupons = coupons + coupon } + + operator fun plus(addedCoupons: CouponBook): List { + return coupons + addedCoupons.showCoupons() + } } diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt index a5d3d3f..4c64d66 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt @@ -7,27 +7,15 @@ import com.example.estdelivery.domain.member.Member class Shop( private val publishedCoupons: CouponBook, private val handOutCoupon: CouponBook, - private val usedCouponBook: CouponBook, + private val usedCouponBook: UsedCouponBook, private val royalCustomers: RoyalCustomers ) { fun publishCoupon(coupon: Coupon) { publishedCoupons.addCoupon(coupon) } - fun alreadyUsedCoupon(coupon: Coupon): Boolean { - return usedCouponBook.showCoupons().contains(coupon) - } - fun useCoupon(coupon: Coupon) { - if (usedCouponBook.showCoupons().contains(coupon)) { - throw IllegalArgumentException("이미 사용한 쿠폰입니다.") - } - - if (!(publishedCoupons.showCoupons().contains(coupon) || handOutCoupon.showCoupons().contains(coupon))) { - throw IllegalArgumentException("게시하지 않은 쿠폰입니다.") - } - - usedCouponBook.addCoupon(coupon) + usedCouponBook.useCoupon(coupon, CouponBook(publishedCoupons + handOutCoupon)) } fun addRoyalCustomers(vararg members: Member) { diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/UsedCouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/UsedCouponBook.kt new file mode 100644 index 0000000..a24e0dc --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/UsedCouponBook.kt @@ -0,0 +1,20 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook + +class UsedCouponBook( + private val usedCouponBook: CouponBook = CouponBook(), +) { + fun useCoupon(coupon: Coupon, shopCouponBook: CouponBook) { + if (usedCouponBook.showCoupons().contains(coupon)) { + throw IllegalArgumentException("이미 사용한 쿠폰입니다.") + } + + if (!shopCouponBook.showCoupons().contains(coupon)) { + throw IllegalArgumentException("게시하지 않은 쿠폰입니다.") + } + + usedCouponBook.addCoupon(coupon) + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt index f610c5a..318089e 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt @@ -16,7 +16,7 @@ class ShopOwnerTest : FreeSpec({ val 김철수 = Member(2, "김철수", CouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수) - val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), CouponBook(), 단골_리스트)) + val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), UsedCouponBook(), 단골_리스트)) val 나눠줄_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) // when @@ -28,7 +28,7 @@ class ShopOwnerTest : FreeSpec({ "쿠폰을 가게에 게시한다." { // given - val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), CouponBook(), RoyalCustomers())) + val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), UsedCouponBook(), RoyalCustomers())) val 게시할_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) // when @@ -40,7 +40,7 @@ class ShopOwnerTest : FreeSpec({ "단골 회원을 가게에 추가한다." { // given - val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), CouponBook(), RoyalCustomers())) + val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), UsedCouponBook(), RoyalCustomers())) val 홍길동 = Member(1, "홍길동", CouponBook()) val 김철수 = Member(2, "김철수", CouponBook()) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt index cd29098..007a287 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt @@ -20,7 +20,7 @@ class ShopTest : FreeSpec({ val 김철수 = Member(2, "김철수", CouponBook()) val 이영희 = Member(3, "이영희", CouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) - 매장 = Shop(CouponBook(), CouponBook(), CouponBook(), 단골_리스트) + 매장 = Shop(CouponBook(), CouponBook(), UsedCouponBook(), 단골_리스트) } "쿠폰을 게시할 수 있다." { @@ -28,12 +28,6 @@ class ShopTest : FreeSpec({ 매장.showPublishedCoupons().contains(게시할_쿠폰) shouldBe true } - "이미 사용한 쿠폰인지 확인할 수 있다." { - 매장.publishCoupon(게시할_쿠폰) - 매장.useCoupon(게시할_쿠폰) - 매장.alreadyUsedCoupon(게시할_쿠폰) shouldBe true - } - "이미 사용한 쿠폰은 재사용 할 수 없다." { 매장.publishCoupon(게시할_쿠폰) 매장.useCoupon(게시할_쿠폰) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/UsedCouponBookTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/UsedCouponBookTest.kt new file mode 100644 index 0000000..e676219 --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/UsedCouponBookTest.kt @@ -0,0 +1,35 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook +import com.example.estdelivery.domain.coupon.CouponType +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.FreeSpec +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class UsedCouponBookTest : FreeSpec({ + "이미 사용한 쿠폰은 재사용 할 수 없다." { + // given + val usedCouponBook = UsedCouponBook() + val shopCouponBook = CouponBook() + val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + + // when + shopCouponBook.addCoupon(coupon) + usedCouponBook.useCoupon(coupon, shopCouponBook) + + // then + shouldThrow { usedCouponBook.useCoupon(coupon, shopCouponBook) } + } + + "게시하지 않는 쿠폰인 경우 사용 할 수 없다." { + // given + val usedCouponBook = UsedCouponBook() + val shopCouponBook = CouponBook() + val notPublishedCoupon = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + + // then + shouldThrow { usedCouponBook.useCoupon(notPublishedCoupon, shopCouponBook) } + } +}) From d839c5b87c0db190bad8fb898d86aa6bc03187c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:51:47 +0900 Subject: [PATCH 23/33] =?UTF-8?q?refactor=20:=20PublishedCouponBook=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estdelivery/domain/coupon/CouponBook.kt | 4 ---- .../domain/shop/PublishedCouponBook.kt | 16 ++++++++++++++++ .../com/example/estdelivery/domain/shop/Shop.kt | 10 +++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBook.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt index a6818bf..9097a69 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/coupon/CouponBook.kt @@ -20,8 +20,4 @@ class CouponBook( } coupons = coupons + coupon } - - operator fun plus(addedCoupons: CouponBook): List { - return coupons + addedCoupons.showCoupons() - } } diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBook.kt new file mode 100644 index 0000000..79a6958 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBook.kt @@ -0,0 +1,16 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook + +class PublishedCouponBook( + private val publishedCoupons: CouponBook = CouponBook(), +) { + fun publishCoupon(coupon: Coupon) { + publishedCoupons.addCoupon(coupon) + } + + fun showPublishedCoupons(): List { + return publishedCoupons.showCoupons() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt index 4c64d66..8d1fbe2 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt @@ -5,13 +5,13 @@ import com.example.estdelivery.domain.coupon.CouponBook import com.example.estdelivery.domain.member.Member class Shop( - private val publishedCoupons: CouponBook, + private val publishedCoupons: PublishedCouponBook, private val handOutCoupon: CouponBook, private val usedCouponBook: UsedCouponBook, private val royalCustomers: RoyalCustomers ) { fun publishCoupon(coupon: Coupon) { - publishedCoupons.addCoupon(coupon) + publishedCoupons.publishCoupon(coupon) } fun useCoupon(coupon: Coupon) { @@ -28,7 +28,7 @@ class Shop( } fun showPublishedCoupons(): List { - return publishedCoupons.showCoupons() + return publishedCoupons.showPublishedCoupons() } fun showRoyalCustomers(): List { @@ -39,3 +39,7 @@ class Shop( return handOutCoupon.showCoupons() } } + +private operator fun PublishedCouponBook.plus(coupon: CouponBook): List { + return showPublishedCoupons() + coupon.showCoupons() +} From 7628e9d15f7c308a92c833ebdfe18a0a88cd0c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:53:47 +0900 Subject: [PATCH 24/33] =?UTF-8?q?refactor=20:=20HandOutCoupon=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estdelivery/domain/shop/HandOutCoupon.kt | 16 ++++++++++++++++ .../com/example/estdelivery/domain/shop/Shop.kt | 10 +++++----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCoupon.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCoupon.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCoupon.kt new file mode 100644 index 0000000..b5f687f --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCoupon.kt @@ -0,0 +1,16 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook + +class HandOutCoupon( + private val handOutCoupons: CouponBook = CouponBook(), +) { + fun showHandOutCoupon(): List { + return handOutCoupons.showCoupons() + } + + fun addHandOutCoupon(coupon: Coupon) { + handOutCoupons.addCoupon(coupon) + } +} diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt index 8d1fbe2..fadfeec 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt @@ -6,7 +6,7 @@ import com.example.estdelivery.domain.member.Member class Shop( private val publishedCoupons: PublishedCouponBook, - private val handOutCoupon: CouponBook, + private val handOutCoupon: HandOutCoupon, private val usedCouponBook: UsedCouponBook, private val royalCustomers: RoyalCustomers ) { @@ -23,7 +23,7 @@ class Shop( } fun handOutCouponToRoyalCustomers(coupon: Coupon) { - handOutCoupon.addCoupon(coupon) + handOutCoupon.addHandOutCoupon(coupon) royalCustomers.handOutCoupon(coupon) } @@ -36,10 +36,10 @@ class Shop( } fun showHandOutCoupon(): List { - return handOutCoupon.showCoupons() + return handOutCoupon.showHandOutCoupon() } } -private operator fun PublishedCouponBook.plus(coupon: CouponBook): List { - return showPublishedCoupons() + coupon.showCoupons() +private operator fun PublishedCouponBook.plus(coupon: HandOutCoupon): List { + return showPublishedCoupons() + coupon.showHandOutCoupon() } From ce88d11a9aab8440f1b788ed71e3aca91765b465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:55:07 +0900 Subject: [PATCH 25/33] =?UTF-8?q?refactor=20:=20UnUsedCouponBook=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estdelivery/domain/member/Member.kt | 10 +++++----- .../domain/member/UnUsedCouponBook.kt | 20 +++++++++++++++++++ .../estdelivery/domain/member/MemberTest.kt | 6 +++--- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/com/example/estdelivery/domain/member/UnUsedCouponBook.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt b/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt index fb650f7..bffb0e9 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt @@ -6,18 +6,18 @@ import com.example.estdelivery.domain.coupon.CouponBook class Member( val id: Long, val name: String, - private val unUsedCouponBook: CouponBook + private val unUsedCouponBook: UnUsedCouponBook ) { fun useCoupon(coupon: Coupon) { - unUsedCouponBook.deleteCoupon(coupon) + unUsedCouponBook.deleteUnUsedCoupon(coupon) } - fun showMyCouponBook(): CouponBook { - return unUsedCouponBook + fun showMyCouponBook(): List { + return unUsedCouponBook.showUnUsedCoupons() } fun receiveCoupon(coupon: Coupon) { - unUsedCouponBook.addCoupon(coupon) + unUsedCouponBook.addUnUsedCoupon(coupon) } override fun equals(other: Any?): Boolean { diff --git a/src/main/kotlin/com/example/estdelivery/domain/member/UnUsedCouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/member/UnUsedCouponBook.kt new file mode 100644 index 0000000..5c8a957 --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/member/UnUsedCouponBook.kt @@ -0,0 +1,20 @@ +package com.example.estdelivery.domain.member + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook + +class UnUsedCouponBook( + private val unUsedCouponBook: CouponBook = CouponBook(), +) { + fun showUnUsedCoupons(): List { + return unUsedCouponBook.showCoupons() + } + + fun addUnUsedCoupon(coupon: Coupon) { + unUsedCouponBook.addCoupon(coupon) + } + + fun deleteUnUsedCoupon(coupon: Coupon) { + unUsedCouponBook.deleteCoupon(coupon) + } +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt index 33f7348..1915d51 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt @@ -12,17 +12,17 @@ class MemberTest : FreeSpec({ val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) beforeTest { - member = Member(1, "홍길동", CouponBook()) + member = Member(1, "홍길동", UnUsedCouponBook()) } "쿠폰을 추가할 수 있다." { member.receiveCoupon(coupon) - member.showMyCouponBook().showCoupons().contains(coupon) shouldBe true + member.showMyCouponBook().contains(coupon) shouldBe true } "쿠폰을 사용할 수 있다." { member.receiveCoupon(coupon) member.useCoupon(coupon) - member.showMyCouponBook().showCoupons().contains(coupon) shouldBe false + member.showMyCouponBook().contains(coupon) shouldBe false } }) From b869dc026a14b90592c42fd174a55909ae5da72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:57:05 +0900 Subject: [PATCH 26/33] =?UTF-8?q?chore=20:=20HandOutCouponBook=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/shop/{HandOutCoupon.kt => HandOutCouponBook.kt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/kotlin/com/example/estdelivery/domain/shop/{HandOutCoupon.kt => HandOutCouponBook.kt} (94%) diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCoupon.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBook.kt similarity index 94% rename from src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCoupon.kt rename to src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBook.kt index b5f687f..a52a8be 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCoupon.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBook.kt @@ -3,7 +3,7 @@ package com.example.estdelivery.domain.shop import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.coupon.CouponBook -class HandOutCoupon( +class HandOutCouponBook( private val handOutCoupons: CouponBook = CouponBook(), ) { fun showHandOutCoupon(): List { From 45aa799d8287fe9dc329f18229c7209b181a0fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:57:13 +0900 Subject: [PATCH 27/33] =?UTF-8?q?test=20:=20=EC=8B=A4=ED=8C=A8=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/estdelivery/domain/shop/Shop.kt | 10 +++++----- .../estdelivery/domain/shop/RoyalCustomersTest.kt | 11 ++++++----- .../estdelivery/domain/shop/ShopOwnerTest.kt | 15 ++++++++------- .../example/estdelivery/domain/shop/ShopTest.kt | 14 +++++++------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt index fadfeec..f984731 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/Shop.kt @@ -6,7 +6,7 @@ import com.example.estdelivery.domain.member.Member class Shop( private val publishedCoupons: PublishedCouponBook, - private val handOutCoupon: HandOutCoupon, + private val handOutCouponBook: HandOutCouponBook, private val usedCouponBook: UsedCouponBook, private val royalCustomers: RoyalCustomers ) { @@ -15,7 +15,7 @@ class Shop( } fun useCoupon(coupon: Coupon) { - usedCouponBook.useCoupon(coupon, CouponBook(publishedCoupons + handOutCoupon)) + usedCouponBook.useCoupon(coupon, CouponBook(publishedCoupons + handOutCouponBook)) } fun addRoyalCustomers(vararg members: Member) { @@ -23,7 +23,7 @@ class Shop( } fun handOutCouponToRoyalCustomers(coupon: Coupon) { - handOutCoupon.addHandOutCoupon(coupon) + handOutCouponBook.addHandOutCoupon(coupon) royalCustomers.handOutCoupon(coupon) } @@ -36,10 +36,10 @@ class Shop( } fun showHandOutCoupon(): List { - return handOutCoupon.showHandOutCoupon() + return handOutCouponBook.showHandOutCoupon() } } -private operator fun PublishedCouponBook.plus(coupon: HandOutCoupon): List { +private operator fun PublishedCouponBook.plus(coupon: HandOutCouponBook): List { return showPublishedCoupons() + coupon.showHandOutCoupon() } diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt index eb7340f..44a1377 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt @@ -4,6 +4,7 @@ import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.coupon.CouponBook import com.example.estdelivery.domain.coupon.CouponType import com.example.estdelivery.domain.member.Member +import com.example.estdelivery.domain.member.UnUsedCouponBook import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec import io.kotest.core.spec.style.FunSpec @@ -14,9 +15,9 @@ class RoyalCustomersTest : FreeSpec({ "모든 회원에게 쿠폰을 나눠줄 수 있다." { // given val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member(1, "홍길동", CouponBook()) - val 김철수 = Member(2, "김철수", CouponBook()) - val 이영희 = Member(3, "이영희", CouponBook()) + val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) + val 김철수 = Member(2, "김철수", UnUsedCouponBook()) + val 이영희 = Member(3, "이영희", UnUsedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) @@ -25,14 +26,14 @@ class RoyalCustomersTest : FreeSpec({ // then for (royalMember in 단골_리스트.showRoyalCustomers()) { - royalMember.showMyCouponBook().showCoupons().contains(coupon) shouldBe true + royalMember.showMyCouponBook().contains(coupon) shouldBe true } } "이미 추가된 회원은 추가할 수 없다." { // given val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member(1, "홍길동", CouponBook()) + val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동) // when diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt index 318089e..1e502a5 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt @@ -4,6 +4,7 @@ import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.coupon.CouponBook import com.example.estdelivery.domain.coupon.CouponType import com.example.estdelivery.domain.member.Member +import com.example.estdelivery.domain.member.UnUsedCouponBook import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe @@ -12,11 +13,11 @@ class ShopOwnerTest : FreeSpec({ "모든 회원에게 쿠폰을 나눠줄 수 있다." { // given val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member(1, "홍길동", CouponBook()) - val 김철수 = Member(2, "김철수", CouponBook()) + val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) + val 김철수 = Member(2, "김철수", UnUsedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수) - val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), UsedCouponBook(), 단골_리스트)) + val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(), UsedCouponBook(), 단골_리스트)) val 나눠줄_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) // when @@ -28,7 +29,7 @@ class ShopOwnerTest : FreeSpec({ "쿠폰을 가게에 게시한다." { // given - val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), UsedCouponBook(), RoyalCustomers())) + val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(),UsedCouponBook(), RoyalCustomers())) val 게시할_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) // when @@ -40,9 +41,9 @@ class ShopOwnerTest : FreeSpec({ "단골 회원을 가게에 추가한다." { // given - val 가게_주인 = ShopOwner(Shop(CouponBook(), CouponBook(), UsedCouponBook(), RoyalCustomers())) - val 홍길동 = Member(1, "홍길동", CouponBook()) - val 김철수 = Member(2, "김철수", CouponBook()) + val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(),UsedCouponBook(), RoyalCustomers())) + val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) + val 김철수 = Member(2, "김철수", UnUsedCouponBook()) // when 가게_주인.addRoyalCustomersInShop(홍길동, 김철수) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt index 007a287..dd9174e 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt @@ -4,9 +4,9 @@ import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.coupon.CouponBook import com.example.estdelivery.domain.coupon.CouponType import com.example.estdelivery.domain.member.Member +import com.example.estdelivery.domain.member.UnUsedCouponBook import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec -import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe class ShopTest : FreeSpec({ @@ -16,11 +16,11 @@ class ShopTest : FreeSpec({ beforeTest { val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member(1, "홍길동", CouponBook()) - val 김철수 = Member(2, "김철수", CouponBook()) - val 이영희 = Member(3, "이영희", CouponBook()) + val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) + val 김철수 = Member(2, "김철수", UnUsedCouponBook()) + val 이영희 = Member(3, "이영희", UnUsedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) - 매장 = Shop(CouponBook(), CouponBook(), UsedCouponBook(), 단골_리스트) + 매장 = Shop(PublishedCouponBook(), HandOutCouponBook(), UsedCouponBook(), 단골_리스트) } "쿠폰을 게시할 수 있다." { @@ -54,12 +54,12 @@ class ShopTest : FreeSpec({ // then 매장.showHandOutCoupon().contains(나눠줄_쿠폰_발급) shouldBe true for (royalMember in 매장.showRoyalCustomers()) { - royalMember.showMyCouponBook().showCoupons().contains(나눠줄_쿠폰_발급) shouldBe true + royalMember.showMyCouponBook().contains(나눠줄_쿠폰_발급) shouldBe true } } "단골 회원을 추가할 수 있다." { - val 새로운_철수 = Member(14, "새로운 철수", CouponBook()) + val 새로운_철수 = Member(14, "새로운 철수", UnUsedCouponBook()) 매장.addRoyalCustomers(새로운_철수) 매장.showRoyalCustomers().contains(새로운_철수) shouldBe true } From 56644402a3f90f757a3a6ebc5feed8c2bea9a924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Fri, 9 Feb 2024 20:50:35 +0900 Subject: [PATCH 28/33] =?UTF-8?q?refactor=20:=20fixture=20=EB=A1=9C=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coupon/CouponBookTest.kt | 4 ++-- .../estdelivery/domain/coupon/CouponTest.kt | 5 ++--- .../domain/fixture/CouponFixture.kt | 12 ++++++++++++ .../estdelivery/domain/member/MemberTest.kt | 16 ++++++---------- .../domain/shop/RoyalCustomersTest.kt | 10 +++------- .../estdelivery/domain/shop/ShopOwnerTest.kt | 11 ++++------- .../estdelivery/domain/shop/ShopTest.kt | 19 +++++++------------ .../domain/shop/UsedCouponBookTest.kt | 16 ++++++---------- 8 files changed, 42 insertions(+), 51 deletions(-) create mode 100644 src/test/kotlin/com/example/estdelivery/domain/fixture/CouponFixture.kt diff --git a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponBookTest.kt b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponBookTest.kt index 7826e1b..4d65f7e 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponBookTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponBookTest.kt @@ -1,5 +1,7 @@ package com.example.estdelivery.domain.coupon +import com.example.estdelivery.domain.fixture.게시된_고정_할인_쿠폰 +import com.example.estdelivery.domain.fixture.나눠준_비율_할인_쿠폰 import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe @@ -7,8 +9,6 @@ import io.kotest.matchers.shouldBe class CouponBookTest : FreeSpec({ lateinit var couponBook: CouponBook - val 나눠준_비율_할인_쿠폰 = Coupon.RateDiscountCoupon(1, 10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) - val 게시된_고정_할인_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) beforeTest { couponBook = CouponBook() diff --git a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt index 47edd37..bdc800f 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/coupon/CouponTest.kt @@ -1,12 +1,11 @@ package com.example.estdelivery.domain.coupon +import com.example.estdelivery.domain.fixture.게시된_고정_할인_쿠폰 +import com.example.estdelivery.domain.fixture.나눠준_비율_할인_쿠폰 import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe class CouponTest : FreeSpec({ - val 나눠준_비율_할인_쿠폰 = Coupon.RateDiscountCoupon(1, 10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) - val 게시된_고정_할인_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) - "게시된 쿠폰인지 확인 할 수 있다." { 게시된_고정_할인_쿠폰.isPublished() shouldBe true } diff --git a/src/test/kotlin/com/example/estdelivery/domain/fixture/CouponFixture.kt b/src/test/kotlin/com/example/estdelivery/domain/fixture/CouponFixture.kt new file mode 100644 index 0000000..7bc5ea5 --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/fixture/CouponFixture.kt @@ -0,0 +1,12 @@ +package com.example.estdelivery.domain.fixture + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponType + +val 나눠준_비율_할인_쿠폰 = Coupon.RateDiscountCoupon(1, 10, "10% 할인 쿠폰", "10% 할인 쿠폰 설명", CouponType.IS_HAND_OUT) +val 게시된_고정_할인_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) +val 게시할_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) +val 나눠줄_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) +val 게시되지_않은_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) +val 나눠주지_않은_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) + diff --git a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt index 1915d51..2ab1b77 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt @@ -1,28 +1,24 @@ package com.example.estdelivery.domain.member -import com.example.estdelivery.domain.coupon.Coupon -import com.example.estdelivery.domain.coupon.CouponBook -import com.example.estdelivery.domain.coupon.CouponType +import com.example.estdelivery.domain.fixture.게시된_고정_할인_쿠폰 import io.kotest.core.spec.style.FreeSpec -import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe class MemberTest : FreeSpec({ lateinit var member: Member - val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) beforeTest { member = Member(1, "홍길동", UnUsedCouponBook()) } "쿠폰을 추가할 수 있다." { - member.receiveCoupon(coupon) - member.showMyCouponBook().contains(coupon) shouldBe true + member.receiveCoupon(게시된_고정_할인_쿠폰) + member.showMyCouponBook().contains(게시된_고정_할인_쿠폰) shouldBe true } "쿠폰을 사용할 수 있다." { - member.receiveCoupon(coupon) - member.useCoupon(coupon) - member.showMyCouponBook().contains(coupon) shouldBe false + member.receiveCoupon(게시된_고정_할인_쿠폰) + member.useCoupon(게시된_고정_할인_쿠폰) + member.showMyCouponBook().contains(게시된_고정_할인_쿠폰) shouldBe false } }) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt index 44a1377..9c6af32 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt @@ -1,13 +1,10 @@ package com.example.estdelivery.domain.shop -import com.example.estdelivery.domain.coupon.Coupon -import com.example.estdelivery.domain.coupon.CouponBook -import com.example.estdelivery.domain.coupon.CouponType +import com.example.estdelivery.domain.fixture.게시된_고정_할인_쿠폰 import com.example.estdelivery.domain.member.Member import com.example.estdelivery.domain.member.UnUsedCouponBook import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec -import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe class RoyalCustomersTest : FreeSpec({ @@ -19,14 +16,13 @@ class RoyalCustomersTest : FreeSpec({ val 김철수 = Member(2, "김철수", UnUsedCouponBook()) val 이영희 = Member(3, "이영희", UnUsedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) - val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) // when - 단골_리스트.handOutCoupon(coupon) + 단골_리스트.handOutCoupon(게시된_고정_할인_쿠폰) // then for (royalMember in 단골_리스트.showRoyalCustomers()) { - royalMember.showMyCouponBook().contains(coupon) shouldBe true + royalMember.showMyCouponBook().contains(게시된_고정_할인_쿠폰) shouldBe true } } diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt index 1e502a5..726274c 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt @@ -1,8 +1,7 @@ package com.example.estdelivery.domain.shop -import com.example.estdelivery.domain.coupon.Coupon -import com.example.estdelivery.domain.coupon.CouponBook -import com.example.estdelivery.domain.coupon.CouponType +import com.example.estdelivery.domain.fixture.게시할_쿠폰 +import com.example.estdelivery.domain.fixture.나눠줄_쿠폰 import com.example.estdelivery.domain.member.Member import com.example.estdelivery.domain.member.UnUsedCouponBook import io.kotest.core.spec.style.FreeSpec @@ -18,7 +17,6 @@ class ShopOwnerTest : FreeSpec({ 단골_리스트.addRoyalCustomers(홍길동, 김철수) val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(), UsedCouponBook(), 단골_리스트)) - val 나눠줄_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) // when 가게_주인.handOutCouponToRoyalCustomersInShop(나눠줄_쿠폰) @@ -29,8 +27,7 @@ class ShopOwnerTest : FreeSpec({ "쿠폰을 가게에 게시한다." { // given - val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(),UsedCouponBook(), RoyalCustomers())) - val 게시할_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) + val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(), UsedCouponBook(), RoyalCustomers())) // when 가게_주인.publishCouponInShop(게시할_쿠폰) @@ -41,7 +38,7 @@ class ShopOwnerTest : FreeSpec({ "단골 회원을 가게에 추가한다." { // given - val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(),UsedCouponBook(), RoyalCustomers())) + val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(), UsedCouponBook(), RoyalCustomers())) val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) val 김철수 = Member(2, "김철수", UnUsedCouponBook()) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt index dd9174e..d90320a 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt @@ -1,8 +1,9 @@ package com.example.estdelivery.domain.shop -import com.example.estdelivery.domain.coupon.Coupon -import com.example.estdelivery.domain.coupon.CouponBook -import com.example.estdelivery.domain.coupon.CouponType +import com.example.estdelivery.domain.fixture.게시되지_않은_쿠폰 +import com.example.estdelivery.domain.fixture.게시할_쿠폰 +import com.example.estdelivery.domain.fixture.나눠주지_않은_쿠폰 +import com.example.estdelivery.domain.fixture.나눠줄_쿠폰 import com.example.estdelivery.domain.member.Member import com.example.estdelivery.domain.member.UnUsedCouponBook import io.kotest.assertions.throwables.shouldThrow @@ -12,7 +13,6 @@ import io.kotest.matchers.shouldBe class ShopTest : FreeSpec({ lateinit var 매장: Shop - val 게시할_쿠폰 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) beforeTest { val 단골_리스트 = RoyalCustomers() @@ -35,26 +35,21 @@ class ShopTest : FreeSpec({ } "게시하지 않는 쿠폰인 경우 사용 할 수 없다." { - val 게시되지_않은_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) shouldThrow { 매장.useCoupon(게시되지_않은_쿠폰) } } "나눠준 쿠폰이 아닌 경우 사용 할 수 없다." { - val 나눠주지_않은_쿠폰 = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) shouldThrow { 매장.useCoupon(나눠주지_않은_쿠폰) } } "모든 회원에게 쿠폰을 나눠줄 수 있다." { - // given - val 나눠줄_쿠폰_발급 = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_HAND_OUT) - // when - 매장.handOutCouponToRoyalCustomers(나눠줄_쿠폰_발급) + 매장.handOutCouponToRoyalCustomers(나눠줄_쿠폰) // then - 매장.showHandOutCoupon().contains(나눠줄_쿠폰_발급) shouldBe true + 매장.showHandOutCoupon().contains(나눠줄_쿠폰) shouldBe true for (royalMember in 매장.showRoyalCustomers()) { - royalMember.showMyCouponBook().contains(나눠줄_쿠폰_발급) shouldBe true + royalMember.showMyCouponBook().contains(나눠줄_쿠폰) shouldBe true } } diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/UsedCouponBookTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/UsedCouponBookTest.kt index e676219..17c5c62 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/UsedCouponBookTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/UsedCouponBookTest.kt @@ -1,35 +1,31 @@ package com.example.estdelivery.domain.shop -import com.example.estdelivery.domain.coupon.Coupon import com.example.estdelivery.domain.coupon.CouponBook -import com.example.estdelivery.domain.coupon.CouponType +import com.example.estdelivery.domain.fixture.게시되지_않은_쿠폰 +import com.example.estdelivery.domain.fixture.게시된_고정_할인_쿠폰 import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec -import io.kotest.core.spec.style.FunSpec -import io.kotest.matchers.shouldBe class UsedCouponBookTest : FreeSpec({ "이미 사용한 쿠폰은 재사용 할 수 없다." { // given val usedCouponBook = UsedCouponBook() val shopCouponBook = CouponBook() - val coupon = Coupon.FixDiscountCoupon(1, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) // when - shopCouponBook.addCoupon(coupon) - usedCouponBook.useCoupon(coupon, shopCouponBook) + shopCouponBook.addCoupon(게시된_고정_할인_쿠폰) + usedCouponBook.useCoupon(게시된_고정_할인_쿠폰, shopCouponBook) // then - shouldThrow { usedCouponBook.useCoupon(coupon, shopCouponBook) } + shouldThrow { usedCouponBook.useCoupon(게시된_고정_할인_쿠폰, shopCouponBook) } } "게시하지 않는 쿠폰인 경우 사용 할 수 없다." { // given val usedCouponBook = UsedCouponBook() val shopCouponBook = CouponBook() - val notPublishedCoupon = Coupon.FixDiscountCoupon(2, 1000, "1000원 할인 쿠폰", "1000원 할인 쿠폰 설명", CouponType.IS_PUBLISHED) // then - shouldThrow { usedCouponBook.useCoupon(notPublishedCoupon, shopCouponBook) } + shouldThrow { usedCouponBook.useCoupon(게시되지_않은_쿠폰, shopCouponBook) } } }) From c6bb4e0988ef285df20bc7251bbae983fea5014b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:18:23 +0900 Subject: [PATCH 29/33] =?UTF-8?q?chore=20:=20=EB=AA=A8=EB=8D=B8=EB=A7=81?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad199cb..3f7e518 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,20 @@ title: 이달의 민족 --- classDiagram - Shop *-- CouponBook + Shop *-- UnusedCouponBook + Shop *-- PublishedCouponBook + Shop *-- HandOutCouponBook Shop *-- RoyalCustomers RoyalCustomers *-- Member - Member *-- CouponBook + Member *-- UnUsedCouponBook CouponBook *-- Coupon FixDiscountCoupon --|> Coupon RateDiscountCoupon --|> Coupon ShopOwner *-- Shop + UnusedCouponBook *-- CouponBook + PublishedCouponBook *-- CouponBook + HandOutCouponBook *-- CouponBook + UsedCouponBook *-- CouponBook class CouponBook{ -List~Coupon~ coupons @@ -58,6 +64,32 @@ classDiagram +deleteCoupon(Coupon coupon) void +addCoupon(Coupon coupon) void } + + class UsedCouponBook{ + -CouponBook couponBook + +addUsedCoupon(Coupon coupon) void + +showUsedCoupons() List~Coupon~ + } + + class UnusedCouponBook{ + -CouponBook couponBook + +addUnusedCoupon(Coupon coupon) void + +removeUsedCoupon(Coupon coupon) void + +showUnusedCoupons() List~Coupon~ + } + + class PublishedCouponBook{ + -CouponBook couponBook + +addPublishedCoupon(Coupon coupon) void + +removePublishedCoupon(Coupon coupon) void + +showPublishedCoupons() List~Coupon~ + } + + class HandOutCouponBook{ + -CouponBook couponBook + +addHandOutCoupon(Coupon coupon) void + +showHandOutCoupons() List~Coupon~ + } class Coupon{ -String name From 72ffdfc778f60df01690e4a2116d8a8ea6a43714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:23:01 +0900 Subject: [PATCH 30/33] =?UTF-8?q?refactor=20:=20UnusedCouponBook=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=20=EB=B0=8F=20=ED=96=89=EC=9C=84=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estdelivery/domain/member/Member.kt | 11 +++-- .../domain/member/UnUsedCouponBook.kt | 20 --------- .../domain/member/UnusedCouponBook.kt | 28 +++++++++++++ .../estdelivery/domain/member/MemberTest.kt | 2 +- .../domain/member/UnusedCouponBookTest.kt | 42 +++++++++++++++++++ .../domain/shop/RoyalCustomersTest.kt | 10 ++--- .../estdelivery/domain/shop/ShopOwnerTest.kt | 10 ++--- .../estdelivery/domain/shop/ShopTest.kt | 10 ++--- 8 files changed, 91 insertions(+), 42 deletions(-) delete mode 100644 src/main/kotlin/com/example/estdelivery/domain/member/UnUsedCouponBook.kt create mode 100644 src/main/kotlin/com/example/estdelivery/domain/member/UnusedCouponBook.kt create mode 100644 src/test/kotlin/com/example/estdelivery/domain/member/UnusedCouponBookTest.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt b/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt index bffb0e9..1e908d5 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/member/Member.kt @@ -1,23 +1,22 @@ package com.example.estdelivery.domain.member import com.example.estdelivery.domain.coupon.Coupon -import com.example.estdelivery.domain.coupon.CouponBook class Member( val id: Long, val name: String, - private val unUsedCouponBook: UnUsedCouponBook + private val unusedCouponBook: UnusedCouponBook ) { fun useCoupon(coupon: Coupon) { - unUsedCouponBook.deleteUnUsedCoupon(coupon) + unusedCouponBook.removeUsedCoupon(coupon) } fun showMyCouponBook(): List { - return unUsedCouponBook.showUnUsedCoupons() + return unusedCouponBook.showUnusedCoupons() } fun receiveCoupon(coupon: Coupon) { - unUsedCouponBook.addUnUsedCoupon(coupon) + unusedCouponBook.addUnusedCoupon(coupon) } override fun equals(other: Any?): Boolean { @@ -34,6 +33,6 @@ class Member( } override fun toString(): String { - return "Member(id=$id, name='$name', unUsedCouponBook=$unUsedCouponBook)" + return "Member(id=$id, name='$name', unUsedCouponBook=$unusedCouponBook)" } } diff --git a/src/main/kotlin/com/example/estdelivery/domain/member/UnUsedCouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/member/UnUsedCouponBook.kt deleted file mode 100644 index 5c8a957..0000000 --- a/src/main/kotlin/com/example/estdelivery/domain/member/UnUsedCouponBook.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.example.estdelivery.domain.member - -import com.example.estdelivery.domain.coupon.Coupon -import com.example.estdelivery.domain.coupon.CouponBook - -class UnUsedCouponBook( - private val unUsedCouponBook: CouponBook = CouponBook(), -) { - fun showUnUsedCoupons(): List { - return unUsedCouponBook.showCoupons() - } - - fun addUnUsedCoupon(coupon: Coupon) { - unUsedCouponBook.addCoupon(coupon) - } - - fun deleteUnUsedCoupon(coupon: Coupon) { - unUsedCouponBook.deleteCoupon(coupon) - } -} diff --git a/src/main/kotlin/com/example/estdelivery/domain/member/UnusedCouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/member/UnusedCouponBook.kt new file mode 100644 index 0000000..5fcd28c --- /dev/null +++ b/src/main/kotlin/com/example/estdelivery/domain/member/UnusedCouponBook.kt @@ -0,0 +1,28 @@ +package com.example.estdelivery.domain.member + +import com.example.estdelivery.domain.coupon.Coupon +import com.example.estdelivery.domain.coupon.CouponBook + +class UnusedCouponBook( + private val unUsedCouponBook: CouponBook = CouponBook(), +) { + fun showUnusedCoupons(): List { + return unUsedCouponBook.showCoupons() + } + + fun addUnusedCoupon(coupon: Coupon) { + if (unUsedCouponBook.showCoupons().contains(coupon)) { + throw IllegalArgumentException("이미 존재하는 쿠폰입니다.") + } + + unUsedCouponBook.addCoupon(coupon) + } + + fun removeUsedCoupon(coupon: Coupon) { + if (!unUsedCouponBook.showCoupons().contains(coupon)) { + throw IllegalArgumentException("사용할 수 없는 쿠폰입니다.") + } + + unUsedCouponBook.deleteCoupon(coupon) + } +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt index 2ab1b77..5919976 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/member/MemberTest.kt @@ -8,7 +8,7 @@ class MemberTest : FreeSpec({ lateinit var member: Member beforeTest { - member = Member(1, "홍길동", UnUsedCouponBook()) + member = Member(1, "홍길동", UnusedCouponBook()) } "쿠폰을 추가할 수 있다." { diff --git a/src/test/kotlin/com/example/estdelivery/domain/member/UnusedCouponBookTest.kt b/src/test/kotlin/com/example/estdelivery/domain/member/UnusedCouponBookTest.kt new file mode 100644 index 0000000..4c23ef4 --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/member/UnusedCouponBookTest.kt @@ -0,0 +1,42 @@ +package com.example.estdelivery.domain.member + +import com.example.estdelivery.domain.fixture.게시된_고정_할인_쿠폰 +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.FreeSpec +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class UnusedCouponBookTest : FreeSpec({ + + "쿠폰을 추가할 수 있다." { + // given + val unusedCouponBook = UnusedCouponBook() + + // when + unusedCouponBook.addUnusedCoupon(게시된_고정_할인_쿠폰) + + // then + unusedCouponBook.showUnusedCoupons().contains(게시된_고정_할인_쿠폰) shouldBe true + } + + "쿠폰을 사용할 수 있다." { + // given + val unusedCouponBook = UnusedCouponBook() + unusedCouponBook.addUnusedCoupon(게시된_고정_할인_쿠폰) + + // when + unusedCouponBook.removeUsedCoupon(게시된_고정_할인_쿠폰) + + // then + unusedCouponBook.showUnusedCoupons().contains(게시된_고정_할인_쿠폰) shouldBe false + } + + "이미 추가된 쿠폰은 추가할 수 없다." { + // given + val unusedCouponBook = UnusedCouponBook() + unusedCouponBook.addUnusedCoupon(게시된_고정_할인_쿠폰) + + // then + shouldThrow { unusedCouponBook.addUnusedCoupon(게시된_고정_할인_쿠폰) } + } +}) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt index 9c6af32..b2e0d8f 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/RoyalCustomersTest.kt @@ -2,7 +2,7 @@ package com.example.estdelivery.domain.shop import com.example.estdelivery.domain.fixture.게시된_고정_할인_쿠폰 import com.example.estdelivery.domain.member.Member -import com.example.estdelivery.domain.member.UnUsedCouponBook +import com.example.estdelivery.domain.member.UnusedCouponBook import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe @@ -12,9 +12,9 @@ class RoyalCustomersTest : FreeSpec({ "모든 회원에게 쿠폰을 나눠줄 수 있다." { // given val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) - val 김철수 = Member(2, "김철수", UnUsedCouponBook()) - val 이영희 = Member(3, "이영희", UnUsedCouponBook()) + val 홍길동 = Member(1, "홍길동", UnusedCouponBook()) + val 김철수 = Member(2, "김철수", UnusedCouponBook()) + val 이영희 = Member(3, "이영희", UnusedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) // when @@ -29,7 +29,7 @@ class RoyalCustomersTest : FreeSpec({ "이미 추가된 회원은 추가할 수 없다." { // given val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) + val 홍길동 = Member(1, "홍길동", UnusedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동) // when diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt index 726274c..83f06f9 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopOwnerTest.kt @@ -3,7 +3,7 @@ package com.example.estdelivery.domain.shop import com.example.estdelivery.domain.fixture.게시할_쿠폰 import com.example.estdelivery.domain.fixture.나눠줄_쿠폰 import com.example.estdelivery.domain.member.Member -import com.example.estdelivery.domain.member.UnUsedCouponBook +import com.example.estdelivery.domain.member.UnusedCouponBook import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe @@ -12,8 +12,8 @@ class ShopOwnerTest : FreeSpec({ "모든 회원에게 쿠폰을 나눠줄 수 있다." { // given val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) - val 김철수 = Member(2, "김철수", UnUsedCouponBook()) + val 홍길동 = Member(1, "홍길동", UnusedCouponBook()) + val 김철수 = Member(2, "김철수", UnusedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수) val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(), UsedCouponBook(), 단골_리스트)) @@ -39,8 +39,8 @@ class ShopOwnerTest : FreeSpec({ "단골 회원을 가게에 추가한다." { // given val 가게_주인 = ShopOwner(Shop(PublishedCouponBook(), HandOutCouponBook(), UsedCouponBook(), RoyalCustomers())) - val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) - val 김철수 = Member(2, "김철수", UnUsedCouponBook()) + val 홍길동 = Member(1, "홍길동", UnusedCouponBook()) + val 김철수 = Member(2, "김철수", UnusedCouponBook()) // when 가게_주인.addRoyalCustomersInShop(홍길동, 김철수) diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt index d90320a..a3e6d64 100644 --- a/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/ShopTest.kt @@ -5,7 +5,7 @@ import com.example.estdelivery.domain.fixture.게시할_쿠폰 import com.example.estdelivery.domain.fixture.나눠주지_않은_쿠폰 import com.example.estdelivery.domain.fixture.나눠줄_쿠폰 import com.example.estdelivery.domain.member.Member -import com.example.estdelivery.domain.member.UnUsedCouponBook +import com.example.estdelivery.domain.member.UnusedCouponBook import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec import io.kotest.matchers.shouldBe @@ -16,9 +16,9 @@ class ShopTest : FreeSpec({ beforeTest { val 단골_리스트 = RoyalCustomers() - val 홍길동 = Member(1, "홍길동", UnUsedCouponBook()) - val 김철수 = Member(2, "김철수", UnUsedCouponBook()) - val 이영희 = Member(3, "이영희", UnUsedCouponBook()) + val 홍길동 = Member(1, "홍길동", UnusedCouponBook()) + val 김철수 = Member(2, "김철수", UnusedCouponBook()) + val 이영희 = Member(3, "이영희", UnusedCouponBook()) 단골_리스트.addRoyalCustomers(홍길동, 김철수, 이영희) 매장 = Shop(PublishedCouponBook(), HandOutCouponBook(), UsedCouponBook(), 단골_리스트) } @@ -54,7 +54,7 @@ class ShopTest : FreeSpec({ } "단골 회원을 추가할 수 있다." { - val 새로운_철수 = Member(14, "새로운 철수", UnUsedCouponBook()) + val 새로운_철수 = Member(14, "새로운 철수", UnusedCouponBook()) 매장.addRoyalCustomers(새로운_철수) 매장.showRoyalCustomers().contains(새로운_철수) shouldBe true } From 64262c8adfbe6b5ad9bdc88d5c661ec7555c019f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Fri, 9 Feb 2024 23:08:59 +0900 Subject: [PATCH 31/33] =?UTF-8?q?refactor=20:=20HandOutCouponBook=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=20=EB=B0=8F=20=ED=96=89=EC=9C=84=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/shop/HandOutCouponBook.kt | 4 +++ .../domain/shop/HandOutCouponBookTest.kt | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/test/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBookTest.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBook.kt index a52a8be..ba02ab0 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBook.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBook.kt @@ -11,6 +11,10 @@ class HandOutCouponBook( } fun addHandOutCoupon(coupon: Coupon) { + if (handOutCoupons.showCoupons().contains(coupon)) { + throw IllegalArgumentException("이미 나눠준 쿠폰입니다.") + } + handOutCoupons.addCoupon(coupon) } } diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBookTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBookTest.kt new file mode 100644 index 0000000..4eac5d9 --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/HandOutCouponBookTest.kt @@ -0,0 +1,35 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.fixture.게시된_고정_할인_쿠폰 +import com.example.estdelivery.domain.fixture.나눠줄_쿠폰 +import com.example.estdelivery.domain.member.Member +import com.example.estdelivery.domain.member.UnusedCouponBook +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.FreeSpec +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class HandOutCouponBookTest : FreeSpec({ + + "나눠줄 쿠폰을 담을 수 있다." { + // given + val handOutCouponBook = HandOutCouponBook() + + // when + handOutCouponBook.addHandOutCoupon(나눠줄_쿠폰) + + // then + handOutCouponBook.showHandOutCoupon().contains(나눠줄_쿠폰) shouldBe true + } + + "이미 추가된 쿠폰은 담을 수 없다." { + // given + val handOutCouponBook = HandOutCouponBook() + + // when + handOutCouponBook.addHandOutCoupon(나눠줄_쿠폰) + + // then + shouldThrow { handOutCouponBook.addHandOutCoupon(나눠줄_쿠폰) } + } +}) From e5217028be87561964f4c3f4d733718ab70c85f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Fri, 9 Feb 2024 23:10:54 +0900 Subject: [PATCH 32/33] =?UTF-8?q?refactor=20:=20PublishedCouponBook=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=20=EB=B0=8F=20=ED=96=89=EC=9C=84=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/shop/PublishedCouponBook.kt | 6 +++- .../domain/shop/PublishedCouponBookTest.kt | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/test/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBookTest.kt diff --git a/src/main/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBook.kt b/src/main/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBook.kt index 79a6958..65961a8 100644 --- a/src/main/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBook.kt +++ b/src/main/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBook.kt @@ -7,10 +7,14 @@ class PublishedCouponBook( private val publishedCoupons: CouponBook = CouponBook(), ) { fun publishCoupon(coupon: Coupon) { + if (publishedCoupons.showCoupons().contains(coupon)) { + throw IllegalArgumentException("이미 게시한 쿠폰입니다.") + } + publishedCoupons.addCoupon(coupon) } fun showPublishedCoupons(): List { return publishedCoupons.showCoupons() } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBookTest.kt b/src/test/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBookTest.kt new file mode 100644 index 0000000..e25524c --- /dev/null +++ b/src/test/kotlin/com/example/estdelivery/domain/shop/PublishedCouponBookTest.kt @@ -0,0 +1,29 @@ +package com.example.estdelivery.domain.shop + +import com.example.estdelivery.domain.fixture.게시할_쿠폰 +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class PublishedCouponBookTest : FunSpec({ + + test("게시된 쿠폰을 추가할 수 있다.") { + // given + val publishedCouponBook = PublishedCouponBook() + + // when + publishedCouponBook.publishCoupon(게시할_쿠폰) + + // then + publishedCouponBook.showPublishedCoupons().contains(게시할_쿠폰) shouldBe true + } + + test("이미 추가된 쿠폰은 추가할 수 없다.") { + // given + val publishedCouponBook = PublishedCouponBook() + publishedCouponBook.publishCoupon(게시할_쿠폰) + + // then + shouldThrow { publishedCouponBook.publishCoupon(게시할_쿠폰) } + } +}) From 2752118b3cc373788f44b100ebd5103d3782fadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=A5=E1=86=AB=E1=84=8E?= =?UTF-8?q?=E1=85=A1=E1=86=BC?= <92219795+this-is-spear@users.noreply.github.com> Date: Fri, 9 Feb 2024 23:11:53 +0900 Subject: [PATCH 33/33] =?UTF-8?q?chore=20:=20readme=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f7e518..e16491f 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ classDiagram Shop *-- HandOutCouponBook Shop *-- RoyalCustomers RoyalCustomers *-- Member - Member *-- UnUsedCouponBook + Member *-- UnusedCouponBook CouponBook *-- Coupon FixDiscountCoupon --|> Coupon RateDiscountCoupon --|> Coupon