diff --git a/src/services/recipe/recipes.controller.ts b/src/services/recipe/recipes.controller.ts index afab341..877a1bc 100644 --- a/src/services/recipe/recipes.controller.ts +++ b/src/services/recipe/recipes.controller.ts @@ -23,6 +23,55 @@ import { ApiBody, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; export class RecipesController { constructor(private readonly recipesService: RecipesService) {} + @ApiBody({ type: [String] }) + @ApiOperation({ summary: 'Find all ingredients based on many recipes' }) + @Get('generate-ingredients') + async generateIngredientsList( + @Body() recipeIds: string[], + ): Promise { + try { + return await this.recipesService.generateIngredientsList(recipeIds); + } catch (err) { + throw new HttpException( + { + status: HttpStatus.BAD_REQUEST, + error: 'Error generating ingredients list!', + }, + HttpStatus.BAD_REQUEST, + ); + } + } + + @ApiBody({ + description: "Generate a list of recipes based on the user's budget", + required: true, + schema: { + type: 'object', + properties: { + budget: { + type: 'number', + example: 300, + description: 'Total budget for generating recipes', + }, + }, + }, + }) + @ApiOperation({ summary: 'Generate a list of recipes based on budget' }) + @Get('generate') + async generateRecipes(@Body('budget') budget: number): Promise { + try { + return await this.recipesService.generateRecipesFromBudget(budget); + } catch (err) { + throw new HttpException( + { + status: HttpStatus.INTERNAL_SERVER_ERROR, + error: 'Error generating recipe list!' + err.stack, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + @ApiOperation({ summary: 'Create a new recipe' }) @ApiBody({ type: CreateRecipeDto }) @Post() @@ -100,54 +149,4 @@ export class RecipesController { ); } } - - @ApiBody({ type: [String] }) - @ApiOperation({ summary: 'Find all ingredients based on many recipes' }) - @Get('generate-ingredients') - async generateIngredientsList( - @Body() recipeIds: string[], - ): Promise { - try { - return await this.recipesService.generateIngredientsList(recipeIds); - } catch (err) { - throw new HttpException( - { - status: HttpStatus.BAD_REQUEST, - error: 'Error generating ingredients list!', - }, - HttpStatus.BAD_REQUEST, - ); - } - } - - // [TODO] Implement - @ApiBody({ - description: "Generate a list of recipes based on the user's budget", - required: true, - schema: { - type: 'object', - properties: { - budget: { - type: 'number', - example: 300, - description: 'Total budget for generating recipes', - }, - }, - }, - }) - @ApiOperation({ summary: 'Generate a list of recipes based on budget' }) - @Get('generate') - async generateRecipes(@Body('budget') budget: number): Promise { - try { - return await this.recipesService.generateRecipesFromBudget(budget); - } catch (err) { - throw new HttpException( - { - status: HttpStatus.INTERNAL_SERVER_ERROR, - error: 'Error generating recipe list!' + err.stack, - }, - HttpStatus.INTERNAL_SERVER_ERROR, - ); - } - } }