43 lines
1.3 KiB
Kotlin
43 lines
1.3 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.model.enums.QuestionType
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
fun map(type: QuestionType): Int {
|
|
return type.ordinal;
|
|
}
|
|
|
|
fun map(value: Int): QuestionType {
|
|
return QuestionType.entries[value];
|
|
}
|
|
} |