34 lines
1.1 KiB
Kotlin
34 lines
1.1 KiB
Kotlin
|
|
package at.eisibaer.jbear2.service.mapper
|
||
|
|
|
||
|
|
import at.eisibaer.jbear2.dto.board.QuestionDto
|
||
|
|
import at.eisibaer.jbear2.model.File
|
||
|
|
import at.eisibaer.jbear2.model.Question
|
||
|
|
import at.eisibaer.jbear2.repository.FileRepository
|
||
|
|
import org.mapstruct.Context
|
||
|
|
import org.mapstruct.Mapper
|
||
|
|
import java.util.UUID
|
||
|
|
|
||
|
|
@Mapper
|
||
|
|
abstract class QuestionMapper {
|
||
|
|
|
||
|
|
abstract fun toDto(e: Question): QuestionDto;
|
||
|
|
abstract fun toDto(e: List<Question>): List<QuestionDto>;
|
||
|
|
|
||
|
|
abstract fun toEntity(d: QuestionDto, @Context fileRepository: FileRepository): Question;
|
||
|
|
abstract fun toEntity(d: List<QuestionDto>, @Context fileRepository: FileRepository): List<Question>;
|
||
|
|
|
||
|
|
fun map(file: File?): String?{
|
||
|
|
return file?.uuid.toString();
|
||
|
|
}
|
||
|
|
fun map(imageUuid: String?, @Context fileRepository: FileRepository): File? {
|
||
|
|
return if( imageUuid == null ) {
|
||
|
|
null
|
||
|
|
} else {
|
||
|
|
try{
|
||
|
|
fileRepository.findByUuid(UUID.fromString(imageUuid))
|
||
|
|
} catch ( illegalArgumentException: IllegalArgumentException ){
|
||
|
|
null
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|