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