diff --git a/app/backend/src/modules/application/application.controller.ts b/app/backend/src/modules/application/application.controller.ts index cef915b..8c251bc 100644 --- a/app/backend/src/modules/application/application.controller.ts +++ b/app/backend/src/modules/application/application.controller.ts @@ -1,11 +1,12 @@ import { QueryApplicationsResponseDTO } from './dto/query-applications-response.dto' -import { Body, Controller, Delete, Get, Param, Put, Query } from '@nestjs/common' +import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common' import { ApplicationService } from './application.service' import { RegisterApplicationDTO } from './dto/register-application.dto' import { QueryApplicationsDTO } from './dto/query-applications.dto' import { Application } from './entity/application.entity' import { ApiInternalServerErrorResponse, ApiOperation, ApiTags } from '@nestjs/swagger' import { EntityManager } from '@mikro-orm/core' +import { CreateApplicationDTO } from './dto/create-application.dto' @ApiTags('Application') @@ -25,6 +26,14 @@ export class ApplicationController { await this.applicationService.register(dto) } + @Post() + @ApiOperation({ summary: '创建应用' }) + async createApplication( + @Body() dto: CreateApplicationDTO, + ): Promise { + return await this.applicationService.create(dto) + } + @Get() @ApiOperation({ summary: '查询应用列表' }) async queryApplications( diff --git a/app/backend/src/modules/application/application.service.ts b/app/backend/src/modules/application/application.service.ts index f05e42e..f164423 100644 --- a/app/backend/src/modules/application/application.service.ts +++ b/app/backend/src/modules/application/application.service.ts @@ -6,6 +6,7 @@ import { InjectRepository } from '@mikro-orm/nestjs' import { QueryApplicationsDTO } from './dto/query-applications.dto' import { QueryApplicationsResponseDTO } from './dto/query-applications-response.dto' import { EntityRepository } from '@mikro-orm/mysql' +import { CreateApplicationDTO } from './dto/create-application.dto' @Injectable() @@ -38,6 +39,16 @@ export class ApplicationService { await this.em.persistAndFlush(application) } + async create(dto: CreateApplicationDTO): Promise { + const application = this.applicationRepo.create({ + code: dto.code, + title: dto.title || dto.code, + }) + await this.em.persistAndFlush(application) + + return application + } + async queryApplicationByIdOrCode(idOrCode: string): Promise { const app = await this.applicationRepo.findOneOrFail( { diff --git a/app/backend/src/modules/application/dto/create-application.dto.ts b/app/backend/src/modules/application/dto/create-application.dto.ts new file mode 100644 index 0000000..d9c1288 --- /dev/null +++ b/app/backend/src/modules/application/dto/create-application.dto.ts @@ -0,0 +1,7 @@ +import { TakeType } from '@miaooo/nestjs-take-type' +import { Application } from '../entity/application.entity' + + +export class CreateApplicationDTO extends TakeType(Application, ['code'], ['title']) { + +} diff --git a/app/frontend/api/backend/components/schemas/create_application_dto.ts b/app/frontend/api/backend/components/schemas/create_application_dto.ts new file mode 100644 index 0000000..8759a50 --- /dev/null +++ b/app/frontend/api/backend/components/schemas/create_application_dto.ts @@ -0,0 +1,14 @@ +/** + * @interface CreateApplicationDTO + * @export + */ +export interface CreateApplicationDTO { + /** + * 应用名称 + */ + "title"?: string + /** + * 唯一应用编码 + */ + "code": string +} diff --git a/app/frontend/api/backend/components/schemas/index.ts b/app/frontend/api/backend/components/schemas/index.ts index 792773b..a467581 100644 --- a/app/frontend/api/backend/components/schemas/index.ts +++ b/app/frontend/api/backend/components/schemas/index.ts @@ -1,12 +1,12 @@ export * from "./register_api_document_dto" export * from "./application" -export * from "./sdk_publish_lock" export * from "./sdk" export * from "./api_document_file" export * from "./api_document" export * from "./page_dto" export * from "./query_api_documents_response_dto" export * from "./register_application_dto" +export * from "./create_application_dto" export * from "./application_dto" export * from "./query_applications_response_dto" export * from "./example_dto" diff --git a/app/frontend/api/backend/components/schemas/sdk.ts b/app/frontend/api/backend/components/schemas/sdk.ts index 139529f..d8781ae 100644 --- a/app/frontend/api/backend/components/schemas/sdk.ts +++ b/app/frontend/api/backend/components/schemas/sdk.ts @@ -1,6 +1,5 @@ import { ApiDocument } from "./api_document" import { ApiDocumentFile } from "./api_document_file" -import { SdkPublishLock } from "./sdk_publish_lock" /** @@ -20,7 +19,6 @@ export interface Sdk { * 关联的文档文件 */ "apiDocumentFile": ApiDocumentFile - "sdkPublishLock"?: SdkPublishLock "scope": string /** * Npm包名 diff --git a/app/frontend/api/backend/create_application.ts b/app/frontend/api/backend/create_application.ts new file mode 100644 index 0000000..1ab9c3f --- /dev/null +++ b/app/frontend/api/backend/create_application.ts @@ -0,0 +1,35 @@ +import { Keq } from 'keq' +import { request } from 'keq' +import { Application } from "./components/schemas/application" +import { CreateApplicationDTO } from "./components/schemas/create_application_dto" + + +interface ResponseMap { + "201": Application + "500": unknown +} + + +interface QueryArg { +} + +interface ParamArg { +} + +interface HeaderArg { +} + + +export function createApplication(arg?: QueryArg & ParamArg & HeaderArg & (CreateApplicationDTO)): Keq { + const req = request.post + ("/api/application") + .option('module', { + name: "backend", + pathname: "/api/application", + }) + + if (arg && "title" in arg) req.send({ "title": arg["title"] }) + if (arg && "code" in arg) req.send({ "code": arg["code"] }) + + return req +} diff --git a/app/frontend/api/backend/index.ts b/app/frontend/api/backend/index.ts index e937975..30962eb 100644 --- a/app/frontend/api/backend/index.ts +++ b/app/frontend/api/backend/index.ts @@ -11,6 +11,7 @@ export * from "./query_sdk_by_api_document_id" export * from "./query_sdk_by_version" export * from "./query_api_document_files" export * from "./register_application" +export * from "./create_application" export * from "./query_applications" export * from "./query_application" export * from "./delete_application" diff --git a/app/frontend/components/application/create-modal.vue b/app/frontend/components/application/create-modal.vue new file mode 100644 index 0000000..18b0c42 --- /dev/null +++ b/app/frontend/components/application/create-modal.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/app/frontend/pages/applications.vue b/app/frontend/pages/applications.vue index d51c0ae..0cdf3b4 100644 --- a/app/frontend/pages/applications.vue +++ b/app/frontend/pages/applications.vue @@ -14,7 +14,7 @@ const pagination = reactive({ offset: 0, }) -const { pending } = useAsyncData( +const { pending, refresh } = useAsyncData( async () => { const body = await queryApplications<'200'>({ limit: pagination.limit, @@ -26,49 +26,60 @@ const { pending } = useAsyncData( }, ) +const showCreateModal = ref(false)