From e1287806a774ca7b9a639884c79066a6293888bc Mon Sep 17 00:00:00 2001 From: sunmingLee <25thbam@gmail.com> Date: Thu, 30 Oct 2025 13:04:49 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B0=ED=8F=AC=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../events/create/steps/ApprovalStep.tsx | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/app/(main)/events/create/steps/ApprovalStep.tsx b/src/app/(main)/events/create/steps/ApprovalStep.tsx index 155e419..5e4e816 100644 --- a/src/app/(main)/events/create/steps/ApprovalStep.tsx +++ b/src/app/(main)/events/create/steps/ApprovalStep.tsx @@ -88,39 +88,46 @@ export default function ApprovalStep({ eventData, onApprove, onBack }: ApprovalS }); console.log('✅ Event details updated'); - // 3. 배포 채널 선택 - if (eventData.channels && eventData.channels.length > 0) { - console.log('📞 Selecting channels:', eventData.channels); + // 채널명 매핑 (Frontend → Backend) + const channelMap: Record = { + uriTV: ['URIDONGNETV'], + ringoBiz: ['RINGOBIZ'], + genieTV: ['GINITV'], + sns: ['INSTAGRAM', 'NAVER', 'KAKAO'], + }; - // 채널명 매핑 (Frontend → Backend) - const channelMap: Record = { - 'uriTV': 'WEBSITE', - 'ringoBiz': 'EMAIL', - 'genieTV': 'KAKAO', - 'sns': 'INSTAGRAM', - }; + const apiChannels = eventData.channels?.flatMap(ch => channelMap[ch] || []) || []; - const backendChannels = eventData.channels.map(ch => channelMap[ch] || ch.toUpperCase()); + const distributionRequest = { + eventId: eventId, + title: eventName, + description: eventData.contentEdit?.guide || eventData.recommendation?.recommendation?.description || '', + imageUrl: '', // TODO: 이미지 URL 연동 필요 + channels: apiChannels, + channelSettings: {}, + }; - await eventApi.selectChannels(eventId, { - channels: backendChannels, - }); - console.log('✅ Channels selected'); + console.log('🚀 Distributing event:', distributionRequest); + + const response = await fetch(`${DISTRIBUTION_API_BASE_URL}/api/v1/distribution/distribute`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(distributionRequest), + }); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.error || '배포 중 오류가 발생했습니다'); } - // 4. TODO: 이미지 선택 - // 현재 frontend에서 selectedImageId를 추적하지 않음 - // 향후 contentPreview 단계에서 선택된 이미지 ID를 eventData에 저장 필요 - console.log('⚠️ Image selection skipped - imageId not tracked in frontend'); + const data = await response.json(); + console.log('✅ Distribution completed:', data); - // 5. 이벤트 배포 API 호출 - console.log('📞 Publishing event:', eventId); - const publishResponse = await eventApi.publishEvent(eventId); - console.log('✅ Event published:', publishResponse); - - // 성공 다이얼로그 표시 setIsDeploying(false); setSuccessDialogOpen(true); + } else { throw new Error('Event creation failed: No event ID returned'); } @@ -130,7 +137,7 @@ export default function ApprovalStep({ eventData, onApprove, onBack }: ApprovalS alert('이벤트 배포에 실패했습니다. 다시 시도해 주세요.'); } }; - + const handleSaveDraft = () => { // TODO: 임시저장 API 연동