feat: 开发我的持仓列表
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Query,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
UseGuards,
|
||||
Request,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiParam,
|
||||
ApiBearerAuth,
|
||||
} from '@nestjs/swagger';
|
||||
import { PositionChangeService } from './position-change.service';
|
||||
import { CreatePositionChangeDto } from './dto/create-position-change.dto';
|
||||
import { UpdatePositionChangeDto } from './dto/update-position-change.dto';
|
||||
import { QueryPositionChangeDto } from './dto/query-position-change.dto';
|
||||
import { PositionChange } from './position-change.entity';
|
||||
import { PaginatedPositionChangeData } from './dto/paginated-response.dto';
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { User } from '../user/user.entity';
|
||||
|
||||
@ApiTags('position-change')
|
||||
@Controller('position-change')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
export class PositionChangeController {
|
||||
constructor(
|
||||
private readonly positionChangeService: PositionChangeService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 分页查询单个持仓的所有变更记录
|
||||
*/
|
||||
@Get('position/:positionId')
|
||||
@ApiOperation({
|
||||
summary: '查询单个持仓的所有变更记录',
|
||||
description: '分页查询指定持仓的所有变更记录,按变更日期倒序',
|
||||
})
|
||||
@ApiParam({ name: 'positionId', description: '持仓ID', type: Number })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: '查询成功',
|
||||
type: PaginatedPositionChangeData,
|
||||
})
|
||||
@ApiResponse({ status: 401, description: '未授权' })
|
||||
@ApiResponse({ status: 404, description: '持仓不存在' })
|
||||
findAllByPositionId(
|
||||
@Request() req: { user: User },
|
||||
@Param('positionId') positionId: string,
|
||||
@Query() queryDto: QueryPositionChangeDto,
|
||||
): Promise<PaginatedPositionChangeData> {
|
||||
return this.positionChangeService.findAllByPositionId(
|
||||
+positionId,
|
||||
req.user.userId,
|
||||
queryDto,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建持仓变更记录
|
||||
*/
|
||||
@Post()
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@ApiOperation({
|
||||
summary: '创建持仓变更记录',
|
||||
description: '为指定持仓创建新的变更记录',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: '创建成功',
|
||||
type: PositionChange,
|
||||
})
|
||||
@ApiResponse({ status: 400, description: '请求参数错误' })
|
||||
@ApiResponse({ status: 404, description: '持仓不存在' })
|
||||
create(
|
||||
@Request() req: { user: User },
|
||||
@Body() createPositionChangeDto: CreatePositionChangeDto,
|
||||
): Promise<PositionChange> {
|
||||
return this.positionChangeService.create(
|
||||
req.user.userId,
|
||||
createPositionChangeDto,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新持仓变更记录的备注/思考
|
||||
*/
|
||||
@Patch(':id')
|
||||
@ApiOperation({
|
||||
summary: '更新持仓变更记录的备注',
|
||||
description: '更新指定变更记录的备注/思考内容',
|
||||
})
|
||||
@ApiParam({ name: 'id', description: '变更记录ID', type: Number })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: '更新成功',
|
||||
type: PositionChange,
|
||||
})
|
||||
@ApiResponse({ status: 404, description: '变更记录不存在' })
|
||||
@ApiResponse({ status: 403, description: '无权访问' })
|
||||
update(
|
||||
@Request() req: { user: User },
|
||||
@Param('id') id: string,
|
||||
@Body() updatePositionChangeDto: UpdatePositionChangeDto,
|
||||
): Promise<PositionChange> {
|
||||
return this.positionChangeService.update(
|
||||
+id,
|
||||
req.user.userId,
|
||||
updatePositionChangeDto,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user