forked from agzam/vyatsu-schedule
38 lines
1.1 KiB
Kotlin
38 lines
1.1 KiB
Kotlin
package agzam.vyatsu.data.local
|
|
|
|
import agzam.vyatsu.domain.model.Lesson
|
|
import agzam.vyatsu.domain.model.LessonType
|
|
import com.squareup.moshi.JsonClass
|
|
|
|
@JsonClass(generateAdapter = true)
|
|
data class LessonDto(
|
|
val raw: String = "",
|
|
val room: String? = null,
|
|
val group: String? = null,
|
|
val subgroup: String? = null,
|
|
val subject: String? = null,
|
|
val type: String = "",
|
|
val teacher: String? = null
|
|
) {
|
|
fun toDomain(): Lesson = Lesson(
|
|
raw = raw,
|
|
room = room?.takeIf { it.isNotBlank() },
|
|
group = group?.takeIf { it.isNotBlank() },
|
|
subgroup = subgroup?.takeIf { it.isNotBlank() },
|
|
subject = subject?.takeIf { it.isNotBlank() },
|
|
type = runCatching { LessonType.valueOf(type) }.getOrDefault(LessonType.OTHER),
|
|
teacher = teacher?.takeIf { it.isNotBlank() }
|
|
)
|
|
|
|
companion object {
|
|
fun fromDomain(l: Lesson): LessonDto = LessonDto(
|
|
raw = l.raw,
|
|
room = l.room,
|
|
group = l.group,
|
|
subgroup = l.subgroup,
|
|
subject = l.subject,
|
|
type = l.type.name,
|
|
teacher = l.teacher
|
|
)
|
|
}
|
|
} |