Skip to content

Commit 44aa9ac

Browse files
committed
fix: #126 페이지네이션 재수정
1 parent 647a697 commit 44aa9ac

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

backend/src/controllers/user.controller.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,12 @@ exports.getOrgActivities = async (req, res) => {
635635
const limit = 4;
636636
const offset = (page - 1) * limit;
637637

638-
try { // 날짜, 지역, 태그, 응원 수 필드 추가
638+
try {
639+
// 해당 단체가 작성한 전체 게시글 개수 조회
640+
const countSql = 'SELECT COUNT(*) as total FROM boards WHERE user_id = ?';
641+
const [countRows] = await pool.query(countSql, [id]);
642+
const total_count = countRows[0].total;
643+
639644
const sql = `
640645
SELECT
641646
b.id, b.title, b.start_date, b.end_date, b.region, b.district, b.topics, b.created_at,
@@ -658,7 +663,13 @@ exports.getOrgActivities = async (req, res) => {
658663
return success(res, '아직 등록한 연대 활동이 없어요.', { posts: [] });
659664
}
660665

661-
return success(res, '활동 조회 성공', { posts });
666+
// 결과 반환
667+
return success(res, '활동 조회 성공', {
668+
posts,
669+
total_count: total_count,
670+
total_pages: Math.ceil(total_count / limit),
671+
current_page: page
672+
});
662673
} catch (error) {
663674
console.error('Get Org Activities Error:', error);
664675
return fail(res, '서버 에러가 발생했습니다.', 500);
@@ -863,6 +874,11 @@ exports.getIndividualActivities = async (req, res) => {
863874
const limit = 4;
864875
const offset = (page - 1) * limit;
865876
try {
877+
// 전체 게시글 개수 조회 추가
878+
const countSql = 'SELECT COUNT(*) as total FROM boards WHERE user_id = ?';
879+
const [countRows] = await pool.query(countSql, [id]);
880+
const total_count = countRows[0].total;
881+
866882
// LIMIT와 OFFSET을 적용한 게시글 조회 쿼리
867883
const postSql = `
868884
SELECT
@@ -887,7 +903,9 @@ exports.getIndividualActivities = async (req, res) => {
887903

888904
return success(res, '활동 조회 성공', {
889905
written_posts: posts,
890-
cheer_count: cheers[0].count
906+
total_count: total_count,
907+
total_pages: Math.ceil(total_count / limit),
908+
current_page: page
891909
});
892910
} catch (error) {
893911
console.error('Get Individual Activities Error:', error);

0 commit comments

Comments
 (0)