Skip to content

Commit

Permalink
fix: changed request order to avoid conflicts on get :id
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckMeelo committed Dec 13, 2024
1 parent a47f43b commit 4bbaf32
Showing 1 changed file with 49 additions and 50 deletions.
99 changes: 49 additions & 50 deletions src/services/recipe/recipes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IngredientDetailDtoWithPrice[]> {
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<Recipe[]> {
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()
Expand Down Expand Up @@ -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<IngredientDetailDtoWithPrice[]> {
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<Recipe[]> {
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,
);
}
}
}

0 comments on commit 4bbaf32

Please sign in to comment.