Boris Dudelsack
07/20/2021, 11:39 AM@Mapper(uses = [ObjectIdMapper::class, LocalDateToInstantMapper::class])
abstract class SubstitutionBlockingMapper {
@Autowired
lateinit var driverRepository: DriverRepository
@Autowired
lateinit var driverMapper: DriverMapper
@Mappings(
Mapping(source = "entity.id", target = "id"),
Mapping(source = "driverId", target = "driver", qualifiedByName = ["driverIdToObject"]),
Mapping(source = "substitutionDriverId", target = "substitutionDriver", qualifiedByName = ["driverIdToObject"]),
)
abstract fun convertToDto(entity: SubstitutionEntity): SubstitutionWithDriver
@Named("driverIdToObject")
fun map(driverId: ObjectId): Driver {
return runBlocking(Dispatchers.Default) {
driverRepository.findById(driverId)!!.let { driverMapper.convertToDTO(it) }
}
}
}
Is there a general pattern i can use to call suspended functions from a coroutine-unaware code?