feat: add Schedules module with conflict detection and weekly view
This commit is contained in:
119
apps/server/src/schedules/schedules.controller.ts
Normal file
119
apps/server/src/schedules/schedules.controller.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
Request,
|
||||
} from '@nestjs/common';
|
||||
import { SchedulesService } from './schedules.service';
|
||||
import {
|
||||
CreateScheduleDto,
|
||||
UpdateScheduleDto,
|
||||
QueryScheduleDto,
|
||||
WeeklyViewQueryDto,
|
||||
} from './dto/schedule.dto';
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { OperationLogsService } from '../operation-logs/operation-logs.service';
|
||||
import { extractRequestInfo } from '../common/request-utils';
|
||||
import { RequirePermission } from '../auth/decorators/permission.decorator';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('class-schedules')
|
||||
export class SchedulesController {
|
||||
constructor(
|
||||
private readonly service: SchedulesService,
|
||||
private readonly logService: OperationLogsService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@RequirePermission('schedule:view')
|
||||
findAll(@Query() query: QueryScheduleDto) {
|
||||
return this.service.findAll(query);
|
||||
}
|
||||
|
||||
@Get('weekly')
|
||||
@RequirePermission('schedule:view')
|
||||
getWeeklyView(@Query() query: WeeklyViewQueryDto) {
|
||||
return this.service.getWeeklyView(query);
|
||||
}
|
||||
|
||||
@Get('classroom/:id/occupancy')
|
||||
@RequirePermission('schedule:view')
|
||||
getClassroomOccupancy(
|
||||
@Param('id') id: string,
|
||||
@Query('date') date?: string,
|
||||
) {
|
||||
return this.service.getClassroomOccupancy(+id, date);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@RequirePermission('schedule:view')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.service.findOne(+id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@RequirePermission('schedule:create')
|
||||
async create(@Body() dto: CreateScheduleDto, @Request() req: { user?: { id: number; username: string }; headers?: Record<string, string> }) {
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
const result = await this.service.create(dto);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '排课管理',
|
||||
action: '创建排课',
|
||||
targetId: result.id,
|
||||
targetType: 'class-schedule',
|
||||
detail: `${result.subject} 周${result.weekDay} ${result.startTime}-${result.endTime}`,
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@RequirePermission('schedule:edit')
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() dto: UpdateScheduleDto,
|
||||
@Request() req: { user?: { id: number; username: string }; headers?: Record<string, string> },
|
||||
) {
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
const result = await this.service.update(+id, dto);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '排课管理',
|
||||
action: '编辑排课',
|
||||
targetId: +id,
|
||||
targetType: 'class-schedule',
|
||||
detail: JSON.stringify(dto),
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@RequirePermission('schedule:delete')
|
||||
async remove(@Param('id') id: string, @Request() req: { user?: { id: number; username: string }; headers?: Record<string, string> }) {
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
const result = await this.service.remove(+id);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '排课管理',
|
||||
action: '删除排课',
|
||||
targetId: +id,
|
||||
targetType: 'class-schedule',
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user