feat: Phase 1-3 全部完成 — 沙盒增强、学情分析、学习路径
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { Controller, Post, Get, Put, Body, UseGuards, Req, Param } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { AdminService } from './admin.service';
|
||||
import { AdminGuard } from './admin.guard';
|
||||
import { CoursesService } from '../courses/courses.service';
|
||||
import { PrismaService } from '../../prisma/prisma.service';
|
||||
|
||||
@ApiTags('管理后台')
|
||||
@Controller('admin')
|
||||
export class AdminController {
|
||||
constructor(
|
||||
private adminService: AdminService,
|
||||
private coursesService: CoursesService,
|
||||
private prisma: PrismaService,
|
||||
) {}
|
||||
|
||||
@Post('login')
|
||||
async login(@Body() body: { username: string; password: string }) {
|
||||
return this.adminService.login(body.username, body.password);
|
||||
}
|
||||
|
||||
@Get('dashboard')
|
||||
@UseGuards(AuthGuard('jwt'), AdminGuard)
|
||||
@ApiBearerAuth()
|
||||
async dashboard() {
|
||||
return this.adminService.getDashboard();
|
||||
}
|
||||
|
||||
@Get('orders')
|
||||
@UseGuards(AuthGuard('jwt'), AdminGuard)
|
||||
@ApiBearerAuth()
|
||||
async orders(@Req() req: any) {
|
||||
const items = await this.prisma.order.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 100,
|
||||
include: { user: { select: { id: true, nickname: true, phone: true } } },
|
||||
});
|
||||
return { items };
|
||||
}
|
||||
|
||||
@Put('courses/:id/chapters')
|
||||
@UseGuards(AuthGuard('jwt'), AdminGuard)
|
||||
@ApiBearerAuth()
|
||||
async updateCourseChapters(@Param('id') id: string, @Body() body: any) {
|
||||
return this.coursesService.updateWithChapters(+id, body);
|
||||
}
|
||||
|
||||
@Get('comments/pending')
|
||||
@UseGuards(AuthGuard('jwt'), AdminGuard)
|
||||
@ApiBearerAuth()
|
||||
async pendingComments() {
|
||||
const items = await this.prisma.comment.findMany({
|
||||
where: { status: 'PENDING_REVIEW' },
|
||||
include: {
|
||||
user: { select: { id: true, nickname: true, avatar: true } },
|
||||
post: { select: { id: true, title: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 50,
|
||||
});
|
||||
return { items };
|
||||
}
|
||||
|
||||
@Put('comments/:id/approve')
|
||||
@UseGuards(AuthGuard('jwt'), AdminGuard)
|
||||
@ApiBearerAuth()
|
||||
async approveComment(@Param('id') id: string) {
|
||||
await this.prisma.comment.update({
|
||||
where: { id: parseInt(id) },
|
||||
data: { status: 'PUBLISHED', reviewedAt: new Date() },
|
||||
});
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@Put('comments/:id/reject')
|
||||
@UseGuards(AuthGuard('jwt'), AdminGuard)
|
||||
@ApiBearerAuth()
|
||||
async rejectComment(@Param('id') id: string, @Body() body: { reason?: string }) {
|
||||
await this.prisma.comment.update({
|
||||
where: { id: parseInt(id) },
|
||||
data: { status: 'REJECTED', reviewNote: body.reason || '违规内容', reviewedAt: new Date() },
|
||||
});
|
||||
return { ok: true };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user