Skip to content

Commit

Permalink
Merge pull request #172 from demo-Bloodtrail/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aeeazip authored Feb 18, 2024
2 parents a19ea8e + 7b3d879 commit 7b02bd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Binary file modified README.md
Binary file not shown.
21 changes: 18 additions & 3 deletions src/controller/postController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -77,16 +79,29 @@ 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.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;
return res.send(response(status.SUCCESS, { userLiked, post }));
}
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));
Expand Down

0 comments on commit 7b02bd7

Please sign in to comment.