feat: implement recipe analysis service and data models
Test Suite / test (24.15.0) (push) Has been cancelled

- Added RecipeAnalysisService to handle recipe ingredient analysis, including methods for checking ingredient availability and calculating quantities.
- Introduced new TypeScript definitions for recipe analysis results, including ingredient status and summary.
- Created corresponding Dart models for recipe analysis, including RecipeIngredientAnalysis, RecipeAnalysisSummary, and RecipeShoppingCandidate.
- Updated Flutter UI to reflect changes in ingredient availability status.
- Fixed color opacity issue in recipe image card.
This commit is contained in:
Nils-Johan Gynther
2026-05-06 07:54:03 +02:00
parent 969dafdbc6
commit 9fe85a719c
23 changed files with 1271 additions and 693 deletions
+221 -176
View File
@@ -4,12 +4,14 @@ import { CreateIngredientDto } from './dto/create-ingredient.dto';
import { ParseMarkdownDto } from './dto/parse-markdown.dto';
import { ShareRecipeDto } from './dto/share-recipe.dto';
import { SetRecipeVisibilityDto } from './dto/set-recipe-visibility.dto';
import { RecipeAnalysisService } from './recipe-analysis.service';
declare class UpdateImageDto {
sourceUrl: string;
}
export declare class RecipesController {
private readonly recipesService;
constructor(recipesService: RecipesService);
private readonly recipeAnalysisService;
constructor(recipesService: RecipesService, recipeAnalysisService: RecipeAnalysisService);
parseMarkdown(dto: ParseMarkdownDto): Promise<{
name: string;
description: string;
@@ -43,6 +45,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -50,54 +54,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
})[]>;
getInventoryPreview(id: number, user: {
userId: number;
@@ -145,6 +147,49 @@ export declare class RecipesController {
pantryCount: number;
};
}>;
getRecipeAnalysis(id: number, user: {
userId: number;
}): Promise<{
recipeId: number;
ingredients: ({
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
note: any;
status: "missing" | "exact_match" | "covered_by_pantry" | "substitutable";
matchedProductId: any;
matchedProductName: any;
source: string;
availableQuantity: number;
missingQuantity: number;
} | {
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
note: any;
status: "missing" | "exact_match" | "covered_by_pantry" | "substitutable";
matchedProductId: any;
matchedProductName: any;
source: null;
availableQuantity: number;
missingQuantity: number;
})[];
summary: {
exactCount: number;
pantryCount: number;
substituteCount: number;
missingCount: number;
};
shoppingListCandidates: {
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
missingQuantity: number;
}[];
}>;
findOne(id: number, user: {
userId: number;
}): Promise<{
@@ -155,6 +200,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -162,54 +209,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
create(createRecipeDto: CreateRecipeDto, user: {
userId: number;
@@ -217,6 +262,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -224,51 +271,49 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
update(id: number, createRecipeDto: CreateRecipeDto, user: {
userId: number;
@@ -276,6 +321,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -283,51 +330,49 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
remove(id: number, user: {
userId: number;
@@ -342,6 +387,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -349,60 +396,60 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
addIngredient(id: number, ingredient: CreateIngredientDto, user: {
userId: number;
}): Promise<{
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -410,38 +457,36 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
}>;
setVisibility(id: number, dto: SetRecipeVisibilityDto, user: {
@@ -454,6 +499,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -461,54 +508,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
shareRecipe(id: number, dto: ShareRecipeDto, user: {
userId: number;
@@ -520,6 +565,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -527,54 +574,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
unshareRecipe(id: number, username: string, user: {
userId: number;
@@ -586,6 +631,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -593,54 +640,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
}
export {};