diff --git a/src/modules/users/users.controller.ts b/src/modules/users/users.controller.ts index 5c3f71e..c60ee15 100644 --- a/src/modules/users/users.controller.ts +++ b/src/modules/users/users.controller.ts @@ -77,4 +77,18 @@ export class UsersController { async removeDevice(@CurrentUser() user: UserPayload, @Param('deviceId') deviceId: string) { return this.usersService.removeDevice(String(user.id), deviceId); } + + // ── Storage & Assets ── + + @Get('me/storage') + @ApiOperation({ summary: '存储空间统计' }) + async getStorage(@CurrentUser() user: UserPayload) { + return this.usersService.getStorage(String(user.id)); + } + + @Get('me/assets-summary') + @ApiOperation({ summary: '学习资产摘要' }) + async getAssetsSummary(@CurrentUser() user: UserPayload) { + return this.usersService.getAssetsSummary(String(user.id)); + } } diff --git a/src/modules/users/users.service.ts b/src/modules/users/users.service.ts index 248abb0..3d058c2 100644 --- a/src/modules/users/users.service.ts +++ b/src/modules/users/users.service.ts @@ -68,4 +68,27 @@ export class UsersService { }); return { success: true }; } + + // ── Storage ── + + async getStorage(userId: string) { + const files = await this.prisma.uploadedFile.findMany({ + where: { userId }, + select: { sizeBytes: true, mimeType: true }, + }); + const usedBytes = files.reduce((sum, f) => sum + f.sizeBytes, 0); + const totalBytes = 1024 * 1024 * 1024; // 1GB hardcoded for now + return { totalBytes, usedBytes, fileCount: files.length }; + } + + // ── Assets Summary ── + + async getAssetsSummary(userId: string) { + const [kbCount, itemCount, cardCount] = await Promise.all([ + this.prisma.knowledgeBase.count({ where: { userId, deletedAt: null } }), + this.prisma.knowledgeItem.count({ where: { userId, deletedAt: null } }), + this.prisma.reviewCard.count({ where: { userId } }), + ]); + return { knowledgeBaseCount: kbCount, knowledgeItemCount: itemCount, reviewCardCount: cardCount }; + } }