@startuml event-추천안선택 !theme mono title Event Service - 선택한 AI 추천안 저장 (UFR-EVENT-040) actor Client participant "API Gateway" as Gateway participant "EventController" as Controller <> participant "EventService" as Service <> participant "EventRepository" as Repo <> participant "Redis Cache" as Cache <> database "Event DB" as DB <> note over Controller, Cache **UFR-EVENT-040: AI 추천안 선택 및 저장** - 사용자가 3가지 추천안 중 하나를 선택 - 선택된 추천안을 이벤트 초안에 적용 - Redis 캐시에서 AI 추천 결과 삭제 end note Client -> Gateway: PUT /api/events/drafts/{eventDraftId}/recommendation\n{"userId": 123,\n"selectedIndex": 1,\n"recommendation": {...}} activate Gateway Gateway -> Controller: PUT /api/events/drafts/{eventDraftId}/recommendation activate Controller Controller -> Controller: 요청 검증\n(필수 필드, 추천안 유효성) Controller -> Service: updateEventRecommendation(eventDraftId, userId,\nselectedRecommendation) activate Service == 1단계: 이벤트 초안 조회 및 검증 == Service -> Repo: findById(eventDraftId) activate Repo Repo -> DB: 이벤트 초안 조회\n(초안ID로 조회) activate DB DB --> Repo: EventDraft 엔티티\n{목적, 매장정보, 상태} deactivate DB Repo --> Service: EventDraft entity deactivate Repo Service -> Service: validateOwnership(userId, eventDraft) note right 소유권 검증: - 사용자ID와 초안 소유자 일치 확인 - 권한 없으면 403 Forbidden end note Service -> Service: validateRecommendation(selectedRecommendation) note right 추천안 유효성 검증: - 필수 필드 존재 여부 - 비용/ROI 값 타당성 end note == 2단계: 추천안 적용 == Service -> Service: applyRecommendation(eventDraft, selectedRecommendation) note right 추천안 적용: - 이벤트 제목 - 경품 정보 - 참여 방법 - 예상 비용 - 예상 ROI - 홍보 문구 end note == 3단계: DB 저장 == Service -> Repo: update(eventDraft) activate Repo Repo -> DB: 이벤트 초안 업데이트\n(선택된 추천안 정보 저장:\n제목, 경품, 참여방법,\n예상비용, 예상ROI,\n수정일시) activate DB DB --> Repo: 업데이트 완료 deactivate DB Repo --> Service: EventDraft entity deactivate Repo == 4단계: 캐시 무효화 == Service -> Cache: 캐시 삭제\nKey: ai:recommendation:{eventDraftId} activate Cache note right Redis 캐시 무효화: - AI 추천 결과 삭제 - 선택 완료 후 불필요 end note Cache --> Service: 삭제 완료 deactivate Cache == 5단계: 응답 반환 == Service --> Controller: EventRecommendationResponse\n{eventDraftId, selectedRecommendation} deactivate Service Controller --> Gateway: 200 OK\n{"eventDraftId": 123,\n"status": "추천안 선택 완료",\n"selectedRecommendation": {...}} deactivate Controller Gateway --> Client: 200 OK\n추천안 선택 완료 deactivate Gateway note over Client, Cache **저장 내용** - 최종 선택된 추천안만 Event DB에 저장 - Redis에 저장된 3가지 추천안은 선택 후 삭제 - 다음 단계: 콘텐츠 생성 (이미지 선택) **성능 목표** - 응답 시간: 0.5초 이내 - DB 업데이트: 0.1초 - 캐시 삭제: 0.01초 end note @enduml