Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun RecipeDTO.toModel(): RecipeModel {
- return RecipeModel(
- name = this.name,
- description = this.description,
- thumbnailUrl = this.thumbnailUrl,
- keywords = this.keywords,
- isPublic = this.isPublic,
- userEmail = this.userEmail,
- originalVideoUrl = this.originalVideoUrl,
- country = this.country,
- numServings = this.numServings,
- components = this.components.toComponentModelList(),
- instructions = this.instructions.toInstructionModelList(),
- )
- }
- private fun RecipeDetailDTO.toModel(): RecipeDetailModel {
- return RecipeDetailModel(
- name = this.name,
- description = this.description,
- thumbnailUrl = this.thumbnailUrl,
- keywords = this.keywords,
- isPublic = this.isPublic,
- userEmail = this.userEmail,
- originalVideoUrl = this.originalVideoUrl,
- country = this.country,
- numServings = this.numServings,
- components = this.components.toComponentModelList(),
- instructions = this.instructions.toInstructionModelList(),
- nutrition = this.nutrition.toModel(),
- )
- }
- private fun NutritionDTO.toModel(): NutritionModel {
- return NutritionModel(
- calories = this.calories,
- protein = this.protein,
- fat = this.fat,
- carbohydrates = this.carbohydrates,
- sugar = this.sugar,
- fiber = this.fiber
- )
- }
- private fun MeasurementDTO.toModel(): MeasurementModel {
- return MeasurementModel(
- quantity = this.quantity, unit = this.unit.toModel()
- )
- }
- private fun InstructionDTO.toModel(): InstructionModel {
- return InstructionModel(
- position = this.position, displayText = this.displayText
- )
- }
- private fun IngredientDTO.toModel(): IngredientModel {
- return IngredientModel(
- name = this.name
- )
- }
- private fun ComponentDTO.toModel(): ComponentModel {
- return ComponentModel(
- rawText = this.rawText,
- extraComment = this.extraComment,
- ingredient = this.ingredient.toModel(),
- measurement = this.measurement.toModel(),
- position = this.position
- )
- }
- fun List<ComponentDTO>.toComponentModelList(): List<ComponentModel> {
- return this.map { it.toModel() }
- }
- fun List<InstructionDTO>.toInstructionModelList(): List<InstructionModel> {
- return this.map { it.toModel() }
- }
- fun List<MeasurementDTO>.toMeasurementModelList(): List<MeasurementModel> {
- return this.map { it.toModel() }
- }
- fun List<NutritionDTO>.toNutritionModelList(): List<NutritionModel> {
- return this.map { it.toModel() }
- }
- fun List<RecipeDTO>.toRecipeModelList(): List<RecipeModel> {
- return this.map { it.toModel() }
- }
- private fun UnitDTO.toModel(): UnitModel {
- return UnitModel(
- name = this.name,
- displaySingular = this.displaySingular,
- displayPlural = this.displayPlural,
- abbreviation = this.abbreviation
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement