mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 02:56:45 -06:00
Mitigate disappearing teachers in timetable (#485)
This commit is contained in:
parent
e64e6676f3
commit
c3bb489851
@ -7,7 +7,7 @@ import org.threeten.bp.LocalDateTime.now
|
||||
import io.github.wulkanowy.api.timetable.Timetable as TimetableRemote
|
||||
import io.github.wulkanowy.data.db.entities.Timetable as TimetableLocal
|
||||
|
||||
fun createTimetableLocal(number: Int, start: LocalDateTime, room: String = "", subject: String = "", teacher: String = ""): TimetableLocal {
|
||||
fun createTimetableLocal(number: Int, start: LocalDateTime, room: String = "", subject: String = "", teacher: String = "", changes: Boolean = false): TimetableLocal {
|
||||
return TimetableLocal(
|
||||
studentId = 1,
|
||||
diaryId = 2,
|
||||
@ -23,12 +23,12 @@ fun createTimetableLocal(number: Int, start: LocalDateTime, room: String = "", s
|
||||
teacher = teacher,
|
||||
teacherOld = "",
|
||||
info = "",
|
||||
changes = false,
|
||||
changes = changes,
|
||||
canceled = false
|
||||
)
|
||||
}
|
||||
|
||||
fun createTimetableRemote(number: Int, start: LocalDateTime, room: String, subject: String = "", teacher: String = ""): TimetableRemote {
|
||||
fun createTimetableRemote(number: Int, start: LocalDateTime, room: String, subject: String = "", teacher: String = "", changes: Boolean = false): TimetableRemote {
|
||||
return TimetableRemote(
|
||||
number = number,
|
||||
start = start.toDate(),
|
||||
@ -39,7 +39,7 @@ fun createTimetableRemote(number: Int, start: LocalDateTime, room: String, subje
|
||||
room = room,
|
||||
teacher = teacher,
|
||||
info = "",
|
||||
changes = false,
|
||||
changes = changes,
|
||||
canceled = false
|
||||
)
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class TimetableRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun copyDetailsToCompletedFromPrevious() {
|
||||
fun copyRoomToCompletedFromPrevious() {
|
||||
timetableLocal.saveTimetable(listOf(
|
||||
createTimetableLocal(1, of(2019, 3, 5, 8, 0), "123", "Przyroda"),
|
||||
createTimetableLocal(2, of(2019, 3, 5, 8, 50), "321", "Religia"),
|
||||
@ -83,7 +83,32 @@ class TimetableRepositoryTest {
|
||||
assertEquals("123", lessons[0].room)
|
||||
assertEquals("321", lessons[1].room)
|
||||
assertEquals("213", lessons[2].room)
|
||||
}
|
||||
|
||||
assertEquals("", lessons[3].teacher)
|
||||
@Test
|
||||
fun copyTeacherToCompletedFromPrevious() {
|
||||
timetableLocal.saveTimetable(listOf(
|
||||
createTimetableLocal(1, of(2019, 3, 5, 8, 0), "123", "Przyroda", "Jan Garnkiewicz", false),
|
||||
createTimetableLocal(2, of(2019, 3, 5, 8, 50), "321", "Religia", "Paweł Jumper", false),
|
||||
createTimetableLocal(3, of(2019, 3, 5, 9, 40), "213", "W-F", "", true),
|
||||
createTimetableLocal(4, of(2019, 3, 5, 10, 30), "213", "W-F", "", false)
|
||||
))
|
||||
|
||||
every { mockApi.getTimetable(any(), any()) } returns Single.just(listOf(
|
||||
createTimetableRemote(1, of(2019, 3, 5, 8, 0), "", "Przyroda", "", true), // should override local
|
||||
createTimetableRemote(2, of(2019, 3, 5, 8, 50), "", "Religia", "", false),
|
||||
createTimetableRemote(3, of(2019, 3, 5, 9, 40), "", "W-F", "Jan Garnkiewicz", false),
|
||||
createTimetableRemote(4, of(2019, 3, 5, 10, 30), "", "W-F", "Paweł Jumper", false)
|
||||
))
|
||||
|
||||
val lessons = TimetableRepository(settings, timetableLocal, timetableRemote)
|
||||
.getTimetable(semesterMock, LocalDate.of(2019, 3, 5), LocalDate.of(2019, 3, 5), true)
|
||||
.blockingGet()
|
||||
|
||||
assertEquals(4, lessons.size)
|
||||
assertEquals("", lessons[0].teacher)
|
||||
assertEquals("Paweł Jumper", lessons[1].teacher)
|
||||
assertEquals("Jan Garnkiewicz", lessons[2].teacher)
|
||||
assertEquals("Paweł Jumper", lessons[3].teacher)
|
||||
}
|
||||
}
|
||||
|
@ -32,10 +32,11 @@ class TimetableRepository @Inject constructor(
|
||||
.doOnSuccess { old ->
|
||||
local.deleteTimetable(old.uniqueSubtract(new))
|
||||
local.saveTimetable(new.uniqueSubtract(old).map { item ->
|
||||
item.apply {
|
||||
old.singleOrNull { this.start == it.start }?.let {
|
||||
return@map copy(
|
||||
room = if (room.isEmpty()) it.room else room
|
||||
item.also { new ->
|
||||
old.singleOrNull { new.start == it.start }?.let { old ->
|
||||
return@map new.copy(
|
||||
room = if (new.room.isEmpty()) old.room else new.room,
|
||||
teacher = if (new.teacher.isEmpty() && !new.changes) old.teacher else new.teacher
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user