Skip to content

Commit

Permalink
docs: readme 파일 수정, EOL 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
paengdal committed Nov 12, 2024
1 parent 1cba686 commit 24710f0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 33 deletions.
52 changes: 38 additions & 14 deletions ArticleService.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,65 @@
import axios from 'axios';
import axios from "axios";

const instance = axios.create({
baseURL: 'https://sprint-mission-api.vercel.app/',
baseURL: "https://sprint-mission-api.vercel.app/",
timeout: 3000,
});

export function getArticleList(params = {}) {
instance.get('/articles', { params })
instance
.get("/articles", { params })
.then((res) => console.log(res.data))
.catch((e) => console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`));
.catch((e) =>
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
)
);
}

export function getArticle(id) {
instance.get(`/articles/${id}`)
instance
.get(`/articles/${id}`)
.then((res) => console.log(res.data))
.catch((e) => console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`));
.catch((e) =>
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
)
);
}

export function createArticle(article) {
instance.post('/articles', article)
instance
.post("/articles", article)
.then((res) => console.log(res.data))
.catch((e) => console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`));
.catch((e) =>
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
)
);
}

export function patchArticle(id, article) {
instance.patch(`/articles/${id}`, article)
instance
.patch(`/articles/${id}`, article)
.then((res) => console.log(res.data))
.catch((e) => console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`));
.catch((e) =>
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
)
);
}

export function deleteArticle(id) {
instance.delete(`/articles/${id}`)
instance
.delete(`/articles/${id}`)
.then((res) => console.log(res.data))
.catch((e) => console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`));
.catch((e) =>
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
)
);
}


/* fetch로 구현 연습 */
// export async function getArticleList(params = {}) {
// const url = new URL('https://sprint-mission-api.vercel.app/articles');
Expand Down Expand Up @@ -72,4 +96,4 @@ export function deleteArticle(id) {
// const data = (await res).json();
// return data;

// }
// }
34 changes: 21 additions & 13 deletions ProductService.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
import axios from 'axios';
import axios from "axios";

const instance = axios.create({
baseURL: 'https://sprint-mission-api.vercel.app/',
baseURL: "https://sprint-mission-api.vercel.app/",
timeout: 3000,
});

export async function getProductList(params = {}) {
try {
const res = await instance.get('/products', { params });
const res = await instance.get("/products", { params });
return res.data;
} catch (e) {
console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`)
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
);
}

}

export async function getProduct(id) {
try {
const res = await instance.get(`/products/${id}`);
return res.data;
} catch (e) {
console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`)
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
);
}
}

export async function createProduct(product) {
try {
const res = await instance.post('/products', product);
const res = await instance.post("/products", product);
return res.data;
} catch (e) {
console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`)
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
);
}
}

Expand All @@ -38,16 +43,19 @@ export async function patchProduct(id, product) {
const res = await instance.patch(`/products/${id}`, product);
return res.data;
} catch (e) {
console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`)
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
);
}
}

export async function deleteProduct(id) {
try {
const res = await instance.delete(`/products/${id}`);
return res.data;
} catch (e) {
console.log(
`status: ${e.response.status}\nmessage: ${e.response.data.message}`
);
}
catch (e) {
console.log(`status: ${e.response.status}\nmessage: ${e.response.data.message}`)
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
* 사용자 데이터 확인 후 에러메시지 팝업(모달) 또는 페이지 이동
* 반응형 디자인(PC, 태블릿, 모바일)
3. **스프린트 미션 4**
* API를 이용한 비동기 처리 함수 구현
21 changes: 15 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { getArticleList, getArticle, createArticle, patchArticle, deleteArticle } from "./ArticleService.js";
import { getProductList, getProduct, createProduct, patchProduct, deleteProduct } from "./ProductService.js";

import {
getArticleList,
getArticle,
createArticle,
patchArticle,
deleteArticle,
} from "./ArticleService.js";
import {
getProductList,
getProduct,
createProduct,
patchProduct,
deleteProduct,
} from "./ProductService.js";

/* --- ArticleService.js 작동 테스트 --- */

Expand All @@ -24,8 +35,6 @@ import { getProductList, getProduct, createProduct, patchProduct, deleteProduct

// deleteArticle(1051);



/* --- ProductService.js 작동 테스트 --- */

// console.log(await getProductList({ page: 10, pageSize: 5, keyword: '상품' }));
Expand All @@ -44,4 +53,4 @@ console.log(await getProduct(569));

// console.log(await patchProduct(569, product));

// console.log(await deleteProduct(569));
// console.log(await deleteProduct(569));

0 comments on commit 24710f0

Please sign in to comment.