From a1b4c420a7221efee5b2436754e4adc28d8347cc Mon Sep 17 00:00:00 2001 From: Goosmos Date: Sun, 18 Feb 2024 11:42:56 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feauture(#165)=2010=EB=B6=84=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=20=EC=A1=B0=ED=9A=8C=EC=88=98=20=EC=A6=9D=EA=B0=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/postController.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/controller/postController.js b/src/controller/postController.js index 07bc233..2754a58 100644 --- a/src/controller/postController.js +++ b/src/controller/postController.js @@ -4,6 +4,8 @@ import { status } from "../config/responseStatus.js"; import { customErrResponse, errResponse, response } from '../config/response.js'; import { deleteImage } from '../middleware/imageMiddleware.js'; +const viewObj = new Object(); + // 줄글 형식으로 게시글을 확인하기 export const getLinePosting = async (req, res, next) => { @@ -77,8 +79,23 @@ export const viewPost = async (req, res, next) => { try { const { _id, email } = req.user; const postId = req.params.id; - const post = await Post.findOneAndUpdate({ _id: postId }, { $inc: { watch_count: +1 } }, { new: true }); - let userLiked + // const post = await Post.findOneAndUpdate({ _id: postId }, { $inc: { watch_count: +1 } }, { new: true }); + const post = await Post.findById({ _id: postId }); + + if (!viewObj[postId]) viewObj[postId] = []; // 리스트를 생성 + if (viewObj[postId].indexOf(_id) == -1) { + viewObj[postId].push(_id); + post.watch_count++; + await post.save(); + setTimeout(() => { + viewObj[postId].splice(viewObj[postId].indexOf(_id), 1) + }, 600000); + } + + for (let i in viewObj) { + if (i.length == 0) delete viewObj.i; + } + if (post.like_users.includes(_id)) { // 이미 좋아요를 누른 사람인 경우 let userLiked = true; @@ -86,7 +103,7 @@ export const viewPost = async (req, res, next) => { } else { let userLiked = false; - return res.send(response(status.SUCCESS, {userLiked, post })); + return res.send(response(status.SUCCESS, { userLiked, post })); } } catch ( error ) { return res.send(errResponse(status.INTERNAL_SERVER_ERROR)); From aa25e2fab84d14040a823e1f9469fba3aeb29432 Mon Sep 17 00:00:00 2001 From: Goosmos Date: Sun, 18 Feb 2024 11:46:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feature(#165)=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9D=BC=EB=B6=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/postController.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/controller/postController.js b/src/controller/postController.js index 2754a58..85978e0 100644 --- a/src/controller/postController.js +++ b/src/controller/postController.js @@ -79,7 +79,6 @@ export const viewPost = async (req, res, next) => { try { const { _id, email } = req.user; const postId = req.params.id; - // const post = await Post.findOneAndUpdate({ _id: postId }, { $inc: { watch_count: +1 } }, { new: true }); const post = await Post.findById({ _id: postId }); if (!viewObj[postId]) viewObj[postId] = []; // 리스트를 생성 @@ -96,7 +95,6 @@ export const viewPost = async (req, res, next) => { if (i.length == 0) delete viewObj.i; } - if (post.like_users.includes(_id)) { // 이미 좋아요를 누른 사람인 경우 let userLiked = true; return res.send(response(status.SUCCESS, { userLiked, post })); From 7b3d879921a87df83aa13bf5734753dc87e6676f Mon Sep 17 00:00:00 2001 From: Jung Chaewon Date: Sun, 18 Feb 2024 22:15:21 +0900 Subject: [PATCH 3/3] Update README.md --- README.md | Bin 1422 -> 3834 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index abbd49c5f0e5a8d68fe14e39d7ba5c7b8f81f677..3e0fad66a3c33253680cf953b431c47b2e976e70 100644 GIT binary patch literal 3834 zcmbtXZBr9h6#mW(|KTXp7H8Z96J8Rg+6e?YI-_-ntsgp_y4k%+RyJ9>y8-FsL&V@P z5R29zL4(pM3UsiI7&VSK{V#sZy*v67dhX2zkQj@SVUp$E=bY!9bI-YX^7hrg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