Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement nutrition data display (see #124) #136

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/assets/locales/de/nutritionData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"nutritionTitle": "Nährwerte:",
"energy": "Energie",
"energyUnit": "kcal",
"protein": "Proteine",
"proteinUnit": "g",
"carbohydrates": "Kohlenhydrate",
"carbohydratesUnit": "g",
"sugar": "Zucker",
"sugarUnit": "g",
"fat": "Fett",
"fatUnit": "g",
"saturatedFat": "Gesättigte Fette",
"saturatedFatUnit": "g",
"salt": "Salz",
"saltUnit": "g"
}
1 change: 1 addition & 0 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void main() async {
"reportReason",
"additive",
"allergen",
"nutritionData",
"mealplanException",
"semantics",
"mealDetails"
Expand Down
42 changes: 28 additions & 14 deletions app/lib/model/api_server/GraphQlServerAccess.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:app/view_model/repository/data_classes/meal/FoodType.dart';
import 'package:app/view_model/repository/data_classes/meal/ImageData.dart';

import 'package:app/view_model/repository/data_classes/meal/Meal.dart';
import 'package:app/view_model/repository/data_classes/meal/NutritionData.dart';
import 'package:app/view_model/repository/data_classes/meal/Price.dart';
import 'package:app/view_model/repository/data_classes/meal/Side.dart';

Expand Down Expand Up @@ -125,7 +126,7 @@ class GraphQlServerAccess implements IServerAccess {

final result = await _client.mutate$LinkImage(Options$Mutation$LinkImage(
variables:
Variables$Mutation$LinkImage(imageUrl: url, mealId: meal.id)));
Variables$Mutation$LinkImage(image: url, mealId: meal.id, hash: hash)));
if (result.hasException) {
if (result.exception!.linkException != null) {
return Failure(ImageUploadException("Verbindungsfehler"));
Expand Down Expand Up @@ -372,10 +373,11 @@ Meal _convertMeal(Fragment$mealInfo meal) {
return Meal(
id: meal.id,
name: meal.name,
foodType: _convertMealType(meal.mealType),
foodType: _convertFoodType(meal.mealType),
price: _convertPrice(meal.price),
additives: meal.additives.map((e) => _convertAdditive(e)).nonNulls.toList(),
allergens: meal.allergens.map((e) => _convertAllergen(e)).nonNulls.toList(),
nutritionData: meal.nutritionData != null ? _convertNutritionData(meal.nutritionData!) : null,
averageRating: meal.ratings.averageRating,
individualRating: meal.ratings.personalRating,
numberOfRatings: meal.ratings.ratingsCount,
Expand Down Expand Up @@ -413,7 +415,7 @@ Side _convertSide(Fragment$mealInfo$sides e) {
return Side(
id: e.id,
name: e.name,
foodType: _convertMealType(e.mealType),
foodType: _convertFoodType(e.mealType),
price: _convertPrice(e.price),
allergens: e.allergens.map((e) => _convertAllergen(e)).nonNulls.toList(),
additives: e.additives.map((e) => _convertAdditive(e)).nonNulls.toList());
Expand Down Expand Up @@ -482,36 +484,48 @@ Additive? _convertAdditive(Enum$Additive e) {
Enum$Additive.LAXATIVE_IF_OVERUSED => Additive.laxativeIfOverused,
Enum$Additive.PHENYLALANINE => Additive.phenylalanine,
Enum$Additive.ALCOHOL => Additive.alcohol,
Enum$Additive.PRESSED_MEET => Additive.pressedMeat,
Enum$Additive.PRESSED_MEAT => Additive.pressedMeat,
Copy link
Contributor Author

@muety muety Feb 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nutrition/logic seems to have diverged from main and didn't compile. Didn't want to rebase, though, because would probably be a mess when merging everything (backend and frontend) together, so I manually applied a couple of changes like this to get a working app to start with.

Enum$Additive.GLAZING_WITH_CACAO => Additive.glazingWithCacao,
Enum$Additive.PRESSED_FISH => Additive.pressedFish,
Enum$Additive.$unknown => null,
};
}

FoodType _convertMealType(Enum$MealType mealType) {
FoodType _convertFoodType(Enum$FoodType mealType) {
switch (mealType) {
case Enum$MealType.BEEF:
case Enum$FoodType.BEEF:
return FoodType.beef;
case Enum$MealType.BEEF_AW:
case Enum$FoodType.BEEF_AW:
return FoodType.beefAw;
case Enum$MealType.FISH:
case Enum$FoodType.FISH:
return FoodType.fish;
case Enum$MealType.PORK:
case Enum$FoodType.PORK:
return FoodType.pork;
case Enum$MealType.PORK_AW:
case Enum$FoodType.PORK_AW:
return FoodType.porkAw;
case Enum$MealType.VEGAN:
case Enum$FoodType.VEGAN:
return FoodType.vegan;
case Enum$MealType.VEGETARIAN:
case Enum$FoodType.VEGETARIAN:
return FoodType.vegetarian;
case Enum$MealType.UNKNOWN:
case Enum$FoodType.UNKNOWN:
return FoodType.unknown;
case Enum$MealType.$unknown:
case Enum$FoodType.$unknown:
return FoodType.unknown;
}
}

NutritionData _convertNutritionData(Fragment$mealInfo$nutritionData nutritionData) {
return NutritionData(
energy: nutritionData.energy,
protein: nutritionData.protein,
carbohydrates: nutritionData.carbohydrates,
sugar: nutritionData.sugar,
fat: nutritionData.fat,
saturatedFat: nutritionData.saturatedFat,
salt: nutritionData.salt,
);
}

Price _convertPrice(Fragment$price price) {
return Price(
student: price.student,
Expand Down
4 changes: 2 additions & 2 deletions app/lib/model/api_server/requests/mutations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ mutation AddUpvote($imageId: UUID!) {
addUpvote(imageId: $imageId)
}

mutation LinkImage($mealId: UUID!, $imageUrl: String!) {
addImage(mealId: $mealId, imageUrl: $imageUrl)
mutation LinkImage($mealId: UUID!, $image: Upload!, $hash: String!) {
addImage(mealId: $mealId, image: $image, hash: $hash)
}

mutation ReportImage($imageId: UUID!, $reason: ReportReason!) {
Expand Down
74 changes: 50 additions & 24 deletions app/lib/model/api_server/requests/mutations.graphql.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'dart:async';

import 'package:flutter/widgets.dart' as widgets;
import 'package:gql/ast.dart';
import 'package:graphql/client.dart' as graphql;
import 'package:graphql_flutter/graphql_flutter.dart' as graphql_flutter;

import 'schema.graphql.dart';

class Variables$Mutation$RemoveDownvote {
Expand Down Expand Up @@ -87,7 +85,6 @@ class _CopyWithImpl$Variables$Mutation$RemoveDownvote<TRes>

static const _undefined = <dynamic, dynamic>{};

@override
TRes call({Object? imageId = _undefined}) =>
_then(Variables$Mutation$RemoveDownvote._({
..._instance._$data,
Expand All @@ -102,7 +99,6 @@ class _CopyWithStubImpl$Variables$Mutation$RemoveDownvote<TRes>

TRes _res;

@override
call({String? imageId}) => _res;
}

Expand Down Expand Up @@ -1882,11 +1878,13 @@ class Mutation$AddUpvote$Widget
class Variables$Mutation$LinkImage {
factory Variables$Mutation$LinkImage({
required String mealId,
required String imageUrl,
required String image,
required String hash,
}) =>
Variables$Mutation$LinkImage._({
r'mealId': mealId,
r'imageUrl': imageUrl,
r'image': image,
r'hash': hash,
});

Variables$Mutation$LinkImage._(this._$data);
Expand All @@ -1895,21 +1893,26 @@ class Variables$Mutation$LinkImage {
final result$data = <String, dynamic>{};
final l$mealId = data['mealId'];
result$data['mealId'] = (l$mealId as String);
final l$imageUrl = data['imageUrl'];
result$data['imageUrl'] = (l$imageUrl as String);
final l$image = data['image'];
result$data['image'] = (l$image as String);
final l$hash = data['hash'];
result$data['hash'] = (l$hash as String);
return Variables$Mutation$LinkImage._(result$data);
}

Map<String, dynamic> _$data;

String get mealId => (_$data['mealId'] as String);
String get imageUrl => (_$data['imageUrl'] as String);
String get image => (_$data['image'] as String);
String get hash => (_$data['hash'] as String);
Map<String, dynamic> toJson() {
final result$data = <String, dynamic>{};
final l$mealId = mealId;
result$data['mealId'] = l$mealId;
final l$imageUrl = imageUrl;
result$data['imageUrl'] = l$imageUrl;
final l$image = image;
result$data['image'] = l$image;
final l$hash = hash;
result$data['hash'] = l$hash;
return result$data;
}

Expand All @@ -1932,9 +1935,14 @@ class Variables$Mutation$LinkImage {
if (l$mealId != lOther$mealId) {
return false;
}
final l$imageUrl = imageUrl;
final lOther$imageUrl = other.imageUrl;
if (l$imageUrl != lOther$imageUrl) {
final l$image = image;
final lOther$image = other.image;
if (l$image != lOther$image) {
return false;
}
final l$hash = hash;
final lOther$hash = other.hash;
if (l$hash != lOther$hash) {
return false;
}
return true;
Expand All @@ -1943,10 +1951,12 @@ class Variables$Mutation$LinkImage {
@override
int get hashCode {
final l$mealId = mealId;
final l$imageUrl = imageUrl;
final l$image = image;
final l$hash = hash;
return Object.hashAll([
l$mealId,
l$imageUrl,
l$image,
l$hash,
]);
}
}
Expand All @@ -1962,7 +1972,8 @@ abstract class CopyWith$Variables$Mutation$LinkImage<TRes> {

TRes call({
String? mealId,
String? imageUrl,
String? image,
String? hash,
});
}

Expand All @@ -1981,14 +1992,15 @@ class _CopyWithImpl$Variables$Mutation$LinkImage<TRes>

TRes call({
Object? mealId = _undefined,
Object? imageUrl = _undefined,
Object? image = _undefined,
Object? hash = _undefined,
}) =>
_then(Variables$Mutation$LinkImage._({
..._instance._$data,
if (mealId != _undefined && mealId != null)
'mealId': (mealId as String),
if (imageUrl != _undefined && imageUrl != null)
'imageUrl': (imageUrl as String),
if (image != _undefined && image != null) 'image': (image as String),
if (hash != _undefined && hash != null) 'hash': (hash as String),
}));
}

Expand All @@ -2000,7 +2012,8 @@ class _CopyWithStubImpl$Variables$Mutation$LinkImage<TRes>

call({
String? mealId,
String? imageUrl,
String? image,
String? hash,
}) =>
_res;
}
Expand Down Expand Up @@ -2143,7 +2156,16 @@ const documentNodeMutationLinkImage = DocumentNode(definitions: [
directives: [],
),
VariableDefinitionNode(
variable: VariableNode(name: NameNode(value: 'imageUrl')),
variable: VariableNode(name: NameNode(value: 'image')),
type: NamedTypeNode(
name: NameNode(value: 'Upload'),
isNonNull: true,
),
defaultValue: DefaultValueNode(value: null),
directives: [],
),
VariableDefinitionNode(
variable: VariableNode(name: NameNode(value: 'hash')),
type: NamedTypeNode(
name: NameNode(value: 'String'),
isNonNull: true,
Expand All @@ -2163,8 +2185,12 @@ const documentNodeMutationLinkImage = DocumentNode(definitions: [
value: VariableNode(name: NameNode(value: 'mealId')),
),
ArgumentNode(
name: NameNode(value: 'imageUrl'),
value: VariableNode(name: NameNode(value: 'imageUrl')),
name: NameNode(value: 'image'),
value: VariableNode(name: NameNode(value: 'image')),
),
ArgumentNode(
name: NameNode(value: 'hash'),
value: VariableNode(name: NameNode(value: 'hash')),
),
],
directives: [],
Expand Down
9 changes: 9 additions & 0 deletions app/lib/model/api_server/requests/querys.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ fragment mealInfo on Meal {
}
allergens
additives
nutritionData {
energy
protein
carbohydrates
sugar
fat
saturatedFat
salt
}
statistics {
lastServed
nextServed
Expand Down
Loading