diff --git a/src/controllers/post.controller.ts b/src/controllers/post.controller.ts index 262cb2737e27871250916978cc83c79b2c8b61c1..5c07d324aff92cd7c43eead5e59b4c62bbeb28fe 100644 --- a/src/controllers/post.controller.ts +++ b/src/controllers/post.controller.ts @@ -5,7 +5,7 @@ import { asyncWrap } from "../helpers"; import { postDb } from "../db"; export const posting = asyncWrap(async (req, res) => { - const { title, text, theme, city, username } = req.body; + const { title, text, theme, city, username, date, counts } = req.body; console.log("body", req.body); @@ -38,18 +38,8 @@ export const posting = asyncWrap(async (req, res) => { theme, city, username, + date, + counts, }); return res.json(newPosting); }); - -export const post = asyncWrap(async (req, res) => { - const { title, theme, city, username, date, counts } = req.body; - - console.log("body", req.body); - - // 1) DB postings에서 title, theme, city, username, date 불러오기 - - // 2) 불러온 데이터 + counts posts에 저장 - - // 3) DB posts에서 데이터 불러서 frontend로 보내기 -}); diff --git a/src/db/post.db.ts b/src/db/post.db.ts index 8a248305210fb60ef7f62e6b627cae04ff9d9ac5..a069423e6bbe710d75a4739e48aa51ac2d85a553 100644 --- a/src/db/post.db.ts +++ b/src/db/post.db.ts @@ -8,16 +8,8 @@ export const createPosting = async (posting: PostingType) => { theme: posting.theme, city: posting.city, username: posting.username, + date: posting.date, + counts: posting.counts, }); return newPosting; }; - -export const createPost = async (post: PostType) => { - const newPost = await Post.create({ - title: post.title, - theme: post.theme, - city: post.city, - date: post.date, - counts: post.counts, - }); -}; diff --git a/src/models/posting.model.ts b/src/models/posting.model.ts index d71ed7eba232784124aea66195ee7cc4156a4ae9..64efd9a23938fc2f67f13c83ea93c4b26fe16f61 100644 --- a/src/models/posting.model.ts +++ b/src/models/posting.model.ts @@ -6,6 +6,8 @@ export interface PostingType { theme: string; city: string; username?: string; + date?: string; + counts?: number; } const postingSchema = new Schema({ @@ -26,6 +28,11 @@ const postingSchema = new Schema({ username: { type: String, }, + date: { + type: Date, + dafault: Date.now, + }, + counts: 0, }); export default model("Posting", postingSchema); diff --git a/src/routes/post.route.ts b/src/routes/post.route.ts index 93e191e4e15a750ddb34c0f0023b9a3d531b30fe..0464fb7cee5c11927af754b8f6fbb62f2b8c549b 100644 --- a/src/routes/post.route.ts +++ b/src/routes/post.route.ts @@ -1,8 +1,8 @@ import express from "express"; -import { postCtrl } from "../controllers"; +import { postCtrl, authCtrl } from "../controllers"; const router = express.Router(); -router.route("/").post(postCtrl.posting); +router.route("/").post(authCtrl.requireLogin, postCtrl.posting); export default router;