Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import express from "express";
import cors from "cors";
import productRouter from "./routes/product/product.js";
import articleRouter from "./routes/article/article.js";
import pCommentRouter from "./routes/pComment/pComment.js";
import aCommentRouter from "./routes/aComment/aComment.js";
import pHeartRouter from "./routes/PHeart/PHeart.js";
import aHeartRouter from "./routes/AHeart/AHeart.js";

const app = express();

app.use(cors());
app.use(express.json());

// 라우터 등록
Expand All @@ -17,8 +21,12 @@ app.use("/pComment", pCommentRouter);

app.use("/aComment", aCommentRouter);

app.use("/pHeart", pHeartRouter);

app.use("/aHeart", aHeartRouter);

// 서버 실행
const PORT = 3000;
const PORT = 5000;
app.listen(PORT, () => {
console.log(`✅ 서버가 http://localhost:${PORT}에서 실행 중...🚀`);
});
30 changes: 30 additions & 0 deletions controllers/AHeart/AHeart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createAHeart, updateAHeart } from "../../services/aHeart/aHeart.js";

export const postAHeart = async (req, res) => {
const data = req.body;
try {
const hearts = await createAHeart(data);
if (!hearts) {
return res.status(404).json({ error: "Articles not found" });
}
res.status(200).json(hearts);
} catch (error) {
console.error("❌ [postAHeart] error:", error);
res.status(500).json({ error: "Internal Server Error" });
}
};

export const patchAHeart = async (req, res) => {
const { id } = req.params;
const { data } = req.body;
try {
const hearts = await updateAHeart(id, data);
if (!hearts) {
return res.status(404).json({ error: "Hearts not found" });
}
res.status(200).json(hearts);
} catch (error) {
console.error("❌ [patchAHeart] error:", error);
res.status(500).json({ error: "Internal Server Error" });
}
};
30 changes: 30 additions & 0 deletions controllers/PHeart/PHeart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createPHeart, updatePHeart } from "../../services/pHeart/pHeart.js";

export const postPHeart = async (req, res) => {
const data = req.body;
try {
const hearts = await createPHeart(data);
if (!hearts) {
return res.status(404).json({ error: "Articles not found" });
}
res.status(200).json(hearts);
} catch (error) {
console.error("❌ [postPHeart] error:", error);
res.status(500).json({ error: "Internal Server Error" });
}
};

export const patchPHeart = async (req, res) => {
const { id } = req.params;
const { data } = req.body;
try {
const hearts = await updatePHeart(id, data);
if (!hearts) {
return res.status(404).json({ error: "Hearts not found" });
}
res.status(200).json(hearts);
} catch (error) {
console.error("❌ [patchPHeart] error:", error);
res.status(500).json({ error: "Internal Server Error" });
}
};
10 changes: 6 additions & 4 deletions controllers/article/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export const getAllArticles = async (req, res) => {
};

export const getArticleById = async (req, res) => {
const id = req.query.id;
const id = req.params.id;
const userId = req.query.userId;
try {
const articles = await fetchArticleById(id);
const articles = await fetchArticleById(id, userId);
if (!articles) {
return res.status(404).json({ error: "Articles not found" });
}
Expand All @@ -35,7 +36,7 @@ export const getArticleById = async (req, res) => {
};

export const postArticle = async (req, res) => {
const data = req.body;
const { data } = req.body;
try {
const articles = await createArticle(data);
if (!articles) {
Expand All @@ -49,7 +50,8 @@ export const postArticle = async (req, res) => {
};

export const patchArticle = async (req, res) => {
const { id, data } = req.body;
const { data } = req.body;
const id = req.params.id;
try {
const articles = await updateArticle(id, data);
if (!articles) {
Expand Down
132 changes: 132 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading