diff --git a/lib/api/auth.ts b/lib/api/auth.ts new file mode 100644 index 0000000..271395c --- /dev/null +++ b/lib/api/auth.ts @@ -0,0 +1,65 @@ +import axiosInstance from "./axiosInstanceApi"; + +interface signInProps { + email: string; + password: string; +} + +interface signUpProps extends signInProps { + name: string; +} + +interface easySignInProps { + token: string; + redirectUri: string; +} + +interface easySignUpProps extends easySignInProps { + name: string; +} + +// 회원가입 +export const postSignUp = async (body: signUpProps) => { + try { + const res = await axiosInstance.post("/auth/sign-up", body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 로그인 +export const postSignIn = async (body: signInProps) => { + try { + const res = await axiosInstance.post("/auth/sign-in", body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 간편 회원가입 +export const postEasySignUp = async ( + provider: "google" | "kakao", + body: easySignUpProps +) => { + try { + const res = await axiosInstance.post(`/auth/sign-up/${provider}`, body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 간편 로그인 +export const postEasySignIn = async ( + provider: "google" | "kakao", + body: easySignInProps +) => { + try { + const res = await axiosInstance.post(`/auth/sign-in/${provider}`, body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; diff --git a/lib/api/axiosInstanceApi.ts b/lib/api/axiosInstanceApi.ts index 79d8c0e..5310b16 100644 --- a/lib/api/axiosInstanceApi.ts +++ b/lib/api/axiosInstanceApi.ts @@ -5,4 +5,10 @@ const axiosInstance = axios.create({ timeout: 5000, }); +export const proxy = axios.create({ + // 배포 이후에는 배포된 URL로 변경해야 함. + baseURL: "http://localhost:3000", + timeout: 5000, +}); + export default axiosInstance; diff --git a/lib/api/folder.ts b/lib/api/folder.ts new file mode 100644 index 0000000..90423dd --- /dev/null +++ b/lib/api/folder.ts @@ -0,0 +1,55 @@ +import axiosInstance, { proxy } from "./axiosInstanceApi"; + +interface folderApiProps { + name: string; +} + +// 유저의 모든 폴더 조회(auth) +export const getFolders = async () => { + try { + const res = await proxy.get("/api/folders"); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 유저의 폴더 생성(auth) +export const postFolders = async (body: folderApiProps) => { + try { + const res = await proxy.post("/api/folders", body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 폴더 조회 +export const getFolder = async (forderId: number) => { + try { + const res = await axiosInstance.get(`/folders/${forderId}`); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 폴더 삭제(auth) +export const deleteFolder = async (forderId: number) => { + try { + const res = await proxy.delete(`/api/folders/${forderId}`); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 폴더 이름 수정(auth) +export const putFolder = async (forderId: number, body: folderApiProps) => { + try { + const res = await proxy.put(`/api/folders/${forderId}`, body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; diff --git a/lib/api/link.ts b/lib/api/link.ts new file mode 100644 index 0000000..54a62d5 --- /dev/null +++ b/lib/api/link.ts @@ -0,0 +1,92 @@ +import axiosInstance, { proxy } from "./axiosInstanceApi"; + +interface postLinkProps { + url: string; + folderId: number; +} + +interface putLinkURLProps { + url: string; +} + +interface putFolderNameProps { + favorite: boolean; +} + +// 폴더에 속한 링크 조회 +export const getLink = async (query: any, forderId: number) => { + let queryString; + query ? (queryString = `?page=${query.page}&pageSize=${query.pageSize}`) : ""; + + try { + const res = await axiosInstance.get( + `/folders/${forderId}/links${queryString}` + ); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 링크 생성(auth) +export const postLink = async (body: postLinkProps) => { + try { + const res = await proxy.post("/api/links", body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 유저의 전체 링크 조회(auth) +export const getLinks = async () => { + try { + const res = await proxy.get("/api/links"); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 유저의 즐겨찾기 링크 조회(auth) +export const getFavorites = async () => { + try { + const res = await proxy.get("/api/favorites"); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 링크 URL 수정(auth) +export const putLinkURL = async (linkId: number, body: putLinkURLProps) => { + try { + const res = await proxy.put(`/api/links/${linkId}`, body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 링크 삭제(auth) +export const deleteLinkURL = async (linkId: number) => { + try { + const res = await proxy.delete(`/api/links/${linkId}`); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 링크의 즐겨찾기 설정(auth) +export const putFolderName = async ( + linkId: number, + body: putFolderNameProps +) => { + try { + const res = await proxy.put(`/api/links/${linkId}`, body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; diff --git a/lib/api/oauth.ts b/lib/api/oauth.ts new file mode 100644 index 0000000..1c40f1e --- /dev/null +++ b/lib/api/oauth.ts @@ -0,0 +1,16 @@ +import axiosInstance from "./axiosInstanceApi"; + +interface postOAuthProps { + provider: string; + appKey: string; +} + +// 간편 로그인 App 등록/수정 +export const postOAuth = async (body: postOAuthProps) => { + try { + const res = await axiosInstance.post("/oauthApps", body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; diff --git a/lib/api/user.ts b/lib/api/user.ts new file mode 100644 index 0000000..2059943 --- /dev/null +++ b/lib/api/user.ts @@ -0,0 +1,25 @@ +import axiosInstance, { proxy } from "./axiosInstanceApi"; + +interface postUserProps { + email: string; +} + +// 현재 유저 조회(auth) +export const getUserInfo = async () => { + try { + const res = await proxy.get("/api/users"); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +}; + +// 이메일 중복 확인 +export const postCheckEmail = async (body: postUserProps) => { + try { + const res = await axiosInstance.post("/users/check-email", body); + if (res.status >= 200 && res.status < 300) return res.data; + } catch (err) { + console.error("에러 메시지: ", err instanceof Error ? err.message : err); + } +};