feat(inventory): add inventory preview functionality and related models

This commit is contained in:
Nils-Johan Gynther
2026-04-22 19:41:45 +02:00
parent b31af6181c
commit b8627d0b7f
5 changed files with 327 additions and 0 deletions
@@ -3,6 +3,7 @@ import '../../../core/api/api_exception.dart';
import '../../../core/api/api_paths.dart';
import '../domain/parsed_recipe.dart';
import '../domain/recipe.dart';
import '../domain/inventory_preview.dart';
class RecipeRepository {
final ApiClient _api;
@@ -93,6 +94,27 @@ class RecipeRepository {
}
}
Future<InventoryPreview> fetchInventoryPreview(int id,
{String? token}) async {
try {
final data = await _api.getJson(
RecipeApiPaths.inventoryPreview(id),
token: token,
);
if (data is! Map<String, dynamic>) {
throw const ApiException(
type: ApiErrorType.unknown, message: 'Ogiltigt svar från servern.');
}
return InventoryPreview.fromJson(data);
} on ApiException {
rethrow;
} catch (_) {
throw const ApiException(
type: ApiErrorType.network,
message: 'Kunde inte hämta inventariestatus.');
}
}
Future<ParsedRecipe> parseMarkdown(String markdown,
{String? token}) async {
try {