I have this ProgramDto :
data class ProgramDto(
val id: Long?,
val title: String,
val description: String,
var images: List<ImageDto>? = emptyList()
)
that may (or not) have Sessions. Sometime the Front end needs it, sometimes it doesn’t. So I’ve created another Dto called ProgramWithSessionsDto. And then I added this function in ProgramDto that converts the ProgramDto to a ProgramWithSessionsDto:
fun ProgramDto.toProgramWithSessionsDto(): ProgramWithSessionsDto = ProgramWithSessionsDto(
id = id,...
ProgramWithSessionsDto, is this:
data class ProgramWithSessionsDto(
val id: Long?,
val title: String,
val description: String,
var images: List<ImageDto>? = emptyList(),
var sessions: List<SessionDto>? = emptyList()
)
But that’s a lot of Dtos I’m going to add to my project. Is there anyway I could simply add this to my ProgramDto:
var sessions: List<SessionDto>? = emptyList(),
but not return it (the sessions) if I don’t need to ? and then I could get rid of ProgramWithSessionsDto.