import { Controller, Get, Post, Delete, Body, Param, Query, HttpCode, HttpStatus, } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiQuery, ApiParam } from '@nestjs/swagger'; import { ShlinkService } from './shlink.service'; import { CreateShortUrlDto } from './dto/shlink.dto'; import { URL_SHORTENER_PROVIDER } from '@prisma/client'; import { LogToDiscord } from 'src/shared/decorators/log-to-discord.decorator'; @ApiTags('Short URL: Shlink') @Controller('short-url/shlink') @LogToDiscord() export class ShlinkController { constructor(private readonly shlinkService: ShlinkService) {} @Post() @ApiOperation({ summary: 'Create a new short URL' }) async createShortUrl(@Body() createDto: CreateShortUrlDto) { return this.shlinkService.createShortUrl(createDto); } @Get() @ApiOperation({ summary: 'Get all short URLs by provider' }) @ApiQuery({ name: 'provider', enum: URL_SHORTENER_PROVIDER, required: false, description: 'Filter by provider (default: SHLINK)', }) async getAllShortUrls(@Query('provider') provider?: URL_SHORTENER_PROVIDER) { return this.shlinkService.getAllShortUrls(provider); } @Get(':id') @ApiOperation({ summary: 'Get a short URL by ID' }) @ApiParam({ name: 'id', description: 'Short URL ID' }) async getShortUrlById(@Param('id') id: string) { return this.shlinkService.getShortUrlById(id); } @Delete(':id') @HttpCode(HttpStatus.OK) @ApiOperation({ summary: 'Delete a short URL' }) @ApiParam({ name: 'id', description: 'Short URL ID' }) async deleteShortUrl(@Param('id') id: string) { return this.shlinkService.deleteShortUrl(id); } }