Advertisement
tankian202

Untitled

Nov 12th, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. private fun RecipeDTO.toModel(): RecipeModel {
  2. return RecipeModel(
  3. name = this.name,
  4. description = this.description,
  5. thumbnailUrl = this.thumbnailUrl,
  6. keywords = this.keywords,
  7. isPublic = this.isPublic,
  8. userEmail = this.userEmail,
  9. originalVideoUrl = this.originalVideoUrl,
  10. country = this.country,
  11. numServings = this.numServings,
  12. components = this.components.toComponentModelList(),
  13. instructions = this.instructions.toInstructionModelList(),
  14. )
  15. }
  16.  
  17.  
  18.  
  19. private fun RecipeDetailDTO.toModel(): RecipeDetailModel {
  20. return RecipeDetailModel(
  21. name = this.name,
  22. description = this.description,
  23. thumbnailUrl = this.thumbnailUrl,
  24. keywords = this.keywords,
  25. isPublic = this.isPublic,
  26. userEmail = this.userEmail,
  27. originalVideoUrl = this.originalVideoUrl,
  28. country = this.country,
  29. numServings = this.numServings,
  30. components = this.components.toComponentModelList(),
  31. instructions = this.instructions.toInstructionModelList(),
  32. nutrition = this.nutrition.toModel(),
  33. )
  34. }
  35.  
  36. private fun NutritionDTO.toModel(): NutritionModel {
  37. return NutritionModel(
  38. calories = this.calories,
  39. protein = this.protein,
  40. fat = this.fat,
  41. carbohydrates = this.carbohydrates,
  42. sugar = this.sugar,
  43. fiber = this.fiber
  44. )
  45. }
  46.  
  47.  
  48.  
  49. private fun MeasurementDTO.toModel(): MeasurementModel {
  50. return MeasurementModel(
  51. quantity = this.quantity, unit = this.unit.toModel()
  52. )
  53. }
  54.  
  55.  
  56.  
  57. private fun InstructionDTO.toModel(): InstructionModel {
  58. return InstructionModel(
  59. position = this.position, displayText = this.displayText
  60. )
  61. }
  62.  
  63. private fun IngredientDTO.toModel(): IngredientModel {
  64. return IngredientModel(
  65. name = this.name
  66. )
  67. }
  68.  
  69. private fun ComponentDTO.toModel(): ComponentModel {
  70. return ComponentModel(
  71. rawText = this.rawText,
  72. extraComment = this.extraComment,
  73. ingredient = this.ingredient.toModel(),
  74. measurement = this.measurement.toModel(),
  75. position = this.position
  76. )
  77. }
  78.  
  79. fun List<ComponentDTO>.toComponentModelList(): List<ComponentModel> {
  80. return this.map { it.toModel() }
  81. }
  82.  
  83. fun List<InstructionDTO>.toInstructionModelList(): List<InstructionModel> {
  84. return this.map { it.toModel() }
  85. }
  86.  
  87. fun List<MeasurementDTO>.toMeasurementModelList(): List<MeasurementModel> {
  88. return this.map { it.toModel() }
  89. }
  90.  
  91. fun List<NutritionDTO>.toNutritionModelList(): List<NutritionModel> {
  92. return this.map { it.toModel() }
  93. }
  94.  
  95. fun List<RecipeDTO>.toRecipeModelList(): List<RecipeModel> {
  96. return this.map { it.toModel() }
  97. }
  98. private fun UnitDTO.toModel(): UnitModel {
  99. return UnitModel(
  100. name = this.name,
  101. displaySingular = this.displaySingular,
  102. displayPlural = this.displayPlural,
  103. abbreviation = this.abbreviation
  104. )
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement