From adae494d807fd729c57230da77c45c46b9eb539d Mon Sep 17 00:00:00 2001 From: juno Date: Tue, 22 Jul 2025 13:19:52 +0900 Subject: [PATCH 1/8] my mission --- .DS_Store | Bin 0 -> 6148 bytes API/.DS_Store | Bin 0 -> 6148 bytes API/ArticleService.js | 86 +++++++++++++++++++++++++++++ API/ProductService.js | 123 ++++++++++++++++++++++++++++++++++++++++++ Models/Article.js | 15 ++++++ Models/Model.js | 25 +++++++++ main.js | 38 +++++++++++++ readme.md | 16 ++++++ 8 files changed, 303 insertions(+) create mode 100644 .DS_Store create mode 100644 API/.DS_Store create mode 100644 API/ArticleService.js create mode 100644 API/ProductService.js create mode 100644 Models/Article.js create mode 100644 Models/Model.js create mode 100644 main.js create mode 100644 readme.md diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 { + console.log("GET 가사 성공", res.data) + }) + .catch(err => { + console.error("GET 기사 실패", err) + }) +} + + + +export async function getArticle() { + const url = new URL(`https://panda-market-api-crud.vercel.app/articles/`); + + axios.get(url.toString()) + + .then(res => { + console.log("GET 가사 성공", res.data) + }) + .catch(err => { + console.error("GET 기사 실패", err) + }) +} + +export async function createArticle() { + const url = new URL(`https://panda-market-api-crud.vercel.app/articles`); + + axios.post(url.toString(), { + title: "제목", + content: "내용", + image: "이미지" + }, { + headers: { + 'Content-Type': "application/json" + } + }) + .then(res => { + console.log("포스트 성공", res.data); + }) + .catch(err => { + console.error("포스트 실패", err); + }); +} + + + + + +export async function patchArticle(id, updatedData) { + const url = new URL(`https://panda-market-api-crud.vercel.app/articles/${id}`) + axios.patch(url.toString(), updatedData, { + headers:{ + 'Content-Type' : "application/json" + }, + + }) + .then(res => { + console.log("수정 완료", res.data) + }) + .catch(err =>{ + console.error("수정 실패", err) + }) +} + + +export async function deleteArticle(id) { + const url = new URL(`https://panda-market-api-crud.vercel.app/articles/${id}`) + axios.delete(url.toString()) + .then(res => { + console.log("삭제 완료", res.data) + }) + .catch(err =>{ + console.error("삭제 실패", err) + }) +} +/// axios는 fetch대신에 axios.method(url,data)형태 +// data는 생성 수정된 내용, 헤더임 diff --git a/API/ProductService.js b/API/ProductService.js new file mode 100644 index 000000000..383b3e2e4 --- /dev/null +++ b/API/ProductService.js @@ -0,0 +1,123 @@ + + +export async function getProductList(page= 1, pageSize = 10, keyword = "") { + const url = new URL(`https://panda-market-api-crud.vercel.app/product/`); + try{// - `page`, `pageSize`, `keyword` 쿼리 파라미터를 이용한 get method + url.searchParams.set("page", page); + url.searchParams.set("pageSize",pageSize); + url.searchParams.set("keyword",keyword); + + const res = await fetch(url); + + if (!res.ok) { + // 실패한 경우 (404, 500 등) + throw new Error(`HTTP error! 상태코드: ${res.status}`); + } + + const data = await res.json(); + + console.log("제품리스트 가져오기 성공", data); + return data + }catch(err){ + console.error("제품정보 가져오기 실패", err); + } + + +} + + +export async function getProduct() { + const url = new URL (`https://panda-market-api-crud.vercel.app/product/`) + try{ + + const res = await fetch(url) + if (!res.ok) { + // 실패한 경우 (404, 500 등) + throw new Error(`HTTP error! 상태코드: ${res.status}`); + } + + const data = await res.json()// 파싱 + + console.log("제품 정보 가져오기 성공", data); + return data + }catch(err){ + console.error("제품 정보 가져오기 실패",err) + } +} + + +export async function createProduct() { + const url = new URL(`https://panda-market-api-crud.vercel.app/product/`) + try{ + const res = await fetch(url,{ + method: "POST", + headers:{ + 'Content-Type' : "application/json" + }, + body:JSON.stringify({ + name : "이름", + description : "설명", + price: "가격", + tags:"태그", + images: "사진" + }) + + }) + const data = await res.json(); + console.log("포스트 성공",data) + return data + }catch(err){ + console.error("포스트 실패", err) + } +} + + +export async function patchProduct(id, updatedData) { + const url =new URL (`https://panda-market-api-crud.vercel.app/product/${id}`) + try{ + const res = await fetch(url,updatedData,{ + method:"PATCH", + headers:{ + 'Content-Type' : "application/json" + } + }) + const data= await res.json() + console.log("수정완료", data) + return data + }catch(err){ + console.error("수정 실패", err) + } +} + + +export async function deleteProduct(id) { + const url = new URL (`https://panda-market-api-crud.vercel.app/product/${id}`) + try{ + const res = await fetch(url, { + method: "DELETE" + }) + const data = await res.json() + console.log("삭제 완료", data) + return data + }catch(err){ + console.error("삭제 실패", err) + } +} + +/** + * export class Article{ + constructor(title, content, writer, likeCount, date){ + this.title = title, + this.content = content, + this.writer = writer, + this.likeCount =likeCount, + this.date = date + } + like(){ + this.likeCount++ + } + createdAt(){ + this.date = new this.date();// article 컨트 실행서 현재 시간날짜 저장 + } +} + */ \ No newline at end of file diff --git a/Models/Article.js b/Models/Article.js new file mode 100644 index 000000000..15997487f --- /dev/null +++ b/Models/Article.js @@ -0,0 +1,15 @@ +export class Article{ + constructor(title, content, writer, likeCount, date){ + this.title = title, + this.content = content, + this.writer = writer, + this.likeCount =likeCount, + this.date = date + } + like(){// method like + this.likeCount++ // article 컨트 호출시 1씩 증가 + } + createdAt(){ + this.date = new Date();// article 컨트 실행서 현재 시간날짜 저장 + } +} \ No newline at end of file diff --git a/Models/Model.js b/Models/Model.js new file mode 100644 index 000000000..b65303bac --- /dev/null +++ b/Models/Model.js @@ -0,0 +1,25 @@ +//class for Product +export class Product{ + // parameters = name, price, tags, images, favoriteCount + constructor(name, price, tags, images, favoriteCount){ + this.name = name, + this.price = price, + this.tags = [tags], // tag 배열 + this.images = [images], // 이미지 배열 + this.favoriteCount = favoriteCount + } + favorite(){ + this.favoriteCount ++ + } + // method favorite, 호출 될 경우 + 1 +} + +//class for ElectronicProduct +export class ElectronicProduct extends Product{ + constructor(name, price, tags, images, favoriteCount, manufacturer){ + // parameter = inherited from Product, add parameter manufacturer` + super(name, price, tags, images, favoriteCount) + this.manufacturer = manufacturer + } +} + diff --git a/main.js b/main.js new file mode 100644 index 000000000..386302103 --- /dev/null +++ b/main.js @@ -0,0 +1,38 @@ +import {Product, ElectronicProduct} from "./Models/Model.js" +import { Article } from "./Models/Article.js" +import {getArticleList,getArticle,createArticle,patchArticle} from "./API/ArticleService.js" +import {getProductList,getProduct, createProduct, patchProduct} from "./API/ProductService.js" + +async function run() { + const list = await getProductList(); + + // map으로 반환값 배열로 만듦 + const products = list.map(p => { + const isElectronic = p.tags.includes("전자기기"); + + // p.tags 찍고 싶으면 여기서 따로 찍기 + console.log(p.tags); + + return isElectronic + ? new ElectronicProduct( + p.name, + p.price, + p.tags, + p.images, + p.favoriteCount, + p.manufacturer + ) + : new Product( + p.name, + p.price, + p.tags, + p.images, + p.favoriteCount, + p.manufacturer + ); + }); + + console.log(products); +} + +run(); diff --git a/readme.md b/readme.md new file mode 100644 index 000000000..01244a26d --- /dev/null +++ b/readme.md @@ -0,0 +1,16 @@ +## 이용한 기술 스택: API, fetch, async/ await + +해당코드에서 Product class 와 Article class, product 생성자에서 상속 받은 electronic product class 를 만든후, 해당 각각의 인스턴스들을 지정해두었다. 그런다음 서버와 통신을 위한 여럿 메소드들을 생성하였다. Article 부분은 axios 중심으로 코드로 짰고, Product 부분은 fetch부분을 중심으로 코드를 짯다. 그런다음 비동기함수인 getProductList에서 제품들을 받아와서 배열화 하였고, 이과정에서 tags 가 전자기기 분류하였고, 나머지는 device로 분류 하였다. 그런다음 코드의 가독성을 위해서 Article 관련된 비동기 함수들을 모두 API 안 article서비스 파일내 정리 하고 export 처리를 하였고, 다른 api 관련 함수는 product 서비스로 정리 및 export 처리 하였다. 그런다음 main 에다가 전부 import를 해두었다. + + +## 어려웠던 점 +당연히 비동기 함수들을 짜는 부분이었던 것 같다. 처음에 fetch랑 axios개념이 혼동이 되서 fetch 부분에 await을 안쓴다던지, 헤더 설정, 바디 설정, 직렬화, 해당 비동기 함수들의 코드를 짜는 순서, 받은 데이터의 배열화 였다. + +## 배웠던 점 +당연히 fetch 개념과 axios개념 차이점, 해당 코드들의 코드짜는 순서 였다. + + +## 공부를 헤야 할점 +1. 해더를 왜 설정해야 하는가? + +2. 헤더 내부 From a3c0d7c436c923c2776b5b046eb2219b24f23f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=A4?= Date: Tue, 20 Jan 2026 17:30:48 +0900 Subject: [PATCH 2/8] sort --- .gitignore | 11 +++ algorithm/sort.js | 227 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 238 insertions(+) create mode 100644 .gitignore create mode 100644 algorithm/sort.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..5d7a6cbcb --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +.DS_Store + +/generated/prisma +mission8/ +mission9/ +mission6/ +mission5/ +mission4/ +mission3/ +mission2/ +typescripted/ diff --git a/algorithm/sort.js b/algorithm/sort.js new file mode 100644 index 000000000..87d997d4c --- /dev/null +++ b/algorithm/sort.js @@ -0,0 +1,227 @@ +// merge sort +/* appraoch: divide and conquer +1. [7] | [3] | [1] | [2] | [8] | [6] | [4] | [9] | [5]; + +2. [3, 7] | [1, 2] | [8] | [6] | [4] | [9] | [5] + +3. [1, 2, 3, 7] | [6, 8] | [4, 9] | [5] + +4. [1, 2, 3, 7] | [4, 6, 8, 9] | [5] + +5. [1, 2, 3, 7] | [4, 5, 6, 8, 9] => o( log n ) + +6. [1 ,2, 3, 4, 5, 6, 7, 8, 9] = o(n) + +time complexity: o(n*logn) +space complexity: o(n) +*/ + +function mergeSort(nums = []) { + let n = nums.length; + if (n <= 1) return nums; + const mid = Math.floor(n / 2); + + let left_nums = nums.slice(0, mid); + let right_nums = nums.slice(mid); + + let sorted_left = mergeSort(left_nums); + let sorted_right = mergeSort(right_nums); + + let res = []; + let idx_l = 0; + let idx_r = 0; + + while (idx_l < sorted_left.length || idx_r < sorted_right.length) { + if (idx_l === sorted_left.length) { + res.push(sorted_right[idx_r]); + idx_r++; + continue; + } + if (idx_r === sorted_right.length) { + res.push(sorted_left[idx_l]); + idx_l++; + continue; + } + if (sorted_right[idx_r] <= sorted_left[idx_l]) { + res.push(sorted_right[idx_r]); + idx_r++; + } else { + res.push(sorted_left[idx_l]); + idx_l++; + } + } + return res; +} +console.log(mergeSort([7, 3, 1, 2, 8, 6, 4, 9, 5])); + +/* insert + ↓ : idx + ⇣ : pivot + + + ↓ ⇣ + [8, 4, 7] + +if nums[pivot] < nums[idx] + temp = 4 + => [8, 8, 7] shift 8 + nums[pivot] = nums[idx] + => [4, 8, 7] idx --(insert temp) + + ↓ ⇣ + [4, 8, 7] + temp = 7 + if temp < nums[idx] + => [2, 8, 8] + + => [4, 7, 8] insert temp + + + time complexity => o(n ** 2) + space complexity => o(1) || O(n) => recursive + +*/ +function insertSort(nums) { + const n = nums.length; + for (let pIdx = 1; pIdx < n; pIdx++) { + let temp = nums[pIdx]; + let idx = pIdx - 1; + while (idx >= 0 && temp < nums[idx]) { + nums[idx + 1] = nums[idx]; + idx--; + } + nums[idx + 1] = temp; + } + return nums; +} + +console.log(insertSort([7, 3, 1, 2, 8, 6, 4, 9, 5])); + +// select sort + +/* + one of the slowest sorting algorithm => on**2 + 1. find minimum number in the array (1 to n - 1) + + 2. compare nums[0: n - 1] and nums[i: n - 1] then switch it or not + ↓ ⇣ +[3, 5, 1, 4] + ↓ ⇣ +[1, 3, 5, 4] + ↓ ⇣ +[1, 3, 5, 4] + +[1, 3, 4, 5] + +=> O n**2 timecomplexity + +=> O(n) + +*/ +function selectSort(nums) { + n = nums.length; + for (let i = 0; i < n; i++) { + minNum = nums[i]; + minIdx = i; + for (let j = i; j < n; j++) { + if (nums[j] < minNum) { + minNum = nums[j]; + minIdx = j; + } + } + [nums[i], nums[minIdx]] = [nums[minIdx], nums[i]]; + } + return nums; +} +console.log(selectSort([7, 3, 1, 2, 8, 6, 4, 9, 5])); + +// quick Sort +/* +pivot = 4 + ↓ ⇣ +[7, 3, 1, 2, 4, 6, 8, 9, 5] +[][7] + + ↓ ⇣ +[7, 3, 1, 2, 4, 6, 8, 9, 5] +[3][7] + + ↓ ⇣ +[7, 3, 1, 2, 4, 6, 8, 9, 5] +[3, 1][7] + + ↓ ⇣ +[7, 3, 1, 2, 4, 6, 8, 9, 5] +[3, 1, 2 ][7] + + ⇣ ↓ +[7, 3, 1, 2, 4, 6, 8, 9, 5] +[3, 1, 2 ][7, 6] + ⇣ ↓ +[7, 3, 1, 2, 4, 6, 8, 9, 5] +[3, 1, 2][7, 6, 8] + ⇣ ↓ +[7, 3, 1, 2, 4, 6, 8, 9, 5] +[3, 1, 2][7, 6, 8, 9] + ⇣ ↓ +[7, 3, 1, 2, 4, 6, 8, 9, 5] +[3, 1, 2] [7, 6, 8, 9, 5] + +pivot 1, 8 + ↓ ⇣ ↓ ⇣ +[3, 1, 2] [7, 6, 8, 9, 5] +[][3] [7][] + ↓ ⇣ ↓ ⇣ +[3, 1, 2] [7, 6, 8, 9, 5] +[2] [3] [7, 6][] + ⇣ ↓ + [7, 6, 8, 9, 5] + [7, 6] [9] + ⇣ ↓ + [7, 6, 8, 9, 5] + [7, 6] [9] + ⇣ ↓ + [7, 6, 8, 9, 5] + [7, 6, 5][9] + + pivot = 6 + ↓ ⇣ + [7, 6, 5] + [][7] + ⇣ ↓ + [7, 6, 5] + [5] [7] + +=> buttom up left + pivot + right + +worst time complexity: o(n**2) +fastest time complexity : n log n + +space complexity: o(n) +*/ +function quickSort(nums = []) { + let n = nums.length; + let mid = Math.floor(n / 2); + + let pivot = nums[mid]; + let leftNums = []; + let rightNums = []; + + leftIdx = 0; + rightIdx = 0; + if (nums.length <= 1) { + return nums; + } + for (let i = 0; i < n; i++) { + if (i === mid) continue; + if (nums[i] < pivot) { + leftNums.push(nums[i]); + } else { + rightNums.push(nums[i]); + } + } + const l_sorted = quickSort(leftNums); + const r_sorted = quickSort(rightNums); + return [...l_sorted, pivot, ...r_sorted]; +} +console.log(quickSort([7, 3, 1, 2, 8, 6, 4, 9, 5])); From 248f5ca3f0931f70fd7314d2bc804e9d05639a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=A4?= Date: Tue, 20 Jan 2026 17:51:22 +0900 Subject: [PATCH 3/8] git igonot: --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5d7a6cbcb..27806544e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store /generated/prisma +API mission8/ mission9/ mission6/ From a05e153762d6b420476923fdd9e5e8ea7726449a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=A4?= Date: Tue, 20 Jan 2026 17:53:33 +0900 Subject: [PATCH 4/8] remove: unused pr --- API/.DS_Store | Bin 6148 -> 0 bytes API/ArticleService.js | 86 ----------------------------- API/ProductService.js | 123 ------------------------------------------ 3 files changed, 209 deletions(-) delete mode 100644 API/.DS_Store delete mode 100644 API/ArticleService.js delete mode 100644 API/ProductService.js diff --git a/API/.DS_Store b/API/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 { - console.log("GET 가사 성공", res.data) - }) - .catch(err => { - console.error("GET 기사 실패", err) - }) -} - - - -export async function getArticle() { - const url = new URL(`https://panda-market-api-crud.vercel.app/articles/`); - - axios.get(url.toString()) - - .then(res => { - console.log("GET 가사 성공", res.data) - }) - .catch(err => { - console.error("GET 기사 실패", err) - }) -} - -export async function createArticle() { - const url = new URL(`https://panda-market-api-crud.vercel.app/articles`); - - axios.post(url.toString(), { - title: "제목", - content: "내용", - image: "이미지" - }, { - headers: { - 'Content-Type': "application/json" - } - }) - .then(res => { - console.log("포스트 성공", res.data); - }) - .catch(err => { - console.error("포스트 실패", err); - }); -} - - - - - -export async function patchArticle(id, updatedData) { - const url = new URL(`https://panda-market-api-crud.vercel.app/articles/${id}`) - axios.patch(url.toString(), updatedData, { - headers:{ - 'Content-Type' : "application/json" - }, - - }) - .then(res => { - console.log("수정 완료", res.data) - }) - .catch(err =>{ - console.error("수정 실패", err) - }) -} - - -export async function deleteArticle(id) { - const url = new URL(`https://panda-market-api-crud.vercel.app/articles/${id}`) - axios.delete(url.toString()) - .then(res => { - console.log("삭제 완료", res.data) - }) - .catch(err =>{ - console.error("삭제 실패", err) - }) -} -/// axios는 fetch대신에 axios.method(url,data)형태 -// data는 생성 수정된 내용, 헤더임 diff --git a/API/ProductService.js b/API/ProductService.js deleted file mode 100644 index 383b3e2e4..000000000 --- a/API/ProductService.js +++ /dev/null @@ -1,123 +0,0 @@ - - -export async function getProductList(page= 1, pageSize = 10, keyword = "") { - const url = new URL(`https://panda-market-api-crud.vercel.app/product/`); - try{// - `page`, `pageSize`, `keyword` 쿼리 파라미터를 이용한 get method - url.searchParams.set("page", page); - url.searchParams.set("pageSize",pageSize); - url.searchParams.set("keyword",keyword); - - const res = await fetch(url); - - if (!res.ok) { - // 실패한 경우 (404, 500 등) - throw new Error(`HTTP error! 상태코드: ${res.status}`); - } - - const data = await res.json(); - - console.log("제품리스트 가져오기 성공", data); - return data - }catch(err){ - console.error("제품정보 가져오기 실패", err); - } - - -} - - -export async function getProduct() { - const url = new URL (`https://panda-market-api-crud.vercel.app/product/`) - try{ - - const res = await fetch(url) - if (!res.ok) { - // 실패한 경우 (404, 500 등) - throw new Error(`HTTP error! 상태코드: ${res.status}`); - } - - const data = await res.json()// 파싱 - - console.log("제품 정보 가져오기 성공", data); - return data - }catch(err){ - console.error("제품 정보 가져오기 실패",err) - } -} - - -export async function createProduct() { - const url = new URL(`https://panda-market-api-crud.vercel.app/product/`) - try{ - const res = await fetch(url,{ - method: "POST", - headers:{ - 'Content-Type' : "application/json" - }, - body:JSON.stringify({ - name : "이름", - description : "설명", - price: "가격", - tags:"태그", - images: "사진" - }) - - }) - const data = await res.json(); - console.log("포스트 성공",data) - return data - }catch(err){ - console.error("포스트 실패", err) - } -} - - -export async function patchProduct(id, updatedData) { - const url =new URL (`https://panda-market-api-crud.vercel.app/product/${id}`) - try{ - const res = await fetch(url,updatedData,{ - method:"PATCH", - headers:{ - 'Content-Type' : "application/json" - } - }) - const data= await res.json() - console.log("수정완료", data) - return data - }catch(err){ - console.error("수정 실패", err) - } -} - - -export async function deleteProduct(id) { - const url = new URL (`https://panda-market-api-crud.vercel.app/product/${id}`) - try{ - const res = await fetch(url, { - method: "DELETE" - }) - const data = await res.json() - console.log("삭제 완료", data) - return data - }catch(err){ - console.error("삭제 실패", err) - } -} - -/** - * export class Article{ - constructor(title, content, writer, likeCount, date){ - this.title = title, - this.content = content, - this.writer = writer, - this.likeCount =likeCount, - this.date = date - } - like(){ - this.likeCount++ - } - createdAt(){ - this.date = new this.date();// article 컨트 실행서 현재 시간날짜 저장 - } -} - */ \ No newline at end of file From f8bd2e0c2aa1aa9c5a3d3e8fac0a36bb0a6dcc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=A4?= Date: Tue, 20 Jan 2026 17:55:23 +0900 Subject: [PATCH 5/8] remove: models --- .gitignore | 1 + Models/Article.js | 15 --------------- Models/Model.js | 25 ------------------------- 3 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 Models/Article.js delete mode 100644 Models/Model.js diff --git a/.gitignore b/.gitignore index 27806544e..df0194d47 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /generated/prisma API +Models mission8/ mission9/ mission6/ diff --git a/Models/Article.js b/Models/Article.js deleted file mode 100644 index 15997487f..000000000 --- a/Models/Article.js +++ /dev/null @@ -1,15 +0,0 @@ -export class Article{ - constructor(title, content, writer, likeCount, date){ - this.title = title, - this.content = content, - this.writer = writer, - this.likeCount =likeCount, - this.date = date - } - like(){// method like - this.likeCount++ // article 컨트 호출시 1씩 증가 - } - createdAt(){ - this.date = new Date();// article 컨트 실행서 현재 시간날짜 저장 - } -} \ No newline at end of file diff --git a/Models/Model.js b/Models/Model.js deleted file mode 100644 index b65303bac..000000000 --- a/Models/Model.js +++ /dev/null @@ -1,25 +0,0 @@ -//class for Product -export class Product{ - // parameters = name, price, tags, images, favoriteCount - constructor(name, price, tags, images, favoriteCount){ - this.name = name, - this.price = price, - this.tags = [tags], // tag 배열 - this.images = [images], // 이미지 배열 - this.favoriteCount = favoriteCount - } - favorite(){ - this.favoriteCount ++ - } - // method favorite, 호출 될 경우 + 1 -} - -//class for ElectronicProduct -export class ElectronicProduct extends Product{ - constructor(name, price, tags, images, favoriteCount, manufacturer){ - // parameter = inherited from Product, add parameter manufacturer` - super(name, price, tags, images, favoriteCount) - this.manufacturer = manufacturer - } -} - From b2bea7406c4c5bc9457af20bd3d0656e8ef1da34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=A4?= Date: Tue, 20 Jan 2026 17:57:04 +0900 Subject: [PATCH 6/8] emty readme --- readme.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/readme.md b/readme.md index 01244a26d..e69de29bb 100644 --- a/readme.md +++ b/readme.md @@ -1,16 +0,0 @@ -## 이용한 기술 스택: API, fetch, async/ await - -해당코드에서 Product class 와 Article class, product 생성자에서 상속 받은 electronic product class 를 만든후, 해당 각각의 인스턴스들을 지정해두었다. 그런다음 서버와 통신을 위한 여럿 메소드들을 생성하였다. Article 부분은 axios 중심으로 코드로 짰고, Product 부분은 fetch부분을 중심으로 코드를 짯다. 그런다음 비동기함수인 getProductList에서 제품들을 받아와서 배열화 하였고, 이과정에서 tags 가 전자기기 분류하였고, 나머지는 device로 분류 하였다. 그런다음 코드의 가독성을 위해서 Article 관련된 비동기 함수들을 모두 API 안 article서비스 파일내 정리 하고 export 처리를 하였고, 다른 api 관련 함수는 product 서비스로 정리 및 export 처리 하였다. 그런다음 main 에다가 전부 import를 해두었다. - - -## 어려웠던 점 -당연히 비동기 함수들을 짜는 부분이었던 것 같다. 처음에 fetch랑 axios개념이 혼동이 되서 fetch 부분에 await을 안쓴다던지, 헤더 설정, 바디 설정, 직렬화, 해당 비동기 함수들의 코드를 짜는 순서, 받은 데이터의 배열화 였다. - -## 배웠던 점 -당연히 fetch 개념과 axios개념 차이점, 해당 코드들의 코드짜는 순서 였다. - - -## 공부를 헤야 할점 -1. 해더를 왜 설정해야 하는가? - -2. 헤더 내부 From d0700c3d3e6b0b0890aeb937a1b1384b706b5c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=A4?= Date: Tue, 20 Jan 2026 17:57:51 +0900 Subject: [PATCH 7/8] delete main.js from pr --- main.js | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 main.js diff --git a/main.js b/main.js deleted file mode 100644 index 386302103..000000000 --- a/main.js +++ /dev/null @@ -1,38 +0,0 @@ -import {Product, ElectronicProduct} from "./Models/Model.js" -import { Article } from "./Models/Article.js" -import {getArticleList,getArticle,createArticle,patchArticle} from "./API/ArticleService.js" -import {getProductList,getProduct, createProduct, patchProduct} from "./API/ProductService.js" - -async function run() { - const list = await getProductList(); - - // map으로 반환값 배열로 만듦 - const products = list.map(p => { - const isElectronic = p.tags.includes("전자기기"); - - // p.tags 찍고 싶으면 여기서 따로 찍기 - console.log(p.tags); - - return isElectronic - ? new ElectronicProduct( - p.name, - p.price, - p.tags, - p.images, - p.favoriteCount, - p.manufacturer - ) - : new Product( - p.name, - p.price, - p.tags, - p.images, - p.favoriteCount, - p.manufacturer - ); - }); - - console.log(products); -} - -run(); From fdb0a4c3343936da736760fb191f777d01146858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=A4?= Date: Thu, 29 Jan 2026 16:08:45 +0900 Subject: [PATCH 8/8] feat: bst 1. find node 2. insert node 3. delete --- algorithm/BinarySearchTree.ts | 109 ++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 algorithm/BinarySearchTree.ts diff --git a/algorithm/BinarySearchTree.ts b/algorithm/BinarySearchTree.ts new file mode 100644 index 000000000..c036d8cc6 --- /dev/null +++ b/algorithm/BinarySearchTree.ts @@ -0,0 +1,109 @@ +type BSTNode = { + val: T; + left: BSTNode | null; + right: BSTNode | null; +}; + +class BinarySearchTree { + private root: BSTNode | null = null; + constructor(private compare: (a: T, b: T) => number) {} + insert(value: T): void { + if (!this.root) { + this.root = { val: value, left: null, right: null }; + return; + } + let current: BSTNode | null = this.root; + let parent: BSTNode | null = null; + while (current !== null) { + parent = current; + if (value < current.val) { + current = current.left; + } else { + current = current.right; + } + } + if (value < parent!.val) { + parent!.left = { val: value, left: null, right: null }; + } else { + parent!.right = { val: value, left: null, right: null }; + } + } + find(targetValue: T) { + if (!this.root) { + return; + } + let crnt = this.root; + while (crnt) { + const comparator = this.compare(targetValue, crnt.val); + if (comparator === 0) return crnt.val; + else if (comparator < 0) crnt = crnt.left!; + else crnt = crnt.right!; + } + return null; + } + remove(target: T) { + if (!this.root) return null; + + let parent: BSTNode | null = null; + let crnt: BSTNode | null = this.root; + let leftChild: Boolean = false; + while (crnt) { + const cmp = this.compare(target, crnt.val); + console.log(cmp); + if (cmp === 0) break; + parent = crnt; + if (cmp < 0) { + leftChild = true; + crnt = crnt.left; + } else { + leftChild = false; + crnt = crnt.right; + } + } + if (!crnt) return null; + if (!crnt.left && !crnt.right) { + if (crnt === this.root) { + this.root = null; + } else if (leftChild) { + parent!.left = null; + } else { + parent!.right = null; + } + } + if (!crnt.left || !crnt.right) { + const child = crnt.left ?? crnt.right; + this.root === crnt + ? (this.root = child) + : leftChild + ? (parent!.left = child) + : (parent!.right = child); + } else { + let succParent: BSTNode | null = crnt; + let succ: BSTNode | null = crnt.right; + + while (succ && succ.left) { + succParent = succ; + succ = succ.left; + } + crnt.val = succ!.val; + while (succ) { + if (!succ.left && !succ.right) { + if (succParent.left === succ) succParent.left = null; + else succParent.right = null; + break; + } else if (succ.right) { + if (succParent!.left === succ) succParent!.left = succ.right; + else succParent!.right = succ.right; + break; + } + } + } + } +} +const tree = new BinarySearchTree((a, b) => a - b); +tree.insert(8); +tree.insert(10); +tree.insert(9); +tree.insert(4); +tree.remove(4); +console.dir(tree, { depth: null });