feat: 新增饮食记录模块,含增删改查及营养汇总功能
This commit is contained in:
@@ -25,7 +25,6 @@ import { ApiOperation, ApiBody, ApiResponse, ApiTags, ApiQuery } from '@nestjs/s
|
||||
import { UpdateUserDto, UpdateUserResponseDto } from './dto/update-user.dto';
|
||||
import { AppleLoginDto, AppleLoginResponseDto, RefreshTokenDto, RefreshTokenResponseDto } from './dto/apple-login.dto';
|
||||
import { DeleteAccountDto, DeleteAccountResponseDto } from './dto/delete-account.dto';
|
||||
import { CreateDietRecordDto, UpdateDietRecordDto, GetDietHistoryQueryDto, DietRecordResponseDto, DietHistoryResponseDto, DietAnalysisResponseDto } from './dto/diet-record.dto';
|
||||
import { GuestLoginDto, GuestLoginResponseDto, RefreshGuestTokenDto, RefreshGuestTokenResponseDto } from './dto/guest-login.dto';
|
||||
import { AppStoreServerNotificationDto, ProcessNotificationResponseDto } from './dto/app-store-notification.dto';
|
||||
import { RestorePurchaseDto, RestorePurchaseResponseDto } from './dto/restore-purchase.dto';
|
||||
@@ -276,83 +275,6 @@ export class UsersController {
|
||||
return this.usersService.restorePurchase(restorePurchaseDto, user.sub, clientIp, userAgent);
|
||||
}
|
||||
|
||||
// ==================== 饮食记录相关接口 ====================
|
||||
|
||||
/**
|
||||
* 添加饮食记录
|
||||
*/
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('diet-records')
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@ApiOperation({ summary: '添加饮食记录' })
|
||||
@ApiBody({ type: CreateDietRecordDto })
|
||||
@ApiResponse({ status: 201, description: '成功添加饮食记录', type: DietRecordResponseDto })
|
||||
async addDietRecord(
|
||||
@Body() createDto: CreateDietRecordDto,
|
||||
@CurrentUser() user: AccessTokenPayload,
|
||||
): Promise<DietRecordResponseDto> {
|
||||
this.logger.log(`添加饮食记录 - 用户ID: ${user.sub}, 食物: ${createDto.foodName}`);
|
||||
return this.usersService.addDietRecord(user.sub, createDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取饮食记录历史
|
||||
*/
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('diet-records')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: '获取饮食记录历史' })
|
||||
@ApiQuery({ name: 'startDate', required: false, description: '开始日期' })
|
||||
@ApiQuery({ name: 'endDate', required: false, description: '结束日期' })
|
||||
@ApiQuery({ name: 'mealType', required: false, description: '餐次类型' })
|
||||
@ApiQuery({ name: 'page', required: false, description: '页码' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: '每页数量' })
|
||||
@ApiResponse({ status: 200, description: '成功获取饮食记录', type: DietHistoryResponseDto })
|
||||
async getDietHistory(
|
||||
@Query() query: GetDietHistoryQueryDto,
|
||||
@CurrentUser() user: AccessTokenPayload,
|
||||
): Promise<DietHistoryResponseDto> {
|
||||
this.logger.log(`获取饮食记录 - 用户ID: ${user.sub}`);
|
||||
return this.usersService.getDietHistory(user.sub, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新饮食记录
|
||||
*/
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('diet-records/:id')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: '更新饮食记录' })
|
||||
@ApiBody({ type: UpdateDietRecordDto })
|
||||
@ApiResponse({ status: 200, description: '成功更新饮食记录', type: DietRecordResponseDto })
|
||||
async updateDietRecord(
|
||||
@Param('id') recordId: string,
|
||||
@Body() updateDto: UpdateDietRecordDto,
|
||||
@CurrentUser() user: AccessTokenPayload,
|
||||
): Promise<DietRecordResponseDto> {
|
||||
this.logger.log(`更新饮食记录 - 用户ID: ${user.sub}, 记录ID: ${recordId}`);
|
||||
return this.usersService.updateDietRecord(user.sub, parseInt(recordId), updateDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除饮食记录
|
||||
*/
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('diet-records/:id')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
@ApiOperation({ summary: '删除饮食记录' })
|
||||
@ApiResponse({ status: 204, description: '成功删除饮食记录' })
|
||||
async deleteDietRecord(
|
||||
@Param('id') recordId: string,
|
||||
@CurrentUser() user: AccessTokenPayload,
|
||||
): Promise<void> {
|
||||
this.logger.log(`删除饮食记录 - 用户ID: ${user.sub}, 记录ID: ${recordId}`);
|
||||
const success = await this.usersService.deleteDietRecord(user.sub, parseInt(recordId));
|
||||
if (!success) {
|
||||
throw new NotFoundException('饮食记录不存在');
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 用户活跃记录相关接口 ====================
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user