fix: improve imageUrl handling in Recipe model to avoid null or empty values
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
:{$PORT:5000} {
|
:{$PORT:5000} {
|
||||||
root * /usr/share/caddy
|
root * /usr/share/caddy
|
||||||
|
|
||||||
|
# Recipe images are stored in a shared volume and served by the Next service.
|
||||||
|
handle /images/* {
|
||||||
|
reverse_proxy recipe-frontend:3000
|
||||||
|
}
|
||||||
|
|
||||||
# Proxy API calls to backend service on the internal Docker network.
|
# Proxy API calls to backend service on the internal Docker network.
|
||||||
handle /api/* {
|
handle /api/* {
|
||||||
reverse_proxy recipe-api:8080
|
reverse_proxy recipe-api:8080
|
||||||
|
|||||||
@@ -26,12 +26,16 @@ class Recipe {
|
|||||||
final dynamic rawImageUrl = json['imageUrl'];
|
final dynamic rawImageUrl = json['imageUrl'];
|
||||||
final dynamic rawServings = json['servings'];
|
final dynamic rawServings = json['servings'];
|
||||||
final rawIngredients = json['ingredients'] as List<dynamic>? ?? [];
|
final rawIngredients = json['ingredients'] as List<dynamic>? ?? [];
|
||||||
|
final normalizedImageUrl = rawImageUrl?.toString().trim();
|
||||||
|
|
||||||
return Recipe(
|
return Recipe(
|
||||||
id: rawId is num ? rawId.toInt() : int.parse(rawId.toString()),
|
id: rawId is num ? rawId.toInt() : int.parse(rawId.toString()),
|
||||||
title: (rawTitle ?? '').toString(),
|
title: (rawTitle ?? '').toString(),
|
||||||
description: rawDescription == null ? null : rawDescription.toString(),
|
description: rawDescription == null ? null : rawDescription.toString(),
|
||||||
imageUrl: rawImageUrl == null ? null : rawImageUrl.toString(),
|
imageUrl:
|
||||||
|
(normalizedImageUrl == null || normalizedImageUrl.isEmpty)
|
||||||
|
? null
|
||||||
|
: normalizedImageUrl,
|
||||||
servings: rawServings == null
|
servings: rawServings == null
|
||||||
? null
|
? null
|
||||||
: (rawServings is num
|
: (rawServings is num
|
||||||
|
|||||||
Reference in New Issue
Block a user