Skip to content

Instantly share code, notes, and snippets.

@MkhytarMkhoian
Created April 18, 2024 14:00
Show Gist options
  • Save MkhytarMkhoian/8d159f2320adbda0b4d3407a14a18245 to your computer and use it in GitHub Desktop.
Save MkhytarMkhoian/8d159f2320adbda0b4d3407a14a18245 to your computer and use it in GitHub Desktop.
fun Category.asPresentation() = CategoryModel(
categoryId = categoryId,
image = image,
name = name,
children = children.asPresentation(),
adsCount = adsCount,
feedType = feedType.asPresentation(),
)
fun Map<CategoryId, List<Category>>.asPresentation(): Map<CategoryIdModel, List<CategoryModel>> =
mapKeys { it.key.asPresentation() }.mapValues { it.value.asPresentation() }
fun List<Category>.asPresentation(): List<CategoryModel> = map { it.asPresentation() }
fun Category.FeedType.asPresentation() = when (this) {
Category.FeedType.MAP -> CategoryModel.FeedType.MAP
else -> CategoryModel.FeedType.DEFAULT
}
fun CategoryModel.asDomain() = Category(
categoryId = categoryId,
image = image,
name = name,
children = children.asDomain(),
adsCount = adsCount,
feedType = feedType.asDomain(),
)
fun Map<CategoryIdModel, List<CategoryModel>>.asDomain(): Map<CategoryId, List<Category>> =
mapKeys { it.key.asDomain() }.mapValues { it.value.asDomain() }
fun List<CategoryModel>.asDomain(): List<Category> = map { it.asDomain() }
fun CategoryModel.FeedType?.asDomain() = when (this) {
CategoryModel.FeedType.MAP -> Category.FeedType.MAP
else -> Category.FeedType.DEFAULT
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment