All files / src/custom-snippets custom-snippets.controller.ts

71.42% Statements 15/21
100% Branches 0/0
14.28% Functions 1/7
68.42% Lines 13/19

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 116 117 118 119 1206x                       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 { CustomSnippetsService } from './custom-snippets.service';
import {
  CreateCustomSnippetDto,
  UpdateCustomSnippetDto,
} from './dto/custom-snippet.dto';
import { CustomSnippet } from '../core-entities';
 
/**
 * Custom snippets are text expansion templates triggered by a prefix.
 *
 * Similar to VS Code snippets - type the prefix to expand into the body.
 * Use for frequently-used code patterns, templates, or prompt structures.
 *
 * Example: A snippet with prefix 'auth-module' expands into a full auth module template.
 */
@ApiTags('custom-snippets')
@Controller('custom-snippets')
export class CustomSnippetsController {
  constructor(private readonly customSnippetsService: CustomSnippetsService) {}
 
  @Post()
  @HttpCode(HttpStatus.CREATED)
  @ApiOperation({ summary: 'Create a custom snippet' })
  @ApiResponse({
    status: 201,
    description: 'Snippet created',
    type: CustomSnippet,
  })
  async create(
    @Body() createCustomSnippetDto: CreateCustomSnippetDto,
  ): Promise<CustomSnippet> {
    return this.customSnippetsService.create(createCustomSnippetDto);
  }
 
  @Get()
  @ApiOperation({ summary: 'List all custom snippets' })
  @ApiResponse({
    status: 200,
    description: 'List of snippets',
    type: [CustomSnippet],
  })
  async findAll(): Promise<CustomSnippet[]> {
    return this.customSnippetsService.findAll();
  }
 
  @Get(':id')
  @ApiOperation({ summary: 'Get a custom snippet by ID' })
  @ApiParam({ name: 'id', description: 'Snippet UUID', format: 'uuid' })
  @ApiResponse({
    status: 200,
    description: 'Snippet found',
    type: CustomSnippet,
  })
  @ApiResponse({ status: 404, description: 'Snippet not found' })
  async findOne(
    @Param('id', ParseUUIDPipe) id: string,
  ): Promise<CustomSnippet> {
    return this.customSnippetsService.findOne(id);
  }
 
  @Put(':id')
  @ApiOperation({ summary: 'Update a custom snippet' })
  @ApiParam({ name: 'id', description: 'Snippet UUID', format: 'uuid' })
  @ApiResponse({
    status: 200,
    description: 'Snippet updated',
    type: CustomSnippet,
  })
  @ApiResponse({ status: 404, description: 'Snippet not found' })
  async update(
    @Param('id', ParseUUIDPipe) id: string,
    @Body() updateCustomSnippetDto: UpdateCustomSnippetDto,
  ): Promise<CustomSnippet> {
    return this.customSnippetsService.update(id, updateCustomSnippetDto);
  }
 
  @Delete(':id')
  @HttpCode(HttpStatus.NO_CONTENT)
  @ApiOperation({ summary: 'Delete a custom 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.customSnippetsService.remove(id);
  }
 
  @Post(':id/duplicate')
  @HttpCode(HttpStatus.CREATED)
  @ApiOperation({ summary: 'Duplicate a custom snippet' })
  @ApiParam({
    name: 'id',
    description: 'Snippet UUID to duplicate',
    format: 'uuid',
  })
  @ApiResponse({
    status: 201,
    description: 'Snippet duplicated',
    type: CustomSnippet,
  })
  @ApiResponse({ status: 404, description: 'Snippet not found' })
  async duplicate(
    @Param('id', ParseUUIDPipe) id: string,
  ): Promise<CustomSnippet> {
    return this.customSnippetsService.duplicate(id);
  }
}