์ฃผ์ ์์
- api ๊ฐ๋ฐ(์งํ์ค)
- get ์นด๋ ๋ถ๋ฌ์ค๊ธฐ(์๋ฃ)
- post ์นด๋ ์ถ๊ฐํ๊ธฐ(์๋ฃ)
- get ํ์คํ ๋ฆฌ ๋ถ๋ฌ์ค๊ธฐ(์๋ฃ)
- delete ์นด๋ ํ์คํ ๋ฆฌ ์ ์ฒด ์ญ์ (๋ฆฌ๋ ๋๋ง ๋ก์ง ์งํ์ค)
- MVC ํจํด ํ๋ก์ ํธ ์ ์ฉ โ 2024-08-29
ํ์ต ํค์๋
- sql(ํ์ต ์งํ์ค) โ 2024-08-29
- reverse engineering โ 2024-08-29
- ํธ๋์ญ์ โ 2024-08-29
- ๋น์ฆ๋์ค ๋ก์ง โ 2024-08-29
๊ณ ๋ฏผ ๋ฐ ํด๊ฒฐ๊ณผ์
CardListModel โ columnListModel์์์ column ์ถ์ถ
function CardListModel(cardsList) {
this.cards = modelProcessing(cardsList);
function modelProcessing(cardsList) {
cardsList.map((card) => new CardModel(card));
}
}
function CardModel(card) {
this.id = card.card_id;
this.author = card.author;
this.title = card.title;
this.detail = card.detail;
this.timestamp = card.timestamp.toDateString();
this.col_name = card.col_name;
}
export default CardListModel;
sql ์ฟผ๋ฆฌ๋ฌธ์ ํตํด ๊ฐ์ ธ์จ ๊ฐ๊ฐ์ ์นด๋๋ค์๋ ์นผ๋ผ์ ์ด๋ฆ์ ๋ํ ์ ๋ณด๊ฐ ๋ค์ด๊ฐ ์๋ค. ๋ฌธ์ ๋ ์นด๋ ๋ชจ๋ธ โ ์นด๋ ๋ฆฌ์คํธ ๋ชจ๋ธ โ ์น์ ๋ชจ๋ธ โ ์น์ ๋ฆฌ์คํธ ๋ชจ๋ธ ์์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐฉ์์ผ๋ก ์๊ฐํ์๋๋ฐ, ์ด ๊ณผ์ ์์ ์นด๋์ ์๋ col_name ๊ฐ์ ์ด๋ป๊ฒ ์ถ์ถํ์ฌ ์นด๋ ๋ฆฌ์คํธ์ ๋ฃ์ด์ค์ผ ํ๋์ง์ ๋ํ ๊ณ ๋ฏผ์ด ์์๋ค.
๊ฐ๊ฐ์ ์์์ ๋ํด์ ์ฌ๋ฌ๋ฒ for๋ฌธ์ ๋๋ฉด ํด๊ฒฐ๋ ์๋ ์๋ ๋ฐฉ๋ฒ์ด๊ธด ํ์ง๋ง ์ด๋ ํ๋ฒ ๋์๋ ์์๋ค์ ๋ํด์ ๋ค์๊ธ ๋ฐ๋ณต๋ฌธ์ ๋๋ ๊ฒ์ด ๊ณผ์ฐ ์ข์ ๋ฐฉ๋ฒ์ผ๊น๋ผ๋ ์๊ฐ์ด ๋ค์๋ค. ๋ฌผ๋ก task card์ ํน์์ฑ์ ๊ณ ๋ คํ ๋, ๋๋ถ๋ถ 100๊ฐ๋ฅผ ๋๋ ์ผ์ด ๊ทธ๋ ๊ฒ ๋ง์ง๋ ์์ ๊ฒ์ด๋ผ ์๊ฐํ ์ ์๊ณ , ์ด์ ๋์ ์๋ฅผ ๋๋ ๊ฒ์ ํฐ๋ ๋์ง ์๋ ์๋์ด์ง๋ง์๋ ๋ณด๋ค ํจ์จ์ ์ผ๋ก ์นผ๋ผ์ ์ถ์ถํ ์ ์๋ ๋ฐฉ๋ฒ์ด ๋ฌด์์ด ์์๊น ์๊ฐํด๋ณด์๋ค.
- forEach๋ฌธ์ ํตํด columnlist, card ๋ฐฐ์ด์ ๋ฐ๋ก ๋๊ณ ๊ฐ๊ฐ push
- col_list์ ๋ํด์ ์ฟผ๋ฆฌ๋ฌธ์ ํตํด ์ปฌ๋ผ ๋ฆฌ์คํธ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ
ํ์ฌ๋ 1๋ฒ์ ์ด์ฉํ ๋ฐฉ์์ผ๋ก ๋ก์ง์ ์์ฑํ๋๋ฐ, ํ์ ์ด๋ฌํ ๋ ๋ฐฉ์ ์ค์ ์ด๋ค ๋ฐฉ์์ด ๋์์ง์ ๋ํด์ ๊ณ์ํด์ ๊ณ ๋ฏผํด๋ด์ผํ ๋ฌธ์ ์ธ ๊ฒ ๊ฐ๋ค.
๋น๋๊ธฐ ๋ฆฌ๋ ๋๋ง ๊ด๋ จ๋ ๋ฌธ์
import { onColumnDataChanged } from "../../../feature/mainsection/rendering.js";
import apicall from "../../../shared/utils/apicall.js";
export function submitNewCard(targetForm) {
try {
const title =
targetForm.getElementsByClassName("form__input--title")[0].value;
const detail = targetForm.getElementsByClassName(
"form__textarea--cardDetail"
)[0].value;
const section = targetForm.id;
apicall.post("/api/todo/new", {
title: title,
detail: detail,
section: section,
});
onColumnDataChanged();
} catch (error) {
console.error(`error while data fetching : ${error}`);
}
}
์๋ก์ด task๋ฅผ ์ถ๊ฐํ์ ๊ฒฝ์ฐ์ post ๋ฉ์๋์ api๋ฅผ ํธ์ถํ์ฌ ๋ฐ์ดํฐ๋ฅผ ๊ฐฑ์ ํ๊ณ , ์ดํ์๋ ๋ค์๊ธ ๋ฆฌ๋ ๋๋ง์ ์ด๋ฐ์ํฌ ์ ์๋๋ก ๋ ๋๋ง์ ์ํ ํ์ผ์ feature์ ๋๊ณ ๋๋๋ฉด ๋ฆฌ๋ ๋๋ง์ ์ํฌ ์ ์๋๋ก ์ด๋ฒคํธ๋ฅผ ์ ๋ฌํ๋ ๋ฐฉ์์ผ๋ก ์ค๊ณํ์๋ค. ํ์ง๋ง ์ด๋ฌํ ๊ฒฝ์ฐ์ ์ ๋๋ก ๋ ์ ๋ณด์ ๊ฐฑ์ ์ด ์ด๋ฃจ์ด์ง์ง ์์ ๋ฐ์ดํฐ๋ฅผ ๋ค์ ์ค๋ ์ค๋ฅ๊ฐ ์์๋ค.
ํด๋น ์ฝ๋๋ฅผ ์์ธํ ๋ณธ ๊ฒฐ๊ณผ ๋น๋๊ธฐ์ ์ผ๋ก ๋์ํ๋ ์ฝ๋์์ post๊ฐ ์ด๋ฃจ์ด์ง ํ์ get์์ฒญ์ด ์ด๋ฃจ์ด์ ธ์ผ ํ๊ธฐ ๋๋ฌธ์ ๋๊ธฐ์ ์ผ๋ก ์คํํ ์ ์๋๋ก ํด์ผ ํ๋๋ฐ, ์ด๋ฌํ ๋ถ๋ถ์ ๊ฐ๊ณผํ๊ณ async/await์ ํ์ฉํ์ง ์์ ๋น๋๊ธฐ์ ์ผ๋ก post์ get ์์ฒญ์ด ์ด์ด์ง๊ธฐ ๋๋ฌธ์ ๊ฐฑ์ ๋์ง ์์ ๋ฐ์ดํฐ๋ฅผ fetchํด์ค๊ณ ์์์ ์๊ฒ ๋์๋ค.
router.post("/new", async (req, res) => {
const { title, detail, section } = req.body;
await transaction(todoRepository.addCard, [title, detail, section]);
res.type("Content-Type", "application/json");
res.status(201).json({ message: "Card created successfully" });
});ํ์ง๋ง async/await์ ์ฌ์ฉํ์ฌ ๋๊ธฐ์ ์ผ๋ก ์ฒ๋ฆฌํ์์๋ ๋๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ฒ ๋์๊ณ , api๋ฅผ ํธ์ถํ๋ ํจ์ ์์์ post ์ดํ์ ์ฝ๋๊ฐ ๋์ํ์ง ์์์ ์๊ฒ ๋์๋ค. ๋ฌธ์ ๋ post ์์ฒญ์ ๋ฐ์์ ๋ ๋ฐ๋ก ๋ณด๋ด์ค ๋ฐ์ดํฐ๊ฐ ์๋ค๊ณ ์๊ฐํด์ ์๋ต์ ์ถ๊ฐํด์ฃผ์๋ค.