From 715ce2d9fadc518f372113a412b1c7203c4c52de Mon Sep 17 00:00:00 2001 From: Lee Soobeom Date: Sat, 23 Jul 2022 19:20:22 +0900 Subject: [PATCH] posting css --- frontend/src/board/board.tsx | 8 +- frontend/src/post/editpost.tsx | 146 +++++++++++++++------------ frontend/src/post/intopost.tsx | 36 ++++--- frontend/src/post/posting.tsx | 153 ++++++++++++++++------------- src/controllers/post.controller.ts | 66 ++++++------- src/db/post.db.ts | 5 + src/db/user.db.ts | 2 +- 7 files changed, 232 insertions(+), 184 deletions(-) diff --git a/frontend/src/board/board.tsx b/frontend/src/board/board.tsx index 0de0699..b864008 100644 --- a/frontend/src/board/board.tsx +++ b/frontend/src/board/board.tsx @@ -37,22 +37,22 @@ export default function BoardPage() { return (
-
+
`Travel Report's Board`
`여행지 후기를 남겨주세요!`
-
+
- +
{" "} {/* Link */}
-
+
Title
Date
Clicks
diff --git a/frontend/src/post/editpost.tsx b/frontend/src/post/editpost.tsx index bbff90e..d99ad95 100644 --- a/frontend/src/post/editpost.tsx +++ b/frontend/src/post/editpost.tsx @@ -108,75 +108,99 @@ export function EditPost() { }; return ( -
-
-
-

Id

-

empty

- - - - +
+ +
+
+ + +
+ +
+ +
+ +
+ +
+ +
+ +
-
+
-
-
+ placeholder="제목을 입력해 주세요!" + className="flex w-96 border-2 border-sky-500 rounded" + /> +
+
+ {/* {imgSrc?.map((img, i) => ( + + ))} */} +
+
+ placeholder="여행 후기를 알려주세요!" + className="flex w-96 h-96 border-2 border-sky-500 rounded" + />
diff --git a/frontend/src/post/intopost.tsx b/frontend/src/post/intopost.tsx index e48d783..c3cee02 100644 --- a/frontend/src/post/intopost.tsx +++ b/frontend/src/post/intopost.tsx @@ -24,37 +24,43 @@ export function IntoPost() {
-
-
-
-
+
- +
-
-
+
+
제목: {post.title}
-
+
작성자: {post.user}
+
+ 작성일: {post.date} +
-
-
+
+
도시: {post.city}
-
+
테마: {post.theme}
-
- 작성일: {post.date} -
-
+
조회수: {post.counts}
diff --git a/frontend/src/post/posting.tsx b/frontend/src/post/posting.tsx index f86de42..cea7a65 100644 --- a/frontend/src/post/posting.tsx +++ b/frontend/src/post/posting.tsx @@ -60,7 +60,8 @@ export default function Posting() { if (postingFormMatch(user)) { setLoading(true); if (file) { - sendImg2Db(file); + const res = sendImg2Db(file); + console.log(res); } // const res = await postApi.posting(user); // console.log("서버연결됬나요", res); @@ -153,83 +154,99 @@ export default function Posting() { }; return ( -
-
-
-

Id

-

empty

-
- +
+ +
+
+ + +
+ +
+ +
+ +
+ +
+ +
+
- - - -
-
+
-
-
-
- {imgSrc?.map((img, i) => ( - - ))} + placeholder="제목을 입력해 주세요!" + className="flex w-96 border-2 border-sky-500 rounded" + /> +
+
+ {imgSrc?.map((img, i) => ( + + ))} +
+ placeholder="여행 후기를 알려주세요!" + className="flex w-96 h-96 border-2 border-sky-500 rounded" + />
diff --git a/src/controllers/post.controller.ts b/src/controllers/post.controller.ts index 69af382..49127bc 100644 --- a/src/controllers/post.controller.ts +++ b/src/controllers/post.controller.ts @@ -7,10 +7,6 @@ import { TypedRequest } from "../types"; export const createImgAndPost = asyncWrap(async (reqExp, res, next) => { const req = reqExp as TypedRequestAuth<{ userId: string }>; - // const { date, counts } = req.body as { - // date: ""; - // counts: 0; - // }; const { userId } = req.auth; @@ -20,43 +16,43 @@ export const createImgAndPost = asyncWrap(async (reqExp, res, next) => { multiples: true, }); - const fileIdArr = new Array(); - form.parse(req, (err, fields, files) => { - const title = fields.title?.[0]; - const text = fields.text?.[0]; - const theme = fields.theme?.[0]; - const city = fields.city?.[0]; - if (Array.isArray(files.picture)) { for (var i = 0; i < files.picture.length; i++) { - if (!(files.picture?.[i].originalFilename === null)) { - const originalfilename = files.picture?.[i].originalFilename; - const newfilename = files.picture?.[i].newFilename; - const filepath = files.picture?.[i].filepath; - - const filesRes = postDb.createFilesRow( - originalfilename, - newfilename, - filepath - ); + const originalfilename = files.picture?.[i].originalFilename; + const newfilename = files.picture?.[i].newFilename; + const filepath = files.picture?.[i].filepath; + + const filesRes = postDb.createFilesRow( + originalfilename, + newfilename, + filepath + ); + } + } // create fileinfos row + + if (!Array.isArray(fields.title)) { + const title = fields.title; + if (!Array.isArray(fields.text)) { + const text = fields.text; + if (!Array.isArray(fields.theme)) { + const theme = fields.theme; + if (!Array.isArray(fields.city)) { + const city = fields.city; + + const postRes = postDb.createPostRow({ + title, + text, + theme, + city, + date: Date.now(), + counts: 0, + user: userId, + }); // create posts + } } } - } else { - console.log("업로드한 사진이 없습니다."); } - - const postRes = postDb.createPostRow({ - title, - text, - theme, - city, - date: Date.now(), - counts: 0, - user: userId, - }); - - console.log("createPostRow", postRes); }); }); diff --git a/src/db/post.db.ts b/src/db/post.db.ts index 1b16277..9ce3319 100644 --- a/src/db/post.db.ts +++ b/src/db/post.db.ts @@ -28,6 +28,11 @@ export const createFilesRow = async ( return newFileRow; }; +export const findFile = async (postId: string) => { + const fileInfo = await Post.findById({ postId }).populate("file"); + return fileInfo; +}; + export const findFileByPostInfo = async (title: string, usreId: string) => { const posts = await Post.find({ title: title, userId: usreId }); return posts; diff --git a/src/db/user.db.ts b/src/db/user.db.ts index 0cb5a43..0ef20e3 100644 --- a/src/db/user.db.ts +++ b/src/db/user.db.ts @@ -102,7 +102,7 @@ export const postPicture = async ( } }; -export const deleteUser = async (userId: string) => { +export const deleteUser = async (userId: ObjectId) => { const user = await User.findById(userId); if (user && user.avatar) { const file = await FileInfo.findById(user.avatar._id); -- GitLab