import { Body, Controller, Delete, Get, HttpCode, Param, ParseUUIDPipe, Patch, Post, Query, } from "@nestjs/common"; import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; import { PaginationQueryDto } from "../common/dto/pagination.dto"; import { CreateEnvironmentDto } from "./dto/create-environment.dto"; import { EnvironmentExportDto } from "./dto/environment-export.dto"; import { UpdateEnvironmentDto } from "./dto/update-environment.dto"; import { EnvironmentOrderBy, EnvironmentService } from "./environment.service"; @ApiTags("environments") @Controller("environments") export class EnvironmentController { constructor(private readonly environmentService: EnvironmentService) {} @Post() @ApiOperation({ summary: "Create a new environment" }) @ApiResponse({ status: 201, description: "Environment created" }) @ApiResponse({ status: 409, description: "Environment name already exists" }) create(@Body() dto: CreateEnvironmentDto) { return this.environmentService.create(dto); } @Post("import") @ApiOperation({ summary: "Import an environment (upsert by id or name)" }) @ApiResponse({ status: 201, description: "Environment imported" }) async importEnvironment(@Body() dto: EnvironmentExportDto) { return this.environmentService.importEnvironment(dto); } @Get() @ApiOperation({ summary: "List all environments (paginated)" }) @ApiResponse({ status: 200, description: "Paginated environments" }) findAll(@Query() query: PaginationQueryDto) { return this.environmentService.findAll(query); } @Get(":id/export") @ApiOperation({ summary: "Export an environment as a plain object" }) @ApiResponse({ status: 200, description: "Environment export payload" }) @ApiResponse({ status: 404, description: "Environment not found" }) async exportEnvironment(@Param("id", ParseUUIDPipe) id: string) { const env = await this.environmentService.findOne(id); return this.environmentService.exportEnvironment(env); } @Get(":id") @ApiOperation({ summary: "Get environment by ID" }) @ApiResponse({ status: 200, description: "Environment record" }) @ApiResponse({ status: 404, description: "Environment not found" }) findOne(@Param("id", ParseUUIDPipe) id: string) { return this.environmentService.findOne(id); } @Patch(":id") @ApiOperation({ summary: "Update an environment" }) @ApiResponse({ status: 200, description: "Environment updated" }) @ApiResponse({ status: 404, description: "Environment not found" }) update( @Param("id", ParseUUIDPipe) id: string, @Body() dto: UpdateEnvironmentDto, ) { return this.environmentService.update(id, dto); } @Delete(":id") @HttpCode(204) @ApiOperation({ summary: "Delete an environment" }) @ApiResponse({ status: 204, description: "Environment deleted" }) @ApiResponse({ status: 404, description: "Environment not found" }) remove(@Param("id", ParseUUIDPipe) id: string) { return this.environmentService.remove(id); } }