import { Body, Controller, Delete, Get, Post, Query } from '@nestjs/common'; import { ApiBody, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger'; import { CarreraProgramaService } from './carrera-programa.service'; import { CarreraProgramaCreateDto } from './dto/carrera-programa-create.dto'; import { CarreraProgramaDeleteDto } from './dto/carrera-programa-delete.dto'; import { IdInstitucionDto } from '../dto/id-institucion.dto'; @Controller('carrera-programa') @ApiTags('carrera-programa') export class CarreraProgramaController { constructor(private carreraProgramaService: CarreraProgramaService) {} @Post() @ApiOperation({ description: 'Endpoint que crea una asociación entra una carrera y un programa.', }) @ApiBody({ description: 'Ambas variables son obligatorios.', examples: { ejemplo: { value: { id_institucion_carrera: 36, id_programa: 1 } }, }, }) create(@Body() body: CarreraProgramaCreateDto) { return this.carreraProgramaService.create( body.id_institucion_carrera, body.id_programa, ); } @Delete() @ApiOperation({ description: 'Endpoint que borra la asociación entre una carrera y un programa.', }) @ApiBody({ description: 'Es obligatorio mandar la variable id_carrera_programa.', examples: { ejemplo: { value: { id_carrera_programa: 1 } } }, }) delete(@Body() body: CarreraProgramaDeleteDto) { return this.carreraProgramaService.delete(body.id_carrera_programa); } @Get() @ApiOperation({ description: 'Endpoint que retorna todos los programas reservados para una carrera de una institución.', }) @ApiQuery({ description: 'Id de la institución.', name: 'id_institucion', type: 'string', }) get(@Query() query: IdInstitucionDto) { return this.carreraProgramaService.findByIdInstitucion( parseInt(query.id_institucion), ); } }