Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions lib/api/auth.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};
6 changes: 6 additions & 0 deletions lib/api/axiosInstanceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
55 changes: 55 additions & 0 deletions lib/api/folder.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};
92 changes: 92 additions & 0 deletions lib/api/link.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};
16 changes: 16 additions & 0 deletions lib/api/oauth.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};
25 changes: 25 additions & 0 deletions lib/api/user.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};
Loading