@startuml event-목적선택 !theme mono title Event Service - 이벤트 목적 선택 및 저장 (UFR-EVENT-020) participant "EventController" as Controller <> participant "EventService" as Service <> participant "EventRepository" as Repo <> participant "Redis Cache" as Cache <> database "Event DB" as DB <> participant "Kafka Producer" as Kafka <> note over Controller: POST /api/events/purposes Controller -> Service: createEventDraft(userId, objective, storeInfo) activate Service Service -> Cache: get("purpose:" + userId) activate Cache Cache --> Service: null (캐시 미스) deactivate Cache Service -> Service: validate(objective, storeInfo) note right: 목적 유효성 검증\n- 신규 고객 유치\n- 재방문 유도\n- 매출 증대\n- 인지도 향상 Service -> Repo: save(eventDraft) activate Repo Repo -> DB: INSERT INTO event_drafts\n(user_id, objective, store_info, status) activate DB DB --> Repo: eventDraftId deactivate DB Repo --> Service: EventDraft entity deactivate Repo Service -> Cache: set("purpose:" + userId, eventDraft, TTL=30분) activate Cache Cache --> Service: OK deactivate Cache Service -> Kafka: publish(EventDraftCreated,\n{eventDraftId, userId, objective, createdAt}) activate Kafka note right: Kafka Event Topic:\nevent-topic\n\nEvent: EventDraftCreated\n(목적 선택 시 발행)\n\n※ EventCreated는\n최종 승인 시 발행 Kafka --> Service: ACK deactivate Kafka Service --> Controller: EventDraftResponse\n{eventDraftId, objective, status} deactivate Service Controller --> Client: 200 OK\n{eventDraftId} note over Controller, Kafka: 캐시 히트 시:\n1. Redis에서 조회 → 즉시 반환\n2. DB 조회 생략\n\n※ EventDraftCreated 이벤트는\nAnalytics Service가 선택적으로 구독\n(통계 초기화는 EventCreated 시) @enduml