import { Controller, Get, Post, Delete, Body, Param, Query, BadRequestException } from '@nestjs/common'; import { FFBProduction } from './ffb-production.schema'; import { FFBProductionService } from './services/ffb-production.service'; import { FFBLangChainService } from './services/ffb-langchain.service'; @Controller('ffb-production') export class FFBProductionController { constructor( private readonly ffbService: FFBProductionService, private readonly ffbLangChainService: FFBLangChainService, ) { } @Post('chat') async query(@Body('message') message: string, @Body('provider') provider?: 'openai' | 'gemini') { if (!message) { throw new BadRequestException('Message is required'); } const response = await this.ffbLangChainService.chatStateless(message, provider); return { response }; } /** Vector search endpoint */ @Get('search') async search(@Query('q') q: string, @Query('k') k?: string) { console.log(`GET /ffb-production/search?q=${q}&k=${k}`); const topK = k ? parseInt(k, 10) : 5; return this.ffbService.search(q, topK); } /** Create a new FFB production record (with embedding) */ @Post() async create(@Body() body: FFBProduction) { console.log('POST /ffb-production'); return this.ffbService.create(body); } /** Find all records */ @Get() async findAll(@Query() query: any) { console.log('GET /ffb-production', query); // Extract pagination parameters const page = query.page ? parseInt(query.page, 10) : 1; const limit = query.limit ? parseInt(query.limit, 10) : 10; // Clean query object (remove page and limit from filters) const filter = { ...query }; delete filter.page; delete filter.limit; return this.ffbService.findAll(filter, { page, limit }); } /** Find a record by ID */ @Get(':id') async findById(@Param('id') id: string) { console.log(`GET /ffb-production/${id}`); return this.ffbService.findById(id); } /** Delete a record by ID */ @Delete(':id') async delete(@Param('id') id: string) { console.log(`DELETE /ffb-production/${id}`); return this.ffbService.delete(id); } /** Generate simple remark string (stateless) */ @Post('generate-remark') async generateRemarks(@Body() body: any) { console.log(`POST /ffb-production/generate-remark`); const remark = await this.ffbService.generateRemarks(body); return { remark }; } @Post('generate-issues') async generateIssues(@Body() body: any) { console.log(`POST /ffb-production/generate-issues`); const issues = await this.ffbService.generateIssues(body); return { issues }; } }