-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from xcjnzvc/react-강수정-5
[강수정] sprint 5
- Loading branch information
Showing
64 changed files
with
20,922 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"liveServer.settings.port": 5501 | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export function responseInterceptor (response) { | ||
if(response.status === 200 || response.status === 201 || response.status === 204) { | ||
console.log('성공') | ||
return response.json().then((res) => ({ isSuccess : true, status : response.status, data:res })); | ||
} else { | ||
console.log('실패') | ||
return response.json().then((res) => ({ isSuccess : false, status : response.status, data:res })); | ||
} | ||
|
||
// return response.json().then((res) => ({ isSuccess : | ||
// response.status === 200 || response.status === 201 || response.status === 204 | ||
// , status : response.status, data:res })); | ||
} | ||
|
||
export function handleError (error) { | ||
console.log(error) | ||
throw errors | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
export const apiUrl = "https://sprint-mission-api.vercel.app" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ArticleService } from "./services/ArticleService.js"; | ||
import { ProductService } from "./services/ProductService.js"; | ||
|
||
|
||
|
||
|
||
//articleservice | ||
const getArticleList = await ArticleService.getArticleList(1, 10, "aa") | ||
console.log(getArticleList) | ||
|
||
const getArticle = await ArticleService.getArticle(2) | ||
console.log(getArticle) | ||
|
||
const createArticle = await ArticleService.createArticle('제목','내용2','sdf.jpg') | ||
console.log(createArticle) | ||
|
||
const patchArticle = await ArticleService.patchArticle('aaa','제목','내용2','sdf.jpg') | ||
console.log(patchArticle) | ||
|
||
const deleteArticle = await ArticleService.deleteArticle(764) | ||
console.log(deleteArticle) | ||
|
||
|
||
|
||
|
||
//productservice | ||
const getProductList = await ProductService.getProductList(2, 2, "수정") | ||
console.log(getProductList) | ||
|
||
const getProduct = await ProductService.getProduct(2) | ||
console.log(getProduct) | ||
|
||
const createProduct = await ProductService.createProduct('수정','dd',123,'a',['asf'],['sef.jpg']) | ||
console.log(createProduct) | ||
|
||
const patchProduct = await ProductService.patchProduct(80, '수정', 'fff', '333', 'aaa', ['ssf'],['asf.jpg']) | ||
console.log(patchProduct) | ||
|
||
const deleteProduct = await ProductService.deleteProduct(370) | ||
console.log(deleteProduct) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type" : "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { responseInterceptor, handleError } from "../common/common.js"; | ||
import { apiUrl } from "../common/constant.js"; | ||
|
||
/** | ||
* 게시글 목록 조회 | ||
* | ||
* @param page 페이지 | ||
* @param pageSize 페이지당 몇개 올 지 | ||
* @param keyword 키워드 | ||
*/ | ||
function getArticleList(page, pageSize, keyword){ | ||
return fetch(`${apiUrl}/articles?page=${page}&pageSize=${pageSize}&keyword=${keyword}`) | ||
.then((response) => responseInterceptor(response)) | ||
.catch((error) => handleError(error)) | ||
} | ||
|
||
async function getArticle(id){ | ||
|
||
return fetch(`https://sprint-mission-api.vercel.app/articles/${id}`, { | ||
method : 'GET', | ||
headers : { | ||
'Content-Type' : 'application/json', | ||
} | ||
}) | ||
.then((response) => responseInterceptor(response)) | ||
.catch((error) => handleError(error)) | ||
|
||
// .then(function(response){ | ||
// return responseInterceptor(response) | ||
// }) | ||
|
||
|
||
} | ||
|
||
/** | ||
* 게시글생성 | ||
* | ||
* @param title 제목 | ||
* @param content 내용 | ||
* @param img 이미지 링크 | ||
*/ | ||
function createArticle(title, content, img) { | ||
|
||
if (!title || !content || !img) return false; | ||
const requestBody = { | ||
title : title, | ||
content : content, | ||
image : img | ||
} | ||
return fetch('https://sprint-mission-api.vercel.app/articles', { | ||
method : 'POST', | ||
body : JSON.stringify(requestBody), | ||
headers : { | ||
'Content-Type' : 'application/json', | ||
} | ||
}) | ||
.then((response) => responseInterceptor(response)) | ||
.catch((error) => handleError(error)) | ||
} | ||
|
||
function patchArticle(id, title, content, img) { | ||
const requestBody = { | ||
title : title, | ||
content : content, | ||
image : img | ||
} | ||
|
||
return fetch(`https://sprint-mission-api.vercel.app/articles/${id}`, { | ||
method : 'PATCH', | ||
body : JSON.stringify(requestBody), | ||
headers : { | ||
'Content-Type' : 'application/json', | ||
} | ||
}) | ||
.then((response) => responseInterceptor(response)) | ||
.catch((error) => handleError(error)) | ||
|
||
} | ||
|
||
function deleteArticle(id) { | ||
return fetch(`https://sprint-mission-api.vercel.app/articles/${id}`, { | ||
method : 'DELETE', | ||
headers : { | ||
'Content-Type' : 'application/json', | ||
}, | ||
}) | ||
.then((response) => responseInterceptor(response)) | ||
.catch((error) => handleError(error)) | ||
} | ||
|
||
export const ArticleService = { | ||
getArticleList, | ||
getArticle, | ||
createArticle, | ||
patchArticle, | ||
deleteArticle | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// import { responseInterceptor, handleError } from "../common/common.js"; | ||
import { apiUrl } from "../common/constant.js"; | ||
|
||
|
||
|
||
async function getProductList(page, pageSize, keyword){ | ||
try { | ||
|
||
const requestBody = { | ||
page : page, | ||
pageSize : pageSize, | ||
keyword : keyword | ||
} | ||
|
||
const response = await fetch(`${apiUrl}/products?page=${page}&pageSize=${pageSize}&keyword=${keyword}`) | ||
const data = await response.json() | ||
|
||
if(response.status === 200 || response.status === 201 || response.status === 204) { | ||
console.log('성공') | ||
} | ||
return { | ||
isSuccess : true, | ||
status : response.status, | ||
data : data | ||
} | ||
} catch(err) { | ||
console.log('이게 에러임', err) | ||
return "err catch" | ||
} | ||
} | ||
|
||
async function getProduct(id){ | ||
try{ | ||
const response = await fetch(`${apiUrl}/products/${id}`) | ||
|
||
const data = await response.json() | ||
return { | ||
isSuccess : true, | ||
status : response.status, | ||
data : data | ||
} | ||
} catch(err) { | ||
console.log('이게 에러임', err) | ||
return "err catch" | ||
} | ||
} | ||
|
||
async function createProduct(name, description, price, manufacturer, tags, images){ | ||
try{ | ||
const requestBody = { | ||
name : name, | ||
description : description, | ||
price : price, | ||
manufacturer : manufacturer, | ||
tags: tags, | ||
images: images | ||
} | ||
|
||
const response = await fetch(`${apiUrl}/products`, { | ||
method : 'POST', | ||
body : JSON.stringify(requestBody), | ||
headers : { | ||
'Content-Type' : 'application/json', | ||
} | ||
}) | ||
|
||
const data = await response.json() | ||
return { | ||
isSuccess : true, | ||
status : response.status, | ||
data : data | ||
} | ||
} catch(err) { | ||
console.log('이게 에러임', err) | ||
return "err catch" | ||
} | ||
} | ||
|
||
async function patchProduct(id, name, description, price, tags, images){ | ||
try{ | ||
const requestBody = { | ||
"name": name, | ||
"description": description, | ||
"price": price, | ||
"tags": tags, | ||
"images": images | ||
} | ||
|
||
const response = await fetch(`${apiUrl}/products/${id}`,{ | ||
method : 'PATCH', | ||
body : JSON.stringify(requestBody), | ||
headers : { | ||
'Content-Type' : 'application/json', | ||
} | ||
}) | ||
const data = await response.json() | ||
return { | ||
isSuccess : true, | ||
status : response.status, | ||
data : data | ||
} | ||
} catch(err) { | ||
console.log('이게 에러임', err) | ||
return "err catch" | ||
} | ||
} | ||
|
||
async function deleteProduct(id){ | ||
const response = await fetch(`${apiUrl}/products/${id}`, { | ||
method : 'DELETE', | ||
headers : { | ||
'Content-Type' : 'application/json', | ||
} | ||
}) | ||
if (response.status === 204) { | ||
return { | ||
isSuccess : true, | ||
status : response.status, | ||
data : null | ||
} | ||
} else { | ||
return { | ||
isSuccess : false, | ||
status : response.status, | ||
data : null | ||
} | ||
} | ||
} | ||
|
||
export const ProductService = { | ||
getProductList, | ||
getProduct, | ||
createProduct, | ||
patchProduct, | ||
deleteProduct | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.