Filter exams from out of range

This commit is contained in:
Mikołaj Pich 2018-12-12 18:50:22 +01:00
parent f3520d0c88
commit d960c6632a
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA

View file

@ -20,6 +20,7 @@ import org.threeten.bp.LocalDate
class StudentRepository(private val api: StudentService) {
fun getExams(startDate: LocalDate, endDate: LocalDate? = null): Single<List<Exam>> {
val end = endDate ?: startDate.plusDays(4)
return api.getExams(ExamRequest(startDate.toDate(), startDate.year)).map { res ->
res.data?.map { weeks ->
weeks.weeks.map { day ->
@ -34,7 +35,9 @@ class StudentRepository(private val api: StudentService) {
}
}
}.flatten()
}?.flatten()
}?.flatten()?.filter {
it.date.toLocalDate() >= startDate && it.date.toLocalDate() <= end
}?.sortedBy { it.date }?.toList()
}
}