-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
26 add cached recipe repository (#27)
* [#25] feat: add get all recipes and ingredients * [#25] feat: add indexed object * [#25] chore: upgrade dependencies * [#25] feat: add cached repository * [#26] test: add model mapper test * [#26] test: add matter unit test * [#26] test: add cached ingredient repository test * [#26] test: add cached recipe repository test * [#26] refactor: change repository to allow datasource to be injected * [@26] chore: fix typo * [#26] fix: github test workflow
- Loading branch information
Showing
39 changed files
with
2,314 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,6 @@ app.*.map.json | |
# Auto generated files | ||
*.freezed.dart | ||
*.g.dart | ||
|
||
# code coverage files | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export 'exceptions.dart'; | ||
export 'datasource/datasource.dart'; | ||
export 'exceptions.dart'; | ||
export 'model/model.dart'; | ||
export 'repository/repository.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 1 addition & 23 deletions
24
data/lib/datasource/model_mapper/ingredient_amount_mapper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
data/lib/datasource/model_mapper/ingredient_data_mapper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
part of 'model_mapper.dart'; | ||
|
||
extension IngredientDataMapper on IngredientData { | ||
IndexedIngredient toIngredient() { | ||
return IndexedIngredient( | ||
name: name, | ||
description: description ?? '', | ||
id: id, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
part of 'model_mapper.dart'; | ||
|
||
extension AmountMapper on Amount { | ||
MatterUnit toMatterUnit() { | ||
if (this is Milligram) return MatterUnit.milligram; | ||
if (this is Gram) return MatterUnit.gram; | ||
if (this is Kilogram) return MatterUnit.kilogram; | ||
if (this is Ounce) return MatterUnit.ounce; | ||
if (this is Pound) return MatterUnit.pound; | ||
if (this is CubicCentimeter) return MatterUnit.cubicCentimeter; | ||
if (this is Milliliter) return MatterUnit.milliliter; | ||
if (this is Liter) return MatterUnit.liter; | ||
if (this is Teaspoon) return MatterUnit.teaspoon; | ||
if (this is Tablespoon) return MatterUnit.tablespoon; | ||
if (this is FluidOunce) return MatterUnit.fluidOunce; | ||
if (this is Cup) return MatterUnit.cup; | ||
if (this is Count) return MatterUnit.count; | ||
throw StateError('Unsupported type $runtimeType'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export 'ingredient_amount_mapper.dart'; | ||
export 'temperature_data_mapper.dart'; | ||
export 'temperature_mapper.dart'; | ||
import 'package:data/data.dart'; | ||
import 'package:domain/domain.dart'; | ||
|
||
part 'ingredient_amount_mapper.dart'; | ||
part 'ingredient_data_mapper.dart'; | ||
part 'matter_unit_mapper.dart'; | ||
part 'recipe_data_mapper.dart'; | ||
part 'temperature_data_mapper.dart'; | ||
part 'temperature_mapper.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
part of 'model_mapper.dart'; | ||
|
||
extension RecipDataMapper on RecipeData { | ||
IndexedRecipe toRecipe() { | ||
final directions = this.directions.map( | ||
(directionData) { | ||
final countByIngredientId = <int, Count>{}; | ||
final massByIngredientId = <int, Mass>{}; | ||
final volumeByIngredientId = <int, Volume>{}; | ||
final ingredientAmounts = directionData.ingredients ?? []; | ||
for (final ingredientAmount in ingredientAmounts) { | ||
final ingredientId = ingredientAmount.ingredientId; | ||
final amount = ingredientAmount.toAmount(); | ||
|
||
if (amount is Count) countByIngredientId[ingredientId] = amount; | ||
if (amount is Mass) massByIngredientId[ingredientId] = amount; | ||
if (amount is Volume) volumeByIngredientId[ingredientId] = amount; | ||
} | ||
|
||
return Direction( | ||
description: directionData.description, | ||
temperature: directionData.temperature?.toTemperature(), | ||
time: Duration(seconds: directionData.timeInSeconds ?? 0), | ||
countByIngredientId: countByIngredientId, | ||
massByIngredientId: massByIngredientId, | ||
volumeByIngredientId: volumeByIngredientId, | ||
); | ||
}, | ||
).toList(); | ||
|
||
return IndexedRecipe( | ||
directions: directions, | ||
name: name, | ||
description: description ?? '', | ||
id: id, | ||
servings: servings, | ||
); | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
data/lib/datasource/model_mapper/temperature_data_mapper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.