Spaces:
Runtime error
Runtime error
File size: 1,665 Bytes
2f0bbdc | 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 | 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);
}
}
|