Skip to content

Commit

Permalink
Merge pull request #1 from this-is-spear/domain
Browse files Browse the repository at this point in the history
도메인 모델을 추가한다.
  • Loading branch information
this-is-spear committed Feb 9, 2024
2 parents 3037c8e + 2752118 commit 09d715e
Show file tree
Hide file tree
Showing 24 changed files with 1,027 additions and 6 deletions.
149 changes: 144 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
**/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
192 changes: 191 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,194 @@
2. fork한 레포지토리를 clone합니다.
3. clone한 레포지토리에서 브랜치를 생성합니다. (브랜치 이름은 자유롭게)
4. 해당 브랜치에서 작업을 진행합니다.
5. 작업이 완료되면 PR을 보냅니다. (PR은 각 이름 브랜치로 보내주세요.)
5. 작업이 완료되면 PR을 보냅니다. (PR은 각 이름 브랜치로 보내주세요.)

## 설계 과정

### 요구사항 정리

- 쿠폰은 OOO 대상을 할인하기 위한 목적이다.
- 가게에 진열된 상품 대상
- 회원은 OOO 행동으로 쿠폰을 발급받는다.
- 가게에 접근해 쿠폰 발급 버튼을 누르는 행동
- 가게 주인이 가게 쿠폰을 가져갔던 손님들에게 쿠폰을 뿌리는 행동
- 쿠폰의 할인 정책은 OOO 방법을 적용한다.
- 고정금액을 할인하는 정액제 방법
- 비율로 할인하는 정률제 방법

### 프로그래밍 요구사항 정리

- 발급받은 쿠폰 식별자는 시간대별로 순서가 보장되어야 한다.

> ID는 시간대별 순서가 보장되도록 고민한 이유는 쿠폰은 유효기간이 존재하고 제약 조건도 많아 사용자의 기억속에 휘발성이 많다고 생각해서이다. 그래서 시간 지역성을 띈다고 생각했고 한 번 조회할 때마다 하나의 블록을 읽어오는 InnonDB의 특성을 잘 살릴 수 있어보였다.
### 도메인 모델링

```mermaid
---
title: 이달의 민족
---
classDiagram
Shop *-- UnusedCouponBook
Shop *-- PublishedCouponBook
Shop *-- HandOutCouponBook
Shop *-- RoyalCustomers
RoyalCustomers *-- Member
Member *-- UnusedCouponBook
CouponBook *-- Coupon
FixDiscountCoupon --|> Coupon
RateDiscountCoupon --|> Coupon
ShopOwner *-- Shop
UnusedCouponBook *-- CouponBook
PublishedCouponBook *-- CouponBook
HandOutCouponBook *-- CouponBook
UsedCouponBook *-- CouponBook
class CouponBook{
-List~Coupon~ coupons
+existCoupon(Coupon coupon) void
+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
-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(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~
}
```


### 데이터 모델링

```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
```
45 changes: 45 additions & 0 deletions src/main/kotlin/com/example/estdelivery/domain/coupon/Coupon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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(id, name, description, couponType)

class FixDiscountCoupon(
id: Long,
val discountAmount: Int,
override val name: String,
override val description: String,
couponType: CouponType
) : Coupon(id, name, description, couponType)

fun isPublished(): Boolean {
return couponType == CouponType.IS_PUBLISHED
}

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()
}
}
Loading

0 comments on commit 09d715e

Please sign in to comment.