From 2bba8a8518cd4c0204847ebacf5ad99dd66432a9 Mon Sep 17 00:00:00 2001 From: wnhaoo <153691178+wnhaoo@users.noreply.github.com> Date: Wed, 21 May 2025 16:36:56 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=8F=AC=ED=8A=B8=ED=8F=B4=EB=A6=AC?= =?UTF-8?q?=EC=98=A4=20=EC=97=85=EB=A1=9C=EB=93=9C=20api=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mentorship/api/MentorViewApi.ts | 4 +- src/user/api/MentorInfoApi.ts | 4 +- src/user/api/profileApi.ts | 16 +++++++ .../components/ProfileEdit/EditHashtags.tsx | 2 +- .../components/ProfileEdit/EditPortfolio.tsx | 42 +++++++++++-------- .../components/profileInfo/MenteeInfoBio.tsx | 3 +- .../profileInfo/MentorInfoPortfolio.tsx | 4 +- .../pages/ProfileEdit/MentorProfileEdit.tsx | 1 + src/user/types.ts | 4 +- 9 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/mentorship/api/MentorViewApi.ts b/src/mentorship/api/MentorViewApi.ts index 50c616c..bb41d61 100644 --- a/src/mentorship/api/MentorViewApi.ts +++ b/src/mentorship/api/MentorViewApi.ts @@ -20,8 +20,8 @@ export const getMentorById = async (mentorId: number): Promise = mentoringField: data.mentoringField ?? [], hashtags: data.hashtags ?? [], message: data.message ?? '', - portfolio: data.portfolio ?? { url: '', description: '', size: 0 }, + portfolio: data.portfolio ?? { url: '', description: '', fileSize: 0 }, image: data.image ?? { fileName: '', filePath: '' }, - mentoringCount: data.mentoringCount ?? 0, + mentoringCount: data.mentoringCount ?? '', }; }; \ No newline at end of file diff --git a/src/user/api/MentorInfoApi.ts b/src/user/api/MentorInfoApi.ts index ffc93eb..ea5d81a 100644 --- a/src/user/api/MentorInfoApi.ts +++ b/src/user/api/MentorInfoApi.ts @@ -23,9 +23,9 @@ export const getMentorProfile = async (): Promise => { mentoringField: data.mentoringField ?? [], hashtags: data.hashtags ?? [], message: data.message ?? '', - portfolio: data.portfolio ?? { url: '', description: '', size: 0 }, + portfolio: data.portfolio ?? { url: '', description: '', fileSize: 0 }, image: data.image ?? { fileName: '', filePath: '' }, - mentoringCount: data.mentoringCount ?? 0, + mentoringCount: data.mentoringCount ?? '', }; }; diff --git a/src/user/api/profileApi.ts b/src/user/api/profileApi.ts index 5ecd33a..fc4d72b 100644 --- a/src/user/api/profileApi.ts +++ b/src/user/api/profileApi.ts @@ -24,6 +24,22 @@ export const uploadProfileImage = async ( } }; +// 멘토 포트폴리오 업로드 API +export const uploadPortfolio = async (file: File): Promise => { + const formData = new FormData(); + formData.append('file', file); + + try { + const response = await axiosInstance.post( + '/v1/portfolio', + formData, + ); + return response.data.message; + } catch (error) { + throw new Error('포트폴리오 업로드 실패'); + } +}; + // 멘토 프로필 등록 API export const createMentorProfile = async (mentorData: MentorProfileData) => { try { diff --git a/src/user/components/ProfileEdit/EditHashtags.tsx b/src/user/components/ProfileEdit/EditHashtags.tsx index 99f5727..c012786 100644 --- a/src/user/components/ProfileEdit/EditHashtags.tsx +++ b/src/user/components/ProfileEdit/EditHashtags.tsx @@ -60,7 +60,7 @@ const EditHashtags = ({ mentorData, setMentorData }: EditHashtagsProps) => { > #{tag} ))} diff --git a/src/user/components/ProfileEdit/EditPortfolio.tsx b/src/user/components/ProfileEdit/EditPortfolio.tsx index c78eda0..aebbe15 100644 --- a/src/user/components/ProfileEdit/EditPortfolio.tsx +++ b/src/user/components/ProfileEdit/EditPortfolio.tsx @@ -1,4 +1,5 @@ import { MentorData } from '@/user/types'; +import { uploadPortfolio } from '@/user/api/profileApi'; import { X } from 'lucide-react'; interface EditPortfolioProps { @@ -19,32 +20,37 @@ const EditPortfolio = ({ mentorData, setMentorData }: EditPortfolioProps) => { }); }; - // 파일 업로드 (10MB 이하 파일만 허용) - const handleFileUpload = (e: React.ChangeEvent) => { + // 파일 업로드 + const handleFileUpload = async (e: React.ChangeEvent) => { if (e.target.files && e.target.files.length > 0) { const file = e.target.files[0]; // 10MB 초과하면 업로드 차단 if (file.size > 10 * 1000 * 1000) { alert('10MB 이하의 파일만 업로드할 수 있습니다.'); - e.target.value = ''; // 파일 선택 초기화 + e.target.value = ''; return; } - // 기존 파일이 있으면 삭제 후 새 파일 업로드 - removeFile(); + try { + const portfolioUrl = await uploadPortfolio(file); - setMentorData((prev) => { - if (!prev) return prev; - return { - ...prev, - portfolio: { - url: URL.createObjectURL(file), - description: file.name, - size: file.size, - }, - }; - }); + removeFile(); + setMentorData((prev) => { + if (!prev) return prev; + return { + ...prev, + portfolio: { + description: file.name, + url: portfolioUrl, + fileSize: file.size, + }, + }; + }); + } catch (error) { + alert('포트폴리오 업로드 실패'); + console.error(error); + } } }; @@ -68,7 +74,7 @@ const EditPortfolio = ({ mentorData, setMentorData }: EditPortfolioProps) => {
{mentorData.portfolio.description} - ({(mentorData.portfolio.size / 1000000).toFixed(1)}MB) + ({(mentorData.portfolio.fileSize / 1000000).toFixed(1)}MB)
)} diff --git a/src/user/components/profileInfo/MenteeInfoBio.tsx b/src/user/components/profileInfo/MenteeInfoBio.tsx index e602dfb..12a3333 100644 --- a/src/user/components/profileInfo/MenteeInfoBio.tsx +++ b/src/user/components/profileInfo/MenteeInfoBio.tsx @@ -5,8 +5,7 @@ interface MenteeInfoBioProps { const MenteeInfoBio = ({ introduction }: MenteeInfoBioProps) => { return (
-
{introduction}
-
{introduction}
+
{introduction}
); }; diff --git a/src/user/components/profileInfo/MentorInfoPortfolio.tsx b/src/user/components/profileInfo/MentorInfoPortfolio.tsx index d3f40b7..870f4bb 100644 --- a/src/user/components/profileInfo/MentorInfoPortfolio.tsx +++ b/src/user/components/profileInfo/MentorInfoPortfolio.tsx @@ -1,5 +1,5 @@ interface MentorInfoPortfolioProps { - portfolio: { url: string; description: string; size: number } | null; + portfolio: { url: string; description: string; fileSize: number } | null; } const MentorInfoPortfolio = ({ portfolio }: MentorInfoPortfolioProps) => { @@ -20,7 +20,7 @@ const MentorInfoPortfolio = ({ portfolio }: MentorInfoPortfolioProps) => { > {portfolio.description} - ({(portfolio.size / 1000000).toFixed(1)}MB) + ({(portfolio.fileSize / 1000000).toFixed(1)}MB) diff --git a/src/user/pages/ProfileEdit/MentorProfileEdit.tsx b/src/user/pages/ProfileEdit/MentorProfileEdit.tsx index 88e8bc9..cf25502 100644 --- a/src/user/pages/ProfileEdit/MentorProfileEdit.tsx +++ b/src/user/pages/ProfileEdit/MentorProfileEdit.tsx @@ -36,6 +36,7 @@ const MentorProfileEdit = () => { } const handleSave = async () => { + console.log("mentorData to be sent:", JSON.stringify(mentorData, null, 2)); try { await updateMentorProfile(mentorData); navigate("/user/mentorinfo"); diff --git a/src/user/types.ts b/src/user/types.ts index 978698e..3b66393 100644 --- a/src/user/types.ts +++ b/src/user/types.ts @@ -26,7 +26,7 @@ export interface MentorData { portfolio: { url: string; description: string; - size: number; + fileSize: number; } | null; image: { fileName: string; @@ -63,7 +63,7 @@ export interface MentorViewData { portfolio: { url: string; description: string; - size: number; + fileSize: number; } | null; image: { fileName: string;