From e4382dcd79e36f22774c028e9a1247eef9b1df7e Mon Sep 17 00:00:00 2001 From: ChoiWonkeun Date: Thu, 4 Dec 2025 16:00:34 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20review=20API=20request=EB=A5=BC=20JSON?= =?UTF-8?q?=20=E2=86=92=20FormData=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=ED=95=98=EC=97=AC=20400=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/reviewService.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/api/reviewService.js b/src/api/reviewService.js index 62bcb75..e5aaf37 100644 --- a/src/api/reviewService.js +++ b/src/api/reviewService.js @@ -3,20 +3,32 @@ const BASE_URL = import.meta.env.VITE_API_BASE_URL; export const fetchCodeReview = async (code, comment, repoUrl) => { const accessToken = localStorage.getItem("accessToken"); - const payload = { - code, - comment: comment?.trim() || null, - repoUrl: repoUrl?.trim() || null, - }; + // ๐Ÿ”น ๋ฐฑ์—”๋“œ๊ฐ€ @RequestParam("code", "comment", "repo_url", "branch") ๋ฅผ ๋ฐ›์œผ๋‹ˆ๊นŒ + // JSON ๋Œ€์‹  FormData๋กœ ๋ณด๋‚ด์ฃผ์ž. + const formData = new FormData(); + formData.append("code", code); // ํ•„์ˆ˜ + + if (comment && comment.trim()) { + formData.append("comment", comment.trim()); + } + + if (repoUrl && repoUrl.trim()) { + // ๋ฐฑ์—”๋“œ๋Š” "repo_url" ์ด๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋ฐ›์Œ!! + formData.append("repo_url", repoUrl.trim()); + } + + // branch๋Š” ์•ˆ ๋ณด๋‚ด๋„ defaultValue = "main" ์ด์ง€๋งŒ, ๋ช…์‹œ์ ์œผ๋กœ ๋ณด๋‚ด์ค„๊ฒŒ + formData.append("branch", "main"); try { const res = await fetch(`${BASE_URL}/api/review`, { method: "POST", headers: { - "Content-Type": "application/json", + // โš ๏ธ FormData ์“ธ ๋•Œ๋Š” Content-Type ์ง์ ‘ ์“ฐ์ง€ ๋ง๊ธฐ! + // ๋ธŒ๋ผ์šฐ์ €๊ฐ€ boundary ํฌํ•จํ•ด์„œ ์ž๋™์œผ๋กœ ๋„ฃ์–ด์คŒ. ...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}), }, - body: JSON.stringify(payload), + body: formData, }); const raw = await res.text(); @@ -45,7 +57,6 @@ export const fetchCodeReview = async (code, comment, repoUrl) => { try { return JSON.parse(raw); } catch { - // ์‘๋‹ต์ด ์ˆœ์ˆ˜ ํ…์ŠคํŠธ์ผ ๋•Œ return { review: raw, questions: [] }; } } catch (error) { @@ -57,4 +68,4 @@ export const fetchCodeReview = async (code, comment, repoUrl) => { } throw error; } -}; +}; \ No newline at end of file