后端: - 新增 Teacher、Student、Class 模块及 CRUD 接口 - 新增 ClassTeacher 多对多关系支持任课教师管理 - Student 支持班级关联查询 - Class 支持班主任一对一和任课教师多对多关系 - 更新 Prisma schema 和种子数据 前端: - 新增教师、学生、班级管理页面 - 新增对应的 hooks 和 services - 更新路由常量和 hooks 导出 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
90 lines
2.4 KiB
TypeScript
90 lines
2.4 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Param,
|
|
Query,
|
|
Body,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiBearerAuth,
|
|
ApiOkResponse,
|
|
ApiCreatedResponse,
|
|
} from '@nestjs/swagger';
|
|
|
|
import { ClassService } from './class.service';
|
|
import {
|
|
CreateClassDto,
|
|
UpdateClassDto,
|
|
AssignTeachersDto,
|
|
ClassQueryDto,
|
|
ClassResponseDto,
|
|
ClassDetailResponseDto,
|
|
PaginatedClassResponseDto,
|
|
TeacherBriefDto,
|
|
} from './dto/class.dto';
|
|
|
|
import { JwtAuthGuard } from '@/auth/guards/jwt-auth.guard';
|
|
|
|
@ApiTags('班级管理')
|
|
@Controller('classes')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
export class ClassController {
|
|
constructor(private readonly classService: ClassService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: '获取班级列表' })
|
|
@ApiOkResponse({ type: PaginatedClassResponseDto, description: '班级列表' })
|
|
findAll(@Query() query: ClassQueryDto) {
|
|
return this.classService.findAllWithRelations(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: '获取班级详情' })
|
|
@ApiOkResponse({ type: ClassDetailResponseDto, description: '班级详情(包含任课教师和学生数量)' })
|
|
findById(@Param('id') id: string) {
|
|
return this.classService.findByIdWithDetails(id);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: '创建班级' })
|
|
@ApiCreatedResponse({ type: ClassResponseDto, description: '创建成功' })
|
|
create(@Body() dto: CreateClassDto) {
|
|
return this.classService.create(dto);
|
|
}
|
|
|
|
@Put(':id')
|
|
@ApiOperation({ summary: '更新班级' })
|
|
@ApiOkResponse({ type: ClassResponseDto, description: '更新成功' })
|
|
update(@Param('id') id: string, @Body() dto: UpdateClassDto) {
|
|
return this.classService.update(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: '删除班级' })
|
|
@ApiOkResponse({ description: '删除成功' })
|
|
delete(@Param('id') id: string) {
|
|
return this.classService.delete(id);
|
|
}
|
|
|
|
@Get(':id/teachers')
|
|
@ApiOperation({ summary: '获取班级任课教师列表' })
|
|
@ApiOkResponse({ type: [TeacherBriefDto], description: '任课教师列表' })
|
|
getTeachers(@Param('id') id: string) {
|
|
return this.classService.getTeachers(id);
|
|
}
|
|
|
|
@Put(':id/teachers')
|
|
@ApiOperation({ summary: '分配任课教师' })
|
|
@ApiOkResponse({ type: ClassDetailResponseDto, description: '分配成功' })
|
|
assignTeachers(@Param('id') id: string, @Body() dto: AssignTeachersDto) {
|
|
return this.classService.assignTeachers(id, dto);
|
|
}
|
|
}
|