Skip to content

Commit

Permalink
[BE#459] 친구 상세화면 친구의 주간 학습 카테고리 1위
Browse files Browse the repository at this point in the history
  • Loading branch information
victolee0 authored Dec 13, 2023
1 parent 45a1125 commit b09d781
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion BE/src/mates/mates.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ export class MatesService {
date,
);
// 랭킹1위 카테고리 조회 로직 - ToDo
const following_primary_category =
await this.studyLogsService.getPrimaryCategory(
following_id,
start_date,
date,
);

return {
my_daily_data,
following_daily_data,
following_primary_category: null,
following_primary_category,
};
}

Expand Down
18 changes: 18 additions & 0 deletions BE/src/study-logs/study-logs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ export class StudyLogsService {
return result;
}

async getPrimaryCategory(
user_id: number,
start_date: string,
end_date: string,
): Promise<object> {
const primary_category = await this.studyLogsRepository.query(
`SELECT c.id, c.name, c.color_code, SUM(study_logs.learning_time) as total_time
FROM study_logs
LEFT JOIN categories c ON study_logs.category_id = c.id
WHERE study_logs.user_id = ?
AND study_logs.date BETWEEN ? AND ?
GROUP BY c.id
ORDER BY total_time DESC
LIMIT 1`,
[user_id, start_date, end_date],
);
return primary_category[0].name ?? null;
}
async groupByCategory(user_id: number, date: string): Promise<object> {
const studyLogsByCategory = await this.studyLogsRepository.query(
`SELECT
Expand Down

0 comments on commit b09d781

Please sign in to comment.