40 lines
1.3 KiB
Kotlin
40 lines
1.3 KiB
Kotlin
|
|
package at.eisibaer.jbear2.service.mapper
|
||
|
|
|
||
|
|
import at.eisibaer.jbear2.dto.board.BoardEntryDto
|
||
|
|
import at.eisibaer.jbear2.model.BoardEntry
|
||
|
|
import at.eisibaer.jbear2.model.File
|
||
|
|
import at.eisibaer.jbear2.repository.FileRepository
|
||
|
|
import org.mapstruct.AfterMapping
|
||
|
|
import org.mapstruct.Context
|
||
|
|
import org.mapstruct.Mapper
|
||
|
|
import org.mapstruct.MappingTarget
|
||
|
|
import java.util.*
|
||
|
|
|
||
|
|
@Mapper(uses = [QuestionMapper::class,AnswerMapper::class])
|
||
|
|
abstract class BoardEntryMapper {
|
||
|
|
|
||
|
|
abstract fun toDto(e: BoardEntry): BoardEntryDto;
|
||
|
|
abstract fun toDto(e: List<BoardEntry>): List<BoardEntryDto>;
|
||
|
|
|
||
|
|
abstract fun toEntity(d: BoardEntryDto, @Context fileRepository: FileRepository): BoardEntry;
|
||
|
|
abstract fun toEntity(d: List<BoardEntryDto>, @Context fileRepository: FileRepository): List<BoardEntry>;
|
||
|
|
|
||
|
|
fun map(file: File): String{
|
||
|
|
return file.uuid.toString()
|
||
|
|
}
|
||
|
|
fun map(imageUuid: String?, @Context fileRepository: FileRepository): File? {
|
||
|
|
return if( imageUuid == null ) {
|
||
|
|
null
|
||
|
|
} else {
|
||
|
|
fileRepository.findByUuid(UUID.fromString(imageUuid))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@AfterMapping
|
||
|
|
fun addBoardEntryToQuestion(source: BoardEntryDto, @MappingTarget target: BoardEntry): BoardEntry {
|
||
|
|
for( question in target.questions ){
|
||
|
|
question.boardEntry = target
|
||
|
|
}
|
||
|
|
return target
|
||
|
|
}
|
||
|
|
}
|