2026-05-18 10:07:57 +08:00
|
|
|
import { Controller, Get, Query } from '@nestjs/common';
|
2026-05-09 18:25:04 +08:00
|
|
|
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
|
|
|
import { LearningActivityService } from './learning-activity.service';
|
2026-05-24 14:16:14 +08:00
|
|
|
import { GrowthService } from './growth.service';
|
2026-05-17 00:39:46 +08:00
|
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
|
|
|
import type { UserPayload } from '../../common/types';
|
2026-05-09 18:25:04 +08:00
|
|
|
|
|
|
|
|
@ApiTags('learning-activity')
|
|
|
|
|
@Controller('activity')
|
|
|
|
|
export class LearningActivityController {
|
2026-05-24 14:16:14 +08:00
|
|
|
constructor(
|
|
|
|
|
private readonly activityService: LearningActivityService,
|
|
|
|
|
private readonly growth: GrowthService,
|
|
|
|
|
) {}
|
2026-05-09 18:25:04 +08:00
|
|
|
|
|
|
|
|
@Get('heatmap')
|
|
|
|
|
@ApiOperation({ summary: '获取学习热力图数据' })
|
2026-05-17 00:39:46 +08:00
|
|
|
async getHeatmap(@CurrentUser() user: UserPayload) {
|
|
|
|
|
return this.activityService.getHeatmap(String(user?.id || 'anonymous'));
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('summary')
|
|
|
|
|
@ApiOperation({ summary: '获取学习统计概览' })
|
2026-05-17 00:39:46 +08:00
|
|
|
async getSummary(@CurrentUser() user: UserPayload) {
|
|
|
|
|
return this.activityService.getSummary(String(user?.id || 'anonymous'));
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
2026-05-18 10:07:57 +08:00
|
|
|
|
|
|
|
|
@Get('trend')
|
|
|
|
|
@ApiOperation({ summary: '获取 AI 学习趋势分析' })
|
2026-05-24 14:16:14 +08:00
|
|
|
async getTrend(@CurrentUser() user: UserPayload, @Query('days') days?: string) {
|
2026-05-18 10:07:57 +08:00
|
|
|
const periodDays = parseInt(days || '7', 10);
|
2026-05-24 14:16:14 +08:00
|
|
|
return this.activityService.getTrend(String(user?.id || 'anonymous'), Math.min(Math.max(periodDays, 7), 30));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('streak')
|
|
|
|
|
@ApiOperation({ summary: '获取连续学习天数' })
|
|
|
|
|
async getStreak(@CurrentUser() user: UserPayload) {
|
|
|
|
|
return this.growth.getStreak(String(user?.id || 'anonymous'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('recommendations')
|
|
|
|
|
@ApiOperation({ summary: '获取下一步学习推荐' })
|
|
|
|
|
async getRecommendations(@CurrentUser() user: UserPayload) {
|
|
|
|
|
return this.growth.getRecommendations(String(user?.id || 'anonymous'));
|
2026-05-18 10:07:57 +08:00
|
|
|
}
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|