Skip to content

Commit ba512d3

Browse files
authored
Merge pull request #129 from Solux-WebBeing/fix/getActivities
fix: #126 ํŽ˜์ด์ง€๋„ค์ด์…˜ ์žฌ์ˆ˜์ •
2 parents daf9dff + 44aa9ac commit ba512d3

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)