Files
liqa/server/src/snippet/snippet.controller.ts
T
ars9 ff83b6c7da feat(versioning): version scenarios and snippets, bump to 1.16.0
- snapshot scenario and snippet content into version tables on every
  content change; live tables keep holding the latest version
- record the scenario version on each run and copy its steps into the
  run steps, so runs execute and show the version they were created with
- keep run step history when a step is deleted (FK set null)
- pin a snippet version with runSnippet('alias@N')
- add version picker to the run modal and version info across the UI
- add version list/get endpoints and MCP tools
- include version in exports and require it on import, restoring the
  exact version by id + version
2026-09-30 15:24:44 +03:00

108 lines
3.6 KiB
TypeScript

import {
Body,
Controller,
Delete,
Get,
HttpCode,
Param,
ParseIntPipe,
ParseUUIDPipe,
Patch,
Post,
Query,
} from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { SnippetQueryDto } from "./dto/snippet-query.dto";
import { CreateSnippetDto } from "./dto/create-snippet.dto";
import { SnippetExportDto } from "./dto/snippet-export.dto";
import { UpdateSnippetDto } from "./dto/update-snippet.dto";
import { SnippetService } from "./snippet.service";
@ApiTags("snippets")
@Controller("snippets")
export class SnippetController {
constructor(private readonly snippetService: SnippetService) {}
@Post()
@ApiOperation({ summary: "Create a new snippet" })
@ApiResponse({ status: 201, description: "Snippet created" })
@ApiResponse({ status: 409, description: "Alias already taken" })
create(@Body() dto: CreateSnippetDto) {
return this.snippetService.create(dto);
}
@Post("import")
@ApiOperation({ summary: "Import a snippet (upsert by id)" })
@ApiResponse({ status: 201, description: "Snippet imported" })
async importSnippet(@Body() dto: SnippetExportDto) {
return this.snippetService.importSnippet(dto);
}
@Get()
@ApiOperation({ summary: "List all snippets (paginated)" })
@ApiResponse({ status: 200, description: "Paginated snippets" })
findAll(@Query() query: SnippetQueryDto) {
return this.snippetService.findAll(query);
}
@Get(":id/export")
@ApiOperation({ summary: "Export a snippet as a plain object" })
@ApiResponse({ status: 200, description: "Snippet export payload" })
@ApiResponse({ status: 404, description: "Snippet not found" })
async exportSnippet(
@Param("id", ParseUUIDPipe) id: string,
@Query("version", new ParseIntPipe({ optional: true })) version?: number,
) {
const snippet = await this.snippetService.findOne(id);
return this.snippetService.exportSnippet(snippet, version);
}
@Get(":id/versions")
@ApiOperation({ summary: "List a snippet's versions, newest first" })
@ApiResponse({ status: 200, description: "Snippet versions" })
@ApiResponse({ status: 404, description: "Snippet not found" })
listVersions(@Param("id", ParseUUIDPipe) id: string) {
return this.snippetService.listVersions(id);
}
@Get(":id/versions/:version")
@ApiOperation({ summary: "Get one version of a snippet" })
@ApiResponse({ status: 200, description: "Snippet version" })
@ApiResponse({ status: 404, description: "Snippet or version not found" })
findVersion(
@Param("id", ParseUUIDPipe) id: string,
@Param("version", ParseIntPipe) version: number,
) {
return this.snippetService.findVersion(id, version);
}
@Get(":id")
@ApiOperation({ summary: "Get snippet by ID" })
@ApiResponse({ status: 200, description: "Snippet record" })
@ApiResponse({ status: 404, description: "Snippet not found" })
findOne(@Param("id", ParseUUIDPipe) id: string) {
return this.snippetService.findOne(id);
}
@Patch(":id")
@ApiOperation({ summary: "Update a snippet" })
@ApiResponse({ status: 200, description: "Snippet updated" })
@ApiResponse({ status: 404, description: "Snippet not found" })
@ApiResponse({ status: 409, description: "Alias already taken" })
update(
@Param("id", ParseUUIDPipe) id: string,
@Body() dto: UpdateSnippetDto,
) {
return this.snippetService.update(id, dto);
}
@Delete(":id")
@HttpCode(204)
@ApiOperation({ summary: "Delete a snippet" })
@ApiResponse({ status: 204, description: "Snippet deleted" })
@ApiResponse({ status: 404, description: "Snippet not found" })
remove(@Param("id", ParseUUIDPipe) id: string) {
return this.snippetService.remove(id);
}
}