feat: 完成分类、worksheet 接口开发,资源迁移到七牛
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Query,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import type {
|
||||
AdminResourcePage,
|
||||
AdminWorksheet,
|
||||
AdminWorksheetPage,
|
||||
AdminWorksheetResource,
|
||||
ApiSuccess,
|
||||
ContentPublication,
|
||||
} from '@doodle/contracts';
|
||||
import { CurrentUser, Roles } from '../auth/auth.decorators';
|
||||
import type { AuthenticatedUser, HttpRequest } from '../common/http-request';
|
||||
import { WorksheetService } from '../worksheets/worksheet.service';
|
||||
import {
|
||||
AdminResourceQueryDto,
|
||||
AdminWorksheetQueryDto,
|
||||
UpdateContentStatusDto,
|
||||
} from './content.dto';
|
||||
import { PublicationService } from './publication.service';
|
||||
import { ResourcePreviewService } from './resource-preview.service';
|
||||
|
||||
@Controller('admin/worksheets')
|
||||
@ApiTags('admin/worksheets')
|
||||
@Roles('admin')
|
||||
/** 管理预览使用本站 JWT 与当前管理员身份,不接受客户端自报测试身份。 */
|
||||
export class AdminWorksheetController {
|
||||
constructor(
|
||||
private readonly worksheets: WorksheetService,
|
||||
private readonly publication: PublicationService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: '全部状态题型(管理员,支持状态及原有筛选)' })
|
||||
async list(
|
||||
@Query() query: AdminWorksheetQueryDto,
|
||||
): Promise<ApiSuccess<AdminWorksheetPage>> {
|
||||
return {
|
||||
code: 0,
|
||||
message: 'ok',
|
||||
data: await this.worksheets.listForAdmin(query),
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: '题型管理预览(管理员,包含草稿及有效可见性)' })
|
||||
async get(@Param('id') id: string): Promise<ApiSuccess<AdminWorksheet>> {
|
||||
return {
|
||||
code: 0,
|
||||
message: 'ok',
|
||||
data: await this.worksheets.getForAdmin(id),
|
||||
};
|
||||
}
|
||||
|
||||
@Patch(':id/status')
|
||||
@ApiOperation({
|
||||
summary: '题型发布、下架或转草稿(管理员);发布要求分类已上线',
|
||||
})
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() input: UpdateContentStatusDto,
|
||||
@CurrentUser() actor: AuthenticatedUser,
|
||||
@Req() request: HttpRequest,
|
||||
): Promise<ApiSuccess<ContentPublication>> {
|
||||
return {
|
||||
code: 0,
|
||||
message: 'ok',
|
||||
data: await this.publication.update(
|
||||
'worksheet',
|
||||
id,
|
||||
input,
|
||||
actor,
|
||||
request.requestId!,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Controller('admin/worksheet-resources')
|
||||
@ApiTags('admin/worksheet-resources')
|
||||
@Roles('admin')
|
||||
/** 资源公开列表尚未开放;管理预览和上下架先落实同一发布规则。 */
|
||||
export class AdminResourceController {
|
||||
constructor(
|
||||
private readonly resources: ResourcePreviewService,
|
||||
private readonly publication: PublicationService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: '分页查询资源(管理员,支持 worksheetId/status)',
|
||||
})
|
||||
async list(
|
||||
@Query() query: AdminResourceQueryDto,
|
||||
): Promise<ApiSuccess<AdminResourcePage>> {
|
||||
return {
|
||||
code: 0,
|
||||
message: 'ok',
|
||||
data: await this.resources.list(query),
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: '资源管理预览(管理员,包含草稿及有效可见性)' })
|
||||
async get(
|
||||
@Param('id') id: string,
|
||||
): Promise<ApiSuccess<AdminWorksheetResource>> {
|
||||
return { code: 0, message: 'ok', data: await this.resources.get(id) };
|
||||
}
|
||||
|
||||
@Patch(':id/status')
|
||||
@ApiOperation({
|
||||
summary: '资源发布、下架或转草稿(管理员);发布要求题型及分类已上线',
|
||||
})
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() input: UpdateContentStatusDto,
|
||||
@CurrentUser() actor: AuthenticatedUser,
|
||||
@Req() request: HttpRequest,
|
||||
): Promise<ApiSuccess<ContentPublication>> {
|
||||
return {
|
||||
code: 0,
|
||||
message: 'ok',
|
||||
data: await this.publication.update(
|
||||
'resource',
|
||||
id,
|
||||
input,
|
||||
actor,
|
||||
request.requestId!,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user