File tree Expand file tree Collapse file tree 3 files changed +49
-3
lines changed
Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ const AddFolderModal = ({ folderName }: { folderName: string }) => {
2222 const res = await postFolders ( body ) ;
2323 console . log ( res ) ;
2424 } catch ( error ) {
25- console . log ( error ) ;
25+ console . log ( error , "폴더 생성 에러" ) ;
2626 }
2727 }
2828 closeModal ( ) ;
Original file line number Diff line number Diff line change @@ -3,12 +3,24 @@ import FolderList from "./modalComponents/FolderList";
33import ModalContainer from "./modalComponents/ModalContainer" ;
44import SubmitButton from "../SubMitButton" ;
55import { useState } from "react" ;
6+ import { postLink } from "@/lib/api/link" ;
67
78const AddModal = ( { list, link } : { list : FolderItemType [ ] ; link : string } ) => {
89 const [ selectedId , setSelectedId ] = useState < number | null > ( null ) ;
910
10- const handleSubmit = ( ) => {
11- //링크 생성 api 요청 또는 id 전달
11+ const handleSubmit = async ( ) => {
12+ const body = {
13+ url : link ,
14+ folderId : Number ( selectedId ) ,
15+ } ;
16+ if ( link !== "" && selectedId ) {
17+ try {
18+ const res = await postLink ( body ) ; // 테스트 필요 (상위에서 list, link받아서)
19+ console . log ( res ) ;
20+ } catch ( error ) {
21+ console . log ( error , "링크 생성 에러" ) ;
22+ }
23+ }
1224 } ;
1325
1426 const handleClickFolderItem = ( id : number ) => {
Original file line number Diff line number Diff line change 1+ import axiosInstance from "@/lib/api/axiosInstanceApi" ;
2+ import axios , { isAxiosError } from "axios" ;
3+ import { NextApiRequest , NextApiResponse } from "next" ;
4+
5+ const handler = async ( req : NextApiRequest , res : NextApiResponse ) => {
6+ const token = req . cookies . accessToken ;
7+ console . log ( "Token:" , token ) ;
8+
9+ if ( ! token ) {
10+ return res . status ( 401 ) . json ( { error : "사용자 정보를 찾을 수 없습니다." } ) ;
11+ }
12+
13+ if ( req . method === "POST" ) {
14+ try {
15+ const response = await axiosInstance . post ( "/folders" , req . body , {
16+ headers : {
17+ Authorization : `Bearer ${ token } ` ,
18+ } ,
19+ } ) ;
20+ console . log ( response ) ;
21+ return res . status ( 201 ) . json ( { message : "링크 추가 성공" } ) ; // 테스트 필요
22+ } catch ( error ) {
23+ if ( isAxiosError ( error ) && error . response ) {
24+ const status = error . response . status ;
25+ const message = error . response . data ?. message || "알 수 없는 오류 발생" ;
26+ return res . status ( status ) . json ( { message } ) ;
27+ }
28+ }
29+ } else {
30+ res . status ( 405 ) . json ( { message : "허용되지 않은 접근 방법" } ) ;
31+ }
32+ } ;
33+
34+ export default handler ;
You can’t perform that action at this time.
0 commit comments