Skip to content
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

[이태빈] Sprint5 #130

Merged
Show file tree
Hide file tree
Changes from 6 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
21 changes: 11 additions & 10 deletions .github/pull-request-template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
## 요구사항
# 요구사항

### 기본
설명

- [x]
- []
- []
## 기본 요구사항

### 심화
- [ ]
- [ ]
- [ ]

- [x]
- []
## 심화 요구사항

- [ ]
- [ ]

## 주요 변경사항

Expand All @@ -18,10 +20,9 @@

## 스크린샷

![image](이미지url)
![이미지 설명](이미지url)

## 멘토에게

-
-
- 셀프 코드 리뷰를 통해 질문 이어가겠습니다.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
63 changes: 63 additions & 0 deletions API/article_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// axios | .then | .catch 이용하기
import axios from "axios"

export {
getArticleList,
getArticle,
createArticle,
patchArticle,
deleteArticle
}

const baseURL = 'https://panda-market-api-crud.vercel.app/articles'
const instance = axios.create({ baseURL })

// 게시글 목록 조회 : GET
// default = page=1&pageSize=10&orderBy=recent
/* query string(optional) :
page 페이지 번호(integer),
pageSize 페이지 당 게시글 수(integer),
orderBy 정렬 기준(string : recent, like),
keyword 검색 키워드(string) */
const getArticleList = params => {
return instance.get('/', { params })
.then(res => res.data)
.catch(e => console.log(e.message))
}


// 게시글 상세 조회 : GET
// path(required) : id(integer)
const getArticle = id => {
return instance.get(`/${id}`)
.then(res => res.data)
.catch(e => console.log(e.message))
}


// 게시글 등록 : POST
// body(required) : title(string), content(string), image(string)
const createArticle = body => {
return instance.post('/', body)
.then(res => res.data)
.catch(e => console.log(e.message))
}


// 게시글 수정 : PATCH
/* path(required) : id(integer)
body(required) : title(string), content(string), image(string)*/
const patchArticle = (id, body) => {
return instance.patch(`/${id}`, body)
.then(res => res.data)
.catch(e => console.log(e.message))
}


// 게시글 삭제 : DELETE
// path(required) : id(integer)
const deleteArticle = id => {
return instance.delete(`/${id}`)
.then(res => res.data)
.catch(e => console.log(e.message))
}
75 changes: 75 additions & 0 deletions API/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { getArticleList, getArticle, createArticle, patchArticle, deleteArticle } from './article_service.js'
import { getProductList, getProduct, createProduct, patchProduct, deleteProduct } from './product_service.js'

// article-data
const articleQuery = {
page: 1,
pageSize: 10,
orderBy: 'recent',
keyword: ''
}

const articlePostBody = {
title: '삼성 갤럭시 S25 Ultra 구매후기',
content: '디자인이 너무 깔끔하네요!',
image: 'https://images.samsung.com/sec/smartphones/galaxy-s25-ultra/images/galaxy-s25-ultra-features-kv.jpg?imbypass=true'
}

const articlePatchBody = {
title: '(수정)NVIDIA RTX 5090 구매후기',
content: '비싼 가격 값 하는 것 같아요!',
image: 'https://www.nvidia.com/content/dam/en-zz/Solutions/geforce/graphic-cards/50-series/rtx-5090/geforce-rtx-5090-learn-more-og-1200x630.jpg'
}

// Article API 함수 테스트
await getArticleList(articleQuery)

await getArticle(500)

await createArticle(articlePostBody)

await patchArticle(500, articlePatchBody)

await deleteArticle(300)


// product-data
const productQuery = {
page: 1,
pageSize: 10,
orderBy: 'recent',
keyword: ''
}

const productPostBody = {
name: 'Samsung galaxy S25 Ultra',
description: '2025년 삼성의 새로운 플래그십 스마트폰 출시',
price: 1698400,
tags: [ '스마트폰', '삼성', 'S25' ],
images: [
'https://images.samsung.com/kdp/goods/2025/01/15/cf939ac6-e80c-4af1-85cc-a0805d345aed.png?$944_550_PNG$',
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR6j0t0s-siCL2rl7qNpJFY4XT5EEEgn6Fx1Q&s'
]
}

const productPatchBody = {
name: 'NVIDIA RTX 5090',
description: 'NVIDIA의 새로운 야심작, RTX 5090',
price: 2900000,
tags: [ 'Graphic card', 'NVIDIA', '5090' ],
images: [
'https://www.nvidia.com/content/dam/en-zz/Solutions/geforce/graphic-cards/50-series/rtx-5090/geforce-rtx-5090-learn-more-og-1200x630.jpg',
'https://imageio.forbes.com/specials-images/imageserve/677edeef69d0ab19fe73be44/Nvidia-s-RTX-5080/960x0.jpg?height=399&width=711&fit=bounds'
]
}

// product API 함수 테스트
await getProductList(productQuery)

await getProduct(515)

await createProduct(productPostBody)

await patchProduct(517, productPatchBody)

await deleteProduct(514)
85 changes: 85 additions & 0 deletions API/product_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// axios | async, await | try, catch 이용하기
import axios from 'axios'

export {
getProductList,
getProduct,
createProduct,
patchProduct,
deleteProduct
}

const baseURL = 'https://panda-market-api-crud.vercel.app/products'
const instance = axios.create({ baseURL })

const handleError = async func => {
try {
return await func()
} catch (e) {
if (e.response) {
console.log(e.response.status)
console.log(e.response.data.message)
} else {
console.log('request failed')
}
}
}

// 상품 목록 조회 : GET
// default = page=1&pageSize=10&orderBy=recent
/* query string(optional) :
page 페이지 번호(integer),
pageSize 페이지 당 게시글 수(integer),
orderBy 정렬 기준(string : recent, favorite),
keyword 검색 키워드(string) */
const getProductList = params => {
return handleError(async () => {
const res = await instance.get('/', { params })
return res.data
})
}


// 상품 상세 조회 : GET
// path(required) : id(integer)
const getProduct = id => {
return handleError(async () => {
const res = await instance.get(`/${id}`)
return res.data
})
}


// 상품 등록 : POST
/* body(required) :
name(string),
description(string),
price(integer),
tags[ (string) ],
images[ (string) ] */
const createProduct = async body => {
const res = await instance.post('/', body)
return res.data
}


// 상품 수정 : PATCH
// path(required) : id(integer)
/* body(required) :
name(string),
description(string),
price(integer),
tags[ (string) ],
images[ (string) ] */
const patchProduct = async (id, body) => {
const res = await instance.patch(`/${id}`, body)
return res.data
}


// 상품 삭제 : DELETE
// path(required) : id(integer)
const deleteProduct = async id => {
const res = await instance.delete(`${id}`)
return res.data
}
Loading