-
Notifications
You must be signed in to change notification settings - Fork 25
박가연 sprint 3 과제 제출 #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: basic
Are you sure you want to change the base?
The head ref may contain hidden characters: "basic-\uBC15\uAC00\uC5F0"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import axios from "axios"; | ||
|
|
||
| const API_URL = "https://panda-market-api-crud.vercel.app/articles"; | ||
|
|
||
| export function getArticleList(params) { | ||
| return axios | ||
| .get(API_URL, { | ||
| params: params, | ||
| }) | ||
| .then(function (response) { | ||
| console.log("게시글 목록을 성공적으로 불러왔습니다."); | ||
| return response.data; | ||
| }) | ||
| .catch(function (error) { | ||
| console.log("목록 조회 중 에러 발생: " + error.message); | ||
| }); | ||
| } | ||
|
|
||
| export function getArticle(id) { | ||
| return axios | ||
| .get(API_URL + "/" + id) | ||
| .then(function (res) { | ||
| return res.data; | ||
| }) | ||
| .catch(function (err) { | ||
| console.log("상세 조회 실패!"); | ||
| }); | ||
| } | ||
|
|
||
| export function createArticle(data) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createArticle 데이터 검증 validation을 하면 좋을거같아요. |
||
| return axios | ||
| .post(API_URL, { | ||
| title: data.title, | ||
| content: data.content, | ||
| image: data.image, | ||
| }) | ||
| .then(function (res) { | ||
| return res.data; | ||
| }) | ||
| .catch(function (err) { | ||
| console.log("글 생성 실패"); | ||
| }); | ||
| } | ||
|
|
||
| export function patchArticle(id, updateData) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. patchArticle 데이터 검증 validation을 하면 좋을거같아요. (2) |
||
| return axios | ||
| .patch(API_URL + "/" + id, updateData) | ||
| .then(function (res) { | ||
| return res.data; | ||
| }) | ||
| .catch(function (err) { | ||
| console.log("글 수정 실패"); | ||
| }); | ||
| } | ||
|
|
||
| export function deleteArticle(id) { | ||
| return axios | ||
| .delete(API_URL + "/" + id) | ||
| .then(function (res) { | ||
| return res.data; | ||
| }) | ||
| .catch(function (err) { | ||
| console.log("글 삭제 실패"); | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import axios from "axios"; | ||
|
|
||
| const PRODUCT_URL = "https://panda-market-api-crud.vercel.app/products"; | ||
|
|
||
| export async function getProductList(params) { | ||
| try { | ||
| const response = await axios.get(PRODUCT_URL, { | ||
| params: params, | ||
| }); | ||
| console.log("상품 목록 조회 완료"); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.log("상품 목록 가져오다 에러 발생함"); | ||
| } | ||
| } | ||
|
|
||
| export async function getProduct(id) { | ||
| try { | ||
| const response = await axios.get(PRODUCT_URL + "/" + id); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.log("상품 상세 조회 에러"); | ||
| } | ||
| } | ||
|
|
||
| export async function createProduct(item) { | ||
| try { | ||
| const response = await axios.post(PRODUCT_URL, { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validation을 할때 400 Bad Request를 잘 활용해보시면 좋겠습니다. |
||
| name: item.name, | ||
| description: item.description, | ||
| price: item.price, | ||
| tags: item.tags, | ||
| images: item.images, | ||
| }); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.log("상품 등록 에러"); | ||
| } | ||
| } | ||
|
|
||
| export async function patchProduct(id, data) { | ||
| try { | ||
| const response = await axios.patch(PRODUCT_URL + "/" + id, data); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.log("상품 수정 에러"); | ||
| } | ||
| } | ||
|
|
||
| export async function deleteProduct(id) { | ||
| try { | ||
| const response = await axios.delete(PRODUCT_URL + "/" + id); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.log("상품 삭제 에러"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { | ||
| getArticleList, | ||
| getArticle, | ||
| createArticle, | ||
| patchArticle, | ||
| deleteArticle, | ||
| } from "./ArticleService.js"; | ||
|
|
||
| import { | ||
| getProductList, | ||
| getProduct, | ||
| createProduct, | ||
| patchProduct, | ||
| deleteProduct, | ||
| } from "./ProductService.js"; | ||
|
|
||
| async function main() { | ||
| console.log("--- 테스트를 시작합니다 ---"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test코드 jest, mocha 를 사용해서 실제로 테스트 코드를 짜보고 돌려봐도 좋을거 같아요. |
||
|
|
||
| console.log("1. 아티클 목록 가져오는 중..."); | ||
| await getArticleList({ page: 1, pageSize: 5, keyword: "" }); | ||
|
|
||
| console.log("2. 새 글 작성 중..."); | ||
| const newArt = await createArticle({ | ||
| title: "테스트 글 제목 /박가연", | ||
| content: "테스트 내용입니다.", | ||
| image: "https://panda.com/image.jpg", | ||
| }); | ||
|
|
||
| if (newArt) { | ||
| console.log("새로 만든 글 ID: " + newArt.id); | ||
| await getArticle(newArt.id); | ||
| await patchArticle(newArt.id, { title: "수정한 제목" }); | ||
| await deleteArticle(newArt.id); | ||
| console.log("아티클 테스트 끝!"); | ||
| } | ||
|
|
||
| console.log("\n3. 상품 목록 가져오는 중..."); | ||
| await getProductList({ page: 1, pageSize: 5, keyword: "" }); | ||
|
|
||
| console.log("4. 새 상품 등록 중..."); | ||
| const newProd = await createProduct({ | ||
| name: "테스트 상품 /박가연", | ||
| description: "설명입니다", | ||
| price: 5000, | ||
| tags: ["공부"], | ||
| images: ["test.jpg"], | ||
| }); | ||
|
|
||
| if (newProd) { | ||
| console.log("새로 만든 상품 ID: " + newProd.id); | ||
| await getProduct(newProd.id); | ||
| await patchProduct(newProd.id, { price: 7000 }); | ||
| await deleteProduct(newProd.id); | ||
| console.log("상품 테스트 끝!"); | ||
| } | ||
|
|
||
| console.log("\n--- 모든 테스트가 종료되었습니다 ---"); | ||
| } | ||
|
|
||
| main(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
파일로 로깅하거나, 네트워크로 로깅을하거나, 디비로 로깅을 하면 좋을거 같아요. 지금은 말고 나중에 한번 해보시면 좋을거 같아요.