Skip to content

Commit

Permalink
[FIX] 커뮤니티 게시글 상세 조회 시 신고한 게시글 필터링 로직 추가 (#351)
Browse files Browse the repository at this point in the history
* [FIX] 커뮤니티 게시글 상세 조회 시 신고한 게시글 필터링

* [FIX] 커뮤니티 게시글 상세 조회 시 params validator 사용하도록 수정

* [FIX] 신고한 게시글 반환 메시지 변수명 수정
  • Loading branch information
jokj624 authored Apr 23, 2024
1 parent 442401d commit 2fd50c5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
19 changes: 15 additions & 4 deletions functions/api/routes/community/communityPostGET.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,31 @@ const asyncWrapper = require('../../../lib/asyncWrapper');
*/

module.exports = asyncWrapper(async (req, res) => {
const { userId } = req.user;
const { communityPostId } = req.params;
if (!communityPostId) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));
}

const dbConnection = await db.connect(req);
req.dbConnection = dbConnection;

const isReportedPost = await communityDB.getReportedPostByUser(
dbConnection,
userId,
communityPostId,
);
if (isReportedPost) {
return res
.status(statusCode.BAD_REQUEST)
.send(util.fail(statusCode.BAD_REQUEST, responseMessage.ALREADY_REPORTED_POST));
}

dayjs().format();
dayjs.extend(customParseFormat);

const communityPost = await communityDB.getCommunityPostDetail(dbConnection, communityPostId);
if (!communityPost) {
return res.status(statusCode.NOT_FOUND).send(util.fail(statusCode.NOT_FOUND, responseMessage.NO_COMMUNITY_POST));
return res
.status(statusCode.NOT_FOUND)
.send(util.fail(statusCode.NOT_FOUND, responseMessage.NO_COMMUNITY_POST));
}

communityPost.createdAt = dayjs(`${communityPost.createdAt}`).format('YYYY. MM. DD');
Expand Down
1 change: 1 addition & 0 deletions functions/api/routes/community/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ router.get(
router.get(
'/posts/:communityPostId',
checkUser,
[...communityValidator.getCommunityPostValidator, validate],
require('./communityPostGET'),
/**
* #swagger.summary = "커뮤니티 게시글 상세 조회"
Expand Down
1 change: 1 addition & 0 deletions functions/constants/responseMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = {
NO_COMMUNITY_CATEGORY: '존재하지 않는 커뮤니티 카테고리',
NO_PAGE: '존재하지 않는 페이지',
READ_COMMUNITY_CATEGORIES_SUCCESS: '커뮤니티 카테고리 조회 성공',
ALREADY_REPORTED_POST: '이미 신고한 게시글',
READ_COMMUNITY_CATEGORY_POSTS_SUCCESS: '커뮤니티 카테고리별 게시글 조회 성공',
REPORT_COMMUNITY_POST_SUCCESS: '커뮤니티 게시글 신고 성공',

Expand Down
16 changes: 15 additions & 1 deletion functions/db/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ const getCommunityPostsCount = async (client, userId) => {
return rows[0].count;
};

const getReportedPostByUser = async (client, userId, communityPostId) => {
const { rows } = await client.query(
`
SELECT 1
FROM community_post_report_user cpru
WHERE cpru.report_user_id = $1 AND cpru.community_post_id = $2
`,
[userId, communityPostId],
);

return rows[0];
};

const getCommunityCategoryPostsCount = async (client, userId, communityCategoryId) => {
const { rows } = await client.query(
`
Expand Down Expand Up @@ -190,7 +203,8 @@ module.exports = {
isExistingCategory,
getCommunityCategories,
getCommunityPostsCount,
getReportedPostByUser,
getCommunityCategoryPostsCount,
getCommunityCategoryPostsById,
reportCommunityPost
reportCommunityPost,
};
8 changes: 8 additions & 0 deletions functions/middlewares/validator/communityValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const getCommunityPostsValidator = [
query('limit').notEmpty().isInt({ min: 1 }).withMessage('Invalid limit field'),
];

const getCommunityPostValidator = [
param('communityPostId')
.notEmpty()
.isInt({ min: 1 })
.withMessage('Invalid communityPostId field'),
];

const getCommunityCategoryPostsValidator = [
query('page').notEmpty().isInt({ min: 1 }).withMessage('Invalid page field'),
query('limit').notEmpty().isInt({ min: 1 }).withMessage('Invalid limit field'),
Expand All @@ -32,6 +39,7 @@ const reportCommunityPostValidator = [
module.exports = {
createCommunityPostValidator,
getCommunityPostsValidator,
getCommunityPostValidator,
getCommunityCategoryPostsValidator,
reportCommunityPostValidator
};

0 comments on commit 2fd50c5

Please sign in to comment.