비즈니스 규칙이 Entity에 있으므로 UseCase는 DomainService 호출만 수행.
의존
선행: STK1-01
후행: STK1-05, STK1-06
다이어그램
처리 흐름
sequenceDiagram
participant DS as PriceAlertDomainService
participant PA as PriceAlert (Entity)
participant AH as AlertHistory
DS->>PA: isReached(currentPrice)
alt 도달
PA-->>DS: true
DS->>PA: trigger(currentPrice)
PA->>PA: status = TRIGGERED
PA->>AH: AlertHistory.create(alert, triggeredPrice)
DS->>AlertRepository: save(alert, history)
else 미도달
PA-->>DS: false
end
클래스 의존
flowchart LR
subgraph Domain["domain"]
DS[PriceAlertDomainService]
PA[PriceAlert]
AH[AlertHistory]
AD[AlertDirection]
AS[AlertStatus]
AR[AlertRepository]
PGW[PriceGateway]
NGW[NotificationGateway]
end
DS --> PA
DS --> AH
DS --> AR
DS --> PGW
DS --> NGW
PA --> AD
PA --> AS
테스트 케이스
ABOVE 방향이고 현재가 >= 목표가이면 isReached()가 true를 반환한다.
ABOVE 방향이고 현재가 < 목표가이면 isReached()가 false를 반환한다.
BELOW 방향이고 현재가 ⇐ 목표가이면 isReached()가 true를 반환한다.
ACTIVE 상태에서 도달 시 trigger() 호출 후 상태가 TRIGGERED로 전이된다.
이미 TRIGGERED된 알림에 trigger()를 재호출해도 상태가 변하지 않는다.
도달 시 AlertHistory가 생성되고 triggeredPrice가 현재가로 기록된다.
DISABLED 상태 알림은 evaluateActiveAlerts() 평가 대상에서 제외된다.