I’m at chapter 4 and just implemented the mapToDomain()
:
override fun mapToDomain(apiEntity: ApiAnimal): AnimalWithDetails {
return AnimalWithDetails(
id = apiEntity.id ?: throw MappingException("animal id cannot be null"),
name = apiEntity.name.orEmpty(),
type = apiEntity.type.orEmpty(),
details = parseAnimalDetails(apiEntity),
media = mapMedia(apiEntity),
tags = apiEntity.tags.orEmpty().map { it.orEmpty() },
adoptionStatus = parseAdoptionStatus(apiEntity.status),
publishedAt = DateTimeUtils.parse(apiEntity.publishedAt.orEmpty())
)
}
There are a few things I don’t understand, consistency wise:
- why are some methods called mappers and some parsers?
- why does
parseAdoptionStatus()
useapiEntity.status
instead of justapiEntity
like all other mappers/parsers? - which brings me to the final question - why not use the concrete property for all mappers/parsers? Then the mapper/parser receives only the data it needs.