111 lines
4.5 KiB
TypeScript
111 lines
4.5 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
Patch,
|
|
Param,
|
|
Delete,
|
|
Query,
|
|
ParseIntPipe,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
|
import { ReadingMaterialsService } from '../services/reading-materials.service';
|
|
import { CreateReadingMaterialDto } from '../dto/create-reading-material.dto';
|
|
import { UpdateReadingMaterialDto } from '../dto/update-reading-material.dto';
|
|
import { ReadingMaterialResponseDto } from '../dto/reading-material-response.dto';
|
|
import { PaginationDto } from '../../../common/dto/pagination.dto';
|
|
|
|
@ApiTags('reading-materials')
|
|
@Controller('reading-materials')
|
|
export class ReadingMaterialsController {
|
|
constructor(private readonly readingMaterialsService: ReadingMaterialsService) {}
|
|
|
|
@Post()
|
|
// @UseGuards(JwtAuthGuard, RolesGuard)
|
|
// @Roles('ADMIN', 'HR')
|
|
// @ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Create a new reading material' })
|
|
@ApiResponse({ status: 201, description: 'Reading material created successfully', type: ReadingMaterialResponseDto })
|
|
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
@ApiResponse({ status: 403, description: 'Forbidden' })
|
|
async create(@Body() createReadingMaterialDto: CreateReadingMaterialDto): Promise<ReadingMaterialResponseDto> {
|
|
return this.readingMaterialsService.create(createReadingMaterialDto);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get all reading materials with pagination' })
|
|
@ApiResponse({ status: 200, description: 'Reading materials retrieved successfully' })
|
|
async findAll(@Query() paginationDto: PaginationDto) {
|
|
return this.readingMaterialsService.findAll(paginationDto);
|
|
}
|
|
|
|
@Get('search/title')
|
|
@ApiOperation({ summary: 'Search reading materials by title' })
|
|
@ApiResponse({ status: 200, description: 'Reading materials retrieved successfully' })
|
|
async searchByTitle(
|
|
@Query('q') title: string,
|
|
@Query() paginationDto: PaginationDto,
|
|
) {
|
|
return this.readingMaterialsService.searchByTitle(title, paginationDto);
|
|
}
|
|
|
|
@Get('search/description')
|
|
@ApiOperation({ summary: 'Search reading materials by description' })
|
|
@ApiResponse({ status: 200, description: 'Reading materials retrieved successfully' })
|
|
async searchByDescription(
|
|
@Query('q') description: string,
|
|
@Query() paginationDto: PaginationDto,
|
|
) {
|
|
return this.readingMaterialsService.searchByDescription(description, paginationDto);
|
|
}
|
|
|
|
@Get('tag/:tag')
|
|
@ApiOperation({ summary: 'Get reading materials by tag' })
|
|
@ApiResponse({ status: 200, description: 'Reading materials retrieved successfully' })
|
|
async findByTag(
|
|
@Param('tag') tag: string,
|
|
@Query() paginationDto: PaginationDto,
|
|
) {
|
|
return this.readingMaterialsService.findByTag(tag, paginationDto);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get reading material by ID' })
|
|
@ApiResponse({ status: 200, description: 'Reading material retrieved successfully', type: ReadingMaterialResponseDto })
|
|
@ApiResponse({ status: 404, description: 'Reading material not found' })
|
|
async findOne(@Param('id', ParseIntPipe) id: number): Promise<ReadingMaterialResponseDto> {
|
|
return this.readingMaterialsService.findOne(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
// @UseGuards(JwtAuthGuard, RolesGuard)
|
|
// @Roles('ADMIN', 'HR')
|
|
// @ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Update reading material' })
|
|
@ApiResponse({ status: 200, description: 'Reading material updated successfully', type: ReadingMaterialResponseDto })
|
|
@ApiResponse({ status: 404, description: 'Reading material not found' })
|
|
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
@ApiResponse({ status: 403, description: 'Forbidden' })
|
|
async update(
|
|
@Param('id', ParseIntPipe) id: number,
|
|
@Body() updateReadingMaterialDto: UpdateReadingMaterialDto,
|
|
): Promise<ReadingMaterialResponseDto> {
|
|
return this.readingMaterialsService.update(id, updateReadingMaterialDto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
// @UseGuards(JwtAuthGuard, RolesGuard)
|
|
// @Roles('ADMIN', 'HR')
|
|
// @ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Delete reading material (soft delete)' })
|
|
@ApiResponse({ status: 200, description: 'Reading material deleted successfully' })
|
|
@ApiResponse({ status: 404, description: 'Reading material not found' })
|
|
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
@ApiResponse({ status: 403, description: 'Forbidden' })
|
|
async remove(@Param('id', ParseIntPipe) id: number): Promise<{ message: string }> {
|
|
await this.readingMaterialsService.remove(id);
|
|
return { message: 'Reading material deleted successfully' };
|
|
}
|
|
}
|