61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
/**
|
|
* RECIPE CONTROLLER INTEGRATION EXAMPLE
|
|
*
|
|
* This shows how to add import endpoints to your existing recipe controller.
|
|
* Add these methods to backend/src/modules/recipes/recipes.controller.ts
|
|
*/
|
|
|
|
import { Controller, Post, UseInterceptors, UploadedFile, Get } from '@nestjs/common';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { ImportService } from '../import/import.service';
|
|
import { RecipesService } from './recipes.service';
|
|
|
|
@Controller('recipes')
|
|
export class RecipesController {
|
|
constructor(
|
|
private recipesService: RecipesService,
|
|
private importService: ImportService, // Add this
|
|
) {}
|
|
|
|
// ... existing endpoints ...
|
|
|
|
/**
|
|
* Import a recipe from PDF without saving
|
|
* Useful for preview before saving
|
|
*
|
|
* POST /recipes/import/pdf
|
|
* Content-Type: multipart/form-data
|
|
* Body: { file: <PDF-file> }
|
|
*/
|
|
@Post('import/pdf')
|
|
@UseInterceptors(FileInterceptor('file'))
|
|
async importRecipeFromPDF(@UploadedFile() file: Express.Multer.File) {
|
|
return this.importService.importRecipeFromPDF(file);
|
|
}
|
|
|
|
/**
|
|
* Import a recipe from PDF and save it to database
|
|
*
|
|
* POST /recipes/import/pdf/save
|
|
* Content-Type: multipart/form-data
|
|
* Body: { file: <PDF-file> }
|
|
*/
|
|
@Post('import/pdf/save')
|
|
@UseInterceptors(FileInterceptor('file'))
|
|
async importAndSaveRecipe(@UploadedFile() file: Express.Multer.File) {
|
|
const imported = await this.importService.importRecipeFromPDF(file);
|
|
return this.importService.saveImportedRecipe(imported.data);
|
|
}
|
|
|
|
/**
|
|
* Check if import service is available
|
|
* Useful for health monitoring
|
|
*
|
|
* GET /recipes/import/health
|
|
*/
|
|
@Get('import/health')
|
|
async importServiceHealth() {
|
|
return this.importService.checkImportServiceHealth();
|
|
}
|
|
}
|