Skip to content

Instantly share code, notes, and snippets.

@MkhytarMkhoian
Created April 18, 2024 13:20
Show Gist options
  • Save MkhytarMkhoian/429582b825241ab3368d7a1137633f24 to your computer and use it in GitHub Desktop.
Save MkhytarMkhoian/429582b825241ab3368d7a1137633f24 to your computer and use it in GitHub Desktop.
fun CategoryDTO.asDomain() = Category(
id = id,
image = image,
name = name,
children = children.asDomain(),
adsCount = adsCount,
feedType = feedType.asDomain(),
)
fun Category.asDTO() = CategoryDTO(
id = id,
image = image,
name = name,
children = children.asDTO(),
adsCount = adsCount,
feedType = feedType.asDTO(),
)
fun List<Category>.asDTO(): List<CategoryDTO> {
return map { it.asDTO() }
}
fun List<CategoryDTO>.asDomain(): List<Category> {
return map { it.asDomain() }
}
fun CategoryDTO.FeedType?.asDomain() = when (this) {
CategoryDTO.FeedType.MAP -> Category.FeedType.MAP
CategoryDTO.FeedType.DEFAULT -> Category.FeedType.DEFAULT
else -> Category.FeedType.DEFAULT
}
fun Category.FeedType.asDTO() = when (this) {
Category.FeedType.MAP -> CategoryDTO.FeedType.MAP
Category.FeedType.DEFAULT -> CategoryDTO.FeedType.DEFAULT
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment