39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { Public } from '../../common/decorators/public.decorator';
|
|
import { Roles } from '../../common/decorators/roles.decorator';
|
|
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
|
import { RolesGuard } from '../../common/guards/roles.guard';
|
|
import { GreetingsService } from './greetings.service';
|
|
|
|
@ApiTags('greetings')
|
|
@Controller('greetings')
|
|
export class GreetingsController {
|
|
constructor(private readonly greetingsService: GreetingsService) {}
|
|
|
|
@Public()
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get all greeting phrases' })
|
|
findAll() {
|
|
return this.greetingsService.findAll();
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('admin')
|
|
@Post()
|
|
@ApiOperation({ summary: 'Add greeting phrase (admin only)' })
|
|
create(@Body('text') text: string) {
|
|
return this.greetingsService.create(text);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('admin')
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: 'Delete greeting phrase (admin only)' })
|
|
delete(@Param('id') id: string) {
|
|
return this.greetingsService.delete(id);
|
|
}
|
|
}
|