Files
gamegroup/src/modules/appointments/appointments.controller.ts

147 lines
4.5 KiB
TypeScript
Raw Normal View History

import {
Controller,
Get,
Post,
Put,
Delete,
Body,
Param,
Query,
UseGuards,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiBearerAuth,
ApiQuery,
} from '@nestjs/swagger';
import { AppointmentsService } from './appointments.service';
import {
CreateAppointmentDto,
UpdateAppointmentDto,
QueryAppointmentsDto,
JoinAppointmentDto,
} from './dto/appointment.dto';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
@ApiTags('appointments')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('appointments')
export class AppointmentsController {
constructor(private readonly appointmentsService: AppointmentsService) {}
@Post()
@ApiOperation({ summary: '创建预约' })
@ApiResponse({ status: 201, description: '创建成功' })
async create(
@CurrentUser('id') userId: string,
@Body() createDto: CreateAppointmentDto,
) {
return this.appointmentsService.create(userId, createDto);
}
@Get()
@ApiOperation({ summary: '获取预约列表' })
@ApiResponse({ status: 200, description: '获取成功' })
@ApiQuery({ name: 'groupId', required: false, description: '小组ID' })
@ApiQuery({ name: 'gameId', required: false, description: '游戏ID' })
@ApiQuery({ name: 'status', required: false, description: '状态' })
@ApiQuery({ name: 'startTime', required: false, description: '开始时间' })
@ApiQuery({ name: 'endTime', required: false, description: '结束时间' })
@ApiQuery({ name: 'page', required: false, description: '页码' })
@ApiQuery({ name: 'limit', required: false, description: '每页数量' })
async findAll(
@CurrentUser('id') userId: string,
@Query() queryDto: QueryAppointmentsDto,
) {
return this.appointmentsService.findAll(userId, queryDto);
}
@Get('my')
@ApiOperation({ summary: '获取我参与的预约' })
@ApiResponse({ status: 200, description: '获取成功' })
@ApiQuery({ name: 'status', required: false, description: '状态' })
@ApiQuery({ name: 'page', required: false, description: '页码' })
@ApiQuery({ name: 'limit', required: false, description: '每页数量' })
async findMyAppointments(
@CurrentUser('id') userId: string,
@Query() queryDto: QueryAppointmentsDto,
) {
return this.appointmentsService.findMyAppointments(userId, queryDto);
}
@Get(':id')
@ApiOperation({ summary: '获取预约详情' })
@ApiResponse({ status: 200, description: '获取成功' })
async findOne(
@CurrentUser('id') userId: string,
@Param('id') id: string,
) {
return this.appointmentsService.findOne(id, userId);
}
@Post('join')
@ApiOperation({ summary: '加入预约' })
@ApiResponse({ status: 200, description: '加入成功' })
async join(
@CurrentUser('id') userId: string,
@Body() joinDto: JoinAppointmentDto,
) {
return this.appointmentsService.join(userId, joinDto.appointmentId);
}
@Delete(':id/leave')
@ApiOperation({ summary: '退出预约' })
@ApiResponse({ status: 200, description: '退出成功' })
async leave(
@CurrentUser('id') userId: string,
@Param('id') id: string,
) {
return this.appointmentsService.leave(userId, id);
}
@Put(':id')
@ApiOperation({ summary: '更新预约' })
@ApiResponse({ status: 200, description: '更新成功' })
async update(
@CurrentUser('id') userId: string,
@Param('id') id: string,
@Body() updateDto: UpdateAppointmentDto,
) {
return this.appointmentsService.update(userId, id, updateDto);
}
@Put(':id/confirm')
@ApiOperation({ summary: '确认预约' })
@ApiResponse({ status: 200, description: '确认成功' })
async confirm(
@CurrentUser('id') userId: string,
@Param('id') id: string,
) {
return this.appointmentsService.confirm(userId, id);
}
@Put(':id/complete')
@ApiOperation({ summary: '完成预约' })
@ApiResponse({ status: 200, description: '完成成功' })
async complete(
@CurrentUser('id') userId: string,
@Param('id') id: string,
) {
return this.appointmentsService.complete(userId, id);
}
@Delete(':id')
@ApiOperation({ summary: '取消预约' })
@ApiResponse({ status: 200, description: '取消成功' })
async cancel(
@CurrentUser('id') userId: string,
@Param('id') id: string,
) {
return this.appointmentsService.cancel(userId, id);
}
}