-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
80 lines (65 loc) · 1.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import axios from "axios";
const baseURL = "https://four-sprint-mission-be.onrender.com";
const client = axios.create({
baseURL,
});
const getProducts = async ({
page = 1,
pageSize = 10,
orderBy = "recent",
keyword = "",
} = {}) => {
const url = `/products?page=${page}&pageSize=${pageSize}&orderBy=${orderBy}&keyword=${keyword}`;
const response = await client.get(url);
const data = response.data;
return data;
};
const getArticles = async ({
limit = 10,
sort = "latest",
skip = 0,
keyword = "",
} = {}) => {
const params = { limit, sort, skip, keyword };
const url = `/articles?`;
const res = await client.get(url, { params });
return res.data.articles;
};
const getArticle = async (articleId) => {
const url = `/articles/${articleId}`;
const response = await client.get(url);
const data = response.data;
return data;
};
const postArticle = async (articleData) => {
const url = `/articles`;
const response = await client.post(url, articleData);
return response.data;
};
// 게시글 삭제
const deleteArticle = async (articleId) => {
const url = `/articles/${articleId}`;
const res = await client.delete(url);
return res.data;
};
const editArticle = async (articleId, newArticle) => {
const url = `/articles/${articleId}`;
const res = await client.patch(url, newArticle);
return res.data;
};
const getCommentsOfArticle = async ({ articleId, limit = 10, cursor = 0 }) => {
const url = `/articles/${articleId}/commets?limit=${limit}&cursor=${cursor}`;
const response = await client.get(url);
const data = response.data;
return data;
};
const api = {
getProducts,
getArticles,
getArticle,
getCommentsOfArticle,
postArticle,
deleteArticle,
editArticle,
};
export default api;