Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x | import {
Controller,
Get,
Post,
Body,
Param,
Put,
Delete,
ParseUUIDPipe,
HttpCode,
HttpStatus,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger';
import { ContextSnippetsService } from './context-snippets.service';
import {
CreateContextSnippetDto,
PreviewContextSnippetDto,
PreviewContextSnippetResponseDto,
UpdateContextSnippetDto,
} from './dto/context-snippet.dto';
import { ContextSnippet } from '../core-entities';
/**
* Context snippets are reusable Eta template blocks for context generation.
*
* Use these to define frequently-needed context blocks (like git status, package info)
* that can be included in templates via it.snippets.handle.
*
* Example: A snippet with handle 'git-status' can be used in templates as:
* <%= it.snippets['git-status'] %>
*/
@ApiTags('context-snippets')
@Controller('context-snippets')
export class ContextSnippetsController {
constructor(
private readonly contextSnippetsService: ContextSnippetsService,
) {}
@Post()
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'Create a context snippet' })
@ApiResponse({
status: 201,
description: 'Snippet created',
type: ContextSnippet,
})
async create(
@Body() createDto: CreateContextSnippetDto,
): Promise<ContextSnippet> {
return this.contextSnippetsService.create(createDto);
}
@Post('preview-output')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Preview rendered snippet output' })
@ApiResponse({ status: 200, description: 'Rendered snippet' })
async preview(
@Body() previewDto: PreviewContextSnippetDto,
): Promise<PreviewContextSnippetResponseDto> {
return this.contextSnippetsService.preview(previewDto);
}
@Get()
@ApiOperation({ summary: 'List all context snippets' })
@ApiResponse({
status: 200,
description: 'List of snippets',
type: [ContextSnippet],
})
async findAll(): Promise<ContextSnippet[]> {
return this.contextSnippetsService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get a context snippet by ID' })
@ApiParam({ name: 'id', description: 'Snippet UUID', format: 'uuid' })
@ApiResponse({
status: 200,
description: 'Snippet found',
type: ContextSnippet,
})
@ApiResponse({ status: 404, description: 'Snippet not found' })
async findOne(
@Param('id', ParseUUIDPipe) id: string,
): Promise<ContextSnippet> {
return this.contextSnippetsService.findOne(id);
}
@Put(':id')
@ApiOperation({ summary: 'Update a context snippet' })
@ApiParam({ name: 'id', description: 'Snippet UUID', format: 'uuid' })
@ApiResponse({
status: 200,
description: 'Snippet updated',
type: ContextSnippet,
})
@ApiResponse({ status: 404, description: 'Snippet not found' })
async update(
@Param('id', ParseUUIDPipe) id: string,
@Body() updateDto: UpdateContextSnippetDto,
): Promise<ContextSnippet> {
return this.contextSnippetsService.update(id, updateDto);
}
@Delete(':id')
@HttpCode(HttpStatus.NO_CONTENT)
@ApiOperation({ summary: 'Delete a context snippet' })
@ApiParam({ name: 'id', description: 'Snippet UUID', format: 'uuid' })
@ApiResponse({ status: 204, description: 'Snippet deleted' })
@ApiResponse({ status: 404, description: 'Snippet not found' })
async remove(@Param('id', ParseUUIDPipe) id: string): Promise<void> {
return this.contextSnippetsService.remove(id);
}
}
|