feat: 新增心情打卡功能模块
实现心情打卡的完整功能,包括数据库表设计、API接口、业务逻辑和文档说明。支持记录多种心情类型、强度评分和统计分析功能。
This commit is contained in:
106
src/mood-checkins/mood-checkins.controller.ts
Normal file
106
src/mood-checkins/mood-checkins.controller.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import { Controller, Get, Post, Put, Delete, Body, Query, UseGuards, Logger } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { MoodCheckinsService } from './mood-checkins.service';
|
||||
import {
|
||||
CreateMoodCheckinDto,
|
||||
UpdateMoodCheckinDto,
|
||||
RemoveMoodCheckinDto,
|
||||
MoodCheckinResponseDto,
|
||||
GetMoodCheckinsQueryDto,
|
||||
GetMoodHistoryQueryDto,
|
||||
MoodStatistics
|
||||
} from './dto/mood-checkin.dto';
|
||||
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
|
||||
import { CurrentUser } from '../common/decorators/current-user.decorator';
|
||||
|
||||
@ApiTags('心情打卡')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('mood-checkins')
|
||||
export class MoodCheckinsController {
|
||||
private readonly logger = new Logger(MoodCheckinsController.name);
|
||||
|
||||
constructor(private readonly moodCheckinsService: MoodCheckinsService) { }
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: '创建心情打卡' })
|
||||
@ApiResponse({ status: 201, description: '心情打卡创建成功', type: MoodCheckinResponseDto })
|
||||
@ApiResponse({ status: 400, description: '请求参数错误' })
|
||||
@ApiResponse({ status: 401, description: '未授权' })
|
||||
async create(
|
||||
@Body() createMoodCheckinDto: CreateMoodCheckinDto,
|
||||
@CurrentUser('id') userId: string,
|
||||
): Promise<MoodCheckinResponseDto> {
|
||||
this.logger.log(`用户 ${userId} 创建心情打卡: ${JSON.stringify(createMoodCheckinDto)}`);
|
||||
return this.moodCheckinsService.create(createMoodCheckinDto, userId);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: '更新心情打卡' })
|
||||
@ApiResponse({ status: 200, description: '心情打卡更新成功', type: MoodCheckinResponseDto })
|
||||
@ApiResponse({ status: 400, description: '请求参数错误' })
|
||||
@ApiResponse({ status: 401, description: '未授权' })
|
||||
@ApiResponse({ status: 403, description: '无权操作' })
|
||||
@ApiResponse({ status: 404, description: '记录不存在' })
|
||||
async update(
|
||||
@Body() updateMoodCheckinDto: UpdateMoodCheckinDto,
|
||||
@CurrentUser('id') userId: string,
|
||||
): Promise<MoodCheckinResponseDto> {
|
||||
this.logger.log(`用户 ${userId} 更新心情打卡: ${JSON.stringify(updateMoodCheckinDto)}`);
|
||||
return this.moodCheckinsService.update(updateMoodCheckinDto, userId);
|
||||
}
|
||||
|
||||
@Delete()
|
||||
@ApiOperation({ summary: '删除心情打卡' })
|
||||
@ApiResponse({ status: 200, description: '心情打卡删除成功', type: MoodCheckinResponseDto })
|
||||
@ApiResponse({ status: 401, description: '未授权' })
|
||||
@ApiResponse({ status: 403, description: '无权操作' })
|
||||
@ApiResponse({ status: 404, description: '记录不存在' })
|
||||
async remove(
|
||||
@Body() removeMoodCheckinDto: RemoveMoodCheckinDto,
|
||||
@CurrentUser('id') userId: string,
|
||||
): Promise<MoodCheckinResponseDto> {
|
||||
this.logger.log(`用户 ${userId} 删除心情打卡: ${removeMoodCheckinDto.id}`);
|
||||
return this.moodCheckinsService.remove(removeMoodCheckinDto, userId);
|
||||
}
|
||||
|
||||
@Get('daily')
|
||||
@ApiOperation({ summary: '获取每日心情打卡' })
|
||||
@ApiResponse({ status: 200, description: '获取成功', type: MoodCheckinResponseDto })
|
||||
@ApiResponse({ status: 400, description: '日期格式错误' })
|
||||
@ApiResponse({ status: 401, description: '未授权' })
|
||||
async getDaily(
|
||||
@Query() query: GetMoodCheckinsQueryDto,
|
||||
@CurrentUser('id') userId: string,
|
||||
): Promise<MoodCheckinResponseDto> {
|
||||
this.logger.log(`用户 ${userId} 获取每日心情打卡: ${query.date || '今天'}`);
|
||||
return this.moodCheckinsService.getDaily(userId, query.date);
|
||||
}
|
||||
|
||||
@Get('history')
|
||||
@ApiOperation({ summary: '获取心情打卡历史' })
|
||||
@ApiResponse({ status: 200, description: '获取成功', type: MoodCheckinResponseDto })
|
||||
@ApiResponse({ status: 400, description: '日期范围错误' })
|
||||
@ApiResponse({ status: 401, description: '未授权' })
|
||||
async getHistory(
|
||||
@Query() query: GetMoodHistoryQueryDto,
|
||||
@CurrentUser('id') userId: string,
|
||||
): Promise<MoodCheckinResponseDto> {
|
||||
this.logger.log(`用户 ${userId} 获取心情打卡历史: ${query.startDate} - ${query.endDate}`);
|
||||
return this.moodCheckinsService.getHistory(userId, query);
|
||||
}
|
||||
|
||||
@Get('statistics')
|
||||
@ApiOperation({ summary: '获取心情统计数据' })
|
||||
@ApiResponse({ status: 200, description: '获取成功', type: MoodCheckinResponseDto })
|
||||
@ApiResponse({ status: 400, description: '日期范围错误' })
|
||||
@ApiResponse({ status: 401, description: '未授权' })
|
||||
async getStatistics(
|
||||
@Query('startDate') startDate: string,
|
||||
@Query('endDate') endDate: string,
|
||||
@CurrentUser('id') userId: string,
|
||||
): Promise<MoodCheckinResponseDto<MoodStatistics>> {
|
||||
this.logger.log(`用户 ${userId} 获取心情统计: ${startDate} - ${endDate}`);
|
||||
return this.moodCheckinsService.getStatistics(userId, startDate, endDate);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user