diff --git a/4-sprint-mission b/4-sprint-mission new file mode 160000 index 00000000..9177be2f --- /dev/null +++ b/4-sprint-mission @@ -0,0 +1 @@ +Subproject commit 9177be2f6be2bfeb878c1a58c5e008cfb24414dd diff --git a/ArticleService.js b/ArticleService.js new file mode 100644 index 00000000..80c477a4 --- /dev/null +++ b/ArticleService.js @@ -0,0 +1,59 @@ +import axios from 'axios'; +const instance = axios.create({ + baseURL: 'https://panda-market-api-crud.vercel.app' +}); +export class Article { + #likeCount; + + constructor(title, content, writer, likeCount = 0, createdAt = new Date()) { + this.title = title; + this.writer = writer; + this.#likeCount = likeCount; + this.content = content; + this.createdAt = createdAt; + } + getLikeCount(){ + return this.#likeCount; + } + + like() { + this.#likeCount += 1 + return this.likeCount; + } +} + +export async function getArticlelist (params ={}){ + const {page, pageSize, keyword} = params; + const res = instance.get(`/articles`,{params : {page, pageSize, keyword}}) + .then((value)=>{return value.data }) + .catch (error =>{ console.log('오류 발생!')}); + return res; +} + +export async function getArticle(id){ + const res = instance.get(`/articles/${id}`) + .then (response => {return response.data}) + .catch (error => {console.log('오류발생!');}); + return res; +} + +export async function createArticle(articleBody){ + const res = instance. post(`/articles`,articleBody) + .then (response => {return response.data}) + .catch (error => {console.log('오류발생')}); + return res; +} + +export async function patchArticle (id, ArticleListType){ + const res = instance. patch(`/articles/${id}`,ArticleListType) + .then (response => {return response.data}) + .catch(error => {console.log ('오류발생')}); + return res; +} + +export async function deleteArticle(id){ + const res = instance. delete('/articles/${id}') + .then (response => {return response.data}) + .catch(error => {console.log ('오류발생!');}); + return res; +} \ No newline at end of file diff --git a/ProductService.js b/ProductService.js new file mode 100644 index 00000000..88ac3e6b --- /dev/null +++ b/ProductService.js @@ -0,0 +1,97 @@ +import axios from 'axios'; +const instance = axios.create({ + baseURL: 'https://panda-market-api-crud.vercel.app' +}); + +export class Product { + #price; + #favoriteCount; + + constructor(id, name, description, price, tags, images, favoriteCount = 0, createdAt, updatedAt) { + this.id = id; + this.name = name; + this.description = description; + this.#price = price; + this.tags = tags; + this.images = images; + this.#favoriteCount = favoriteCount; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + getPrice (){ + return this.#price; + } + + getFavoriteCount (){ + return this.#favoriteCount; + } + favorite() { + return this.#favoriteCount += 1; + } +} + +export class ElectronicProduct extends Product { + constructor(id, name, description, price, manufacturer, tags, images, createdAt, updatedAt) { + super(id, name, description, price, tags, images, createdAt, updatedAt); + this.manufacturer = manufacturer; + } +} + + + +export async function getProductlist(params = {}){ + try{ + const {page, pageSize, keyword} = params; + const response = await instance.get('/products', {params: {page, pageSize, keyword}}); + return response.data; + } catch (error){ + if(error){ + console.error('오류발생!') + throw error; + } + } +} + +export async function getProduct(id){ + try{ + const response = await instance.get('/products/${id}') + return response. data; + } catch (error){ + console.error (`오류 발생`); + throw error; + } +} + +export async function createProduct(){ + try{ + const {name, description, price, tags, images} = productListInfo; + const response = await instance.post('/products', productListInfo); + return response.data; + } catch (error){ + console.error('오류 발생!') + throw error; + } +} + + +export async function patchProduct(id, productListInfo){ + try{ + const response = await instance.patch('/products/${id}', productListInfo); + return response.data; + } catch (error){ + console.error('오류 발생!'); + throw error; + } +} + + +export async function deleteProduct(id){ + try{ + const response = await instance.delete('/products/${id}'); + return response.data; + } catch (error){ + console.log('오류발생!'); + throw error; + } +} + diff --git a/README.md b/README.md new file mode 100644 index 00000000..65e79d4a --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +## Sprintmission 2 +### API 리퀘스트 보내는 코드 구현 +### Git과 Github 활용하기 diff --git a/main.mjs b/main.mjs new file mode 100644 index 00000000..a20d20c9 --- /dev/null +++ b/main.mjs @@ -0,0 +1,22 @@ +import axios from 'axios'; +import * as Productfile from './ProductService.js' +import * as Articlefile from './ArticleService.js' + + +function checkData() { + const products = []; + const responseData = Productfile.getProductlist(); + const objs= responseData.list; + objs.forEach((data)=>{ + if(data.tags.includes('전자제품')){ + const isElectronicProduct = new EletronicProduct(id, name, description, price, manufacturer, tag, images, createdAt, updatedAt); + products.push(isElectronicProduct); + } else{ + const isNotElectioncProduct = new Product (id, name, description, price, tag, images, createdAt, updatedAt); + products.push(isNotElectioncProduct) + } + } +)} + + +