import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query, Req } from '@nestjs/common'; import { LinkComponentSourceDto } from '../gitea/dto'; import { AppsService } from './apps.service'; import { CreateAppComponentDto, CreateAppDto, CreateAppReleaseDto, CreateBuildJobDto, CreateDeploymentJobDto, DecommissionAppDto, CreateMigrationJobDto, CreateRuntimeEnvProfileDto, CreateRuntimeEnvVariableDto, CreateRuntimeIngressRuleDto, EnsureRuntimeNamespaceDto, ReplaceBuildEnvVariablesDto, } from './dto'; @Controller('apps') export class AppsController { constructor(private readonly appsService: AppsService) {} @Get() listApps() { return this.appsService.listApps(); } @Post() createApp(@Body() body: CreateAppDto) { return this.appsService.createApp(body); } @Delete(':appId') deleteApp(@Param('appId') appId: string) { return this.appsService.deleteApp(appId); } @Post(':appId/decommission') decommissionApp( @Param('appId') appId: string, @Body() body: DecommissionAppDto, ) { return this.appsService.decommissionApp(appId, body); } @Post(':appId/components') createComponent( @Param('appId') appId: string, @Body() body: CreateAppComponentDto, ) { return this.appsService.createComponent(appId, body); } @Patch('components/:componentId') updateComponent( @Param('componentId') componentId: string, @Body() body: CreateAppComponentDto, ) { return this.appsService.updateComponent(componentId, body); } @Delete('components/:componentId') deleteComponent(@Param('componentId') componentId: string) { return this.appsService.deleteComponent(componentId); } @Get('sources') listSources() { return this.appsService.listSources(); } @Get('builds') listBuildJobs( @Query('appKey') appKey?: string, @Query('page') page?: string, @Query('limit') limit?: string, @Query('since') since?: string, @Query('status') status?: string, @Query('hideReleaseCandidates') hideReleaseCandidates?: string, ) { return this.appsService.listBuildJobs(appKey, page, limit, since, status, hideReleaseCandidates); } @Post('builds') createBuildJob( @Body() body: CreateBuildJobDto, @Req() request: { admin?: { id: string; name: string; email: string } }, ) { return this.appsService.createBuildJob(body, request.admin); } @Patch('builds/:buildJobId/cancel') cancelBuildJob(@Param('buildJobId') buildJobId: string) { return this.appsService.cancelBuildJob(buildJobId); } @Patch('builds/:buildJobId/hide-release-candidate') hideReleaseCandidate(@Param('buildJobId') buildJobId: string) { return this.appsService.hideReleaseCandidate(buildJobId); } @Delete('builds/:buildJobId') deleteBuildJob(@Param('buildJobId') buildJobId: string) { return this.appsService.deleteBuildJob(buildJobId); } @Patch('components/:componentId/source') linkComponentSource( @Param('componentId') componentId: string, @Body() body: LinkComponentSourceDto, ) { return this.appsService.linkComponentSource(componentId, body); } @Get('components/:componentId/build-env') listComponentBuildEnv(@Param('componentId') componentId: string) { return this.appsService.listComponentBuildEnv(componentId); } @Put('components/:componentId/build-env') replaceComponentBuildEnv( @Param('componentId') componentId: string, @Body() body: ReplaceBuildEnvVariablesDto, ) { return this.appsService.replaceComponentBuildEnv(componentId, body); } @Get('releases') listReleases( @Query('appKey') appKey?: string, @Query('page') page?: string, @Query('limit') limit?: string, @Query('since') since?: string, ) { return this.appsService.listReleases(appKey, page, limit, since); } @Post('releases') createRelease( @Body() body: CreateAppReleaseDto, @Req() request: { admin?: { id: string; name: string; email: string } }, ) { return this.appsService.createRelease(body, request.admin); } @Delete('releases/:releaseId') deleteRelease(@Param('releaseId') releaseId: string) { return this.appsService.deleteRelease(releaseId); } @Get('deployments') listDeployments( @Query('appKey') appKey?: string, @Query('page') page?: string, @Query('limit') limit?: string, @Query('since') since?: string, ) { return this.appsService.listDeployments(appKey, page, limit, since); } @Post('deployments') createDeploymentJob( @Body() body: CreateDeploymentJobDto, @Req() request: { admin?: { id: string; name: string; email: string } }, ) { return this.appsService.createDeploymentJob(body, request.admin); } @Get('migrations') listMigrationJobs( @Query('appId') appId?: string, @Query('page') page?: string, @Query('limit') limit?: string, @Query('since') since?: string, ) { return this.appsService.listMigrationJobs(appId, page, limit, since); } @Post('migrations') createMigrationJob( @Body() body: CreateMigrationJobDto, @Req() request: { admin?: { id: string; name: string; email: string } }, ) { return this.appsService.createMigrationJob(body, request.admin); } @Get('runtime-namespaces/:namespace') checkRuntimeNamespace(@Param('namespace') namespace: string) { return this.appsService.checkRuntimeNamespace(namespace); } @Get('runtime-namespaces/:namespace/resources') listRuntimeResources(@Param('namespace') namespace: string) { return this.appsService.listRuntimeResources(namespace); } @Get('runtime-namespaces/:namespace/resources/:kind/:name/yaml') getRuntimeResourceYaml( @Param('namespace') namespace: string, @Param('kind') kind: string, @Param('name') name: string, ) { return this.appsService.getRuntimeResourceYaml(namespace, kind, name); } @Post('runtime-namespaces') ensureRuntimeNamespace(@Body() body: EnsureRuntimeNamespaceDto) { return this.appsService.ensureRuntimeNamespace(body); } @Patch('runtime-deployments/:namespace/:deploymentName/restart') restartRuntimeDeployment( @Param('namespace') namespace: string, @Param('deploymentName') deploymentName: string, ) { return this.appsService.restartRuntimeDeployment(namespace, deploymentName); } @Get('runtime-profiles') listRuntimeProfiles(@Query('appId') appId?: string) { return this.appsService.listRuntimeProfiles(appId); } @Post('runtime-profiles') createRuntimeProfile(@Body() body: CreateRuntimeEnvProfileDto) { return this.appsService.createRuntimeProfile(body); } @Delete('runtime-profiles/:profileId') deleteRuntimeProfile(@Param('profileId') profileId: string) { return this.appsService.deleteRuntimeProfile(profileId); } @Post('runtime-profiles/:profileId/variables') createRuntimeVariable( @Param('profileId') profileId: string, @Body() body: CreateRuntimeEnvVariableDto, ) { return this.appsService.createRuntimeVariable(profileId, body); } @Post('runtime-profiles/:profileId/ingress-rules') createRuntimeIngressRule( @Param('profileId') profileId: string, @Body() body: CreateRuntimeIngressRuleDto, ) { return this.appsService.createRuntimeIngressRule(profileId, body); } @Delete('runtime-profiles/:profileId/ingress-rules/:ruleId') deleteRuntimeIngressRule( @Param('profileId') profileId: string, @Param('ruleId') ruleId: string, ) { return this.appsService.deleteRuntimeIngressRule(profileId, ruleId); } @Delete('runtime-profiles/:profileId/variables/:variableId') deleteRuntimeVariable( @Param('profileId') profileId: string, @Param('variableId') variableId: string, ) { return this.appsService.deleteRuntimeVariable(profileId, variableId); } @Patch('runtime-profiles/:profileId/apply') applyRuntimeProfile(@Param('profileId') profileId: string) { return this.appsService.applyRuntimeProfile(profileId); } }