-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [FIX] 게시물 전체조회/카테고리별 조회 API response에 currentPage, totalPageCount,isLastPage 추가 * [FEAT] user profile dummy image url 추가 * [FEAT] 커뮤니티 게시글 상세조회 API * [FIX] createdAt 형식 포맷팅 * [FIX] db query 결과 반환 형식 수정 * [FIX] createdAt format 수정 * [FEAT] 커뮤니티 글 전체 조회 API * [FIX] swagger options의 url 변경 * [FIX] page > totalPageCount일 경우 NOT_FOUND 에러 반환 * [FIX] query string 예외 처리 및 주석 추가 * [FIX] isLastPage 비교 조건 수정 * [FIX] 연산자를 이용해 number로 변환 Co-authored-by: Chae Jeong Ah <[email protected]> * [FIX] COUNT 함수 ::int 이용해서 number로 형변환 Co-authored-by: Chae Jeong Ah <[email protected]> * [FIX] ORDER BY created_at 중복 방지를 위해 ORDER BY id 추가 Co-authored-by: Chae Jeong Ah <[email protected]> * [FIX] COUNT(*)::int로 number 변환됨에 따라 parseInt 삭제 * [FIX] 유저가 신고한 게시글 필터링 * [FIX] 커뮤니티 게시글 카운트할 때 유저가 신고한 게시글 제외 * [FIX] middleware를 이용해 query string validate --------- Co-authored-by: jokj624 <[email protected]>
- Loading branch information
1 parent
7d23202
commit f2a14eb
Showing
7 changed files
with
125 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,57 @@ | ||
const dayjs = require('dayjs'); | ||
const customParseFormat = require('dayjs/plugin/customParseFormat'); | ||
const util = require('../../../lib/util'); | ||
const statusCode = require('../../../constants/statusCode'); | ||
const responseMessage = require('../../../constants/responseMessage'); | ||
const asyncWrapper = require('../../../lib/asyncWrapper'); | ||
const db = require('../../../db/db'); | ||
const { communityDB } = require('../../../db'); | ||
const dummyImages = require('../../../constants/dummyImages'); | ||
|
||
/** | ||
* @route GET /community/posts | ||
* @desc 커뮤니티 게시글 전체 조회 | ||
* @access Private | ||
*/ | ||
|
||
module.exports = async (req, res) => { | ||
module.exports = asyncWrapper(async (req, res) => { | ||
const { userId } = req.user; | ||
const { page, limit } = req.query; | ||
}; | ||
|
||
const dbConnection = await db.connect(req); | ||
req.dbConnection = dbConnection; | ||
|
||
dayjs().format(); | ||
dayjs.extend(customParseFormat); | ||
|
||
const totalItemCount = await communityDB.getCommunityPostsCount(dbConnection, userId); // 총 게시글 수 | ||
const totalPageCount = Math.ceil(totalItemCount / limit); // 총 페이지 수 | ||
const currentPage = +page; // 현재 페이지 | ||
const isLastPage = totalPageCount === currentPage; // 마지막 페이지인지 여부 | ||
// 요청한 페이지가 존재하지 않는 경우 | ||
if (page > totalPageCount) { | ||
return res | ||
.status(statusCode.NOT_FOUND) | ||
.send(util.fail(statusCode.NOT_FOUND, responseMessage.NO_PAGE)); | ||
} | ||
|
||
const communityPosts = await communityDB.getCommunityPosts(dbConnection, userId, limit, page); | ||
// 각 게시글의 createdAt 형식 변경 및 프로필 이미지 추가 | ||
const result = await Promise.all( | ||
communityPosts.map((communityPost) => { | ||
communityPost.createdAt = dayjs(`${communityPost.createdAt}`).format('YYYY. MM. DD'); | ||
communityPost.profileImage = dummyImages.user_profile_dummy; | ||
return communityPost; | ||
}), | ||
); | ||
|
||
res.status(statusCode.OK).send( | ||
util.success(statusCode.OK, responseMessage.READ_COMMUNITY_POSTS_SUCCESS, { | ||
posts: result, | ||
currentPage, | ||
totalPageCount, | ||
totalItemCount, | ||
isLastPage, | ||
}), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters