Skip to content

Commit

Permalink
Merge pull request #272 from boostcampwm-2024/feature/be/#271-modifyG…
Browse files Browse the repository at this point in the history
…etChannelsAPI

[BE][Feat] #271 : 사용자의 채널 리스트 가져올 때 게스트 인원수도 가져오기
  • Loading branch information
happyhyep authored Nov 26, 2024
2 parents 7062249 + 23e49e6 commit 6f2e080
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backend/src/repositories/channelRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ export const getGuestByChannelAndGuestIdFromDB = async (channelId, guestId) => {
export const getChannelsByUserIdFromDB = async userId => {
try {
const query = `
SELECT id, name, generated_at
FROM "main"."channel"
WHERE host_id = $1;
SELECT
c.id,
c.name,
c.generated_at,
COUNT(g.id) AS guest_count
FROM "main"."channel" AS c
LEFT JOIN "main"."guest" AS g ON c.id = g.channel_id
WHERE c.host_id = $1
GROUP BY c.id;
`;
const values = [userId];
const result = await pool.query(query, values);
Expand All @@ -140,6 +146,7 @@ export const getChannelsByUserIdFromDB = async userId => {
id: channel.id,
name: channel.name,
generated_at: channel.generated_at,
guest_count: Number(channel.guest_count),
}));
} catch (error) {
console.error('Database error:', error);
Expand Down
1 change: 1 addition & 0 deletions backend/swaggerConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ const swaggerDefinition = {
id: { type: 'string' },
name: { type: 'string' },
generated_at: { type: 'string', format: 'date-time' },
guest_count: { type: 'number' },
},
required: ['id', 'name', 'generated_at'],
},
Expand Down

0 comments on commit 6f2e080

Please sign in to comment.