mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-25 23:24:37 -06:00
Add class name to student (#315)
This commit is contained in:
parent
297a2909ba
commit
8daea5c900
@ -11,10 +11,10 @@ cache:
|
|||||||
- $HOME/.gradle/caches/
|
- $HOME/.gradle/caches/
|
||||||
- $HOME/.gradle/wrapper/
|
- $HOME/.gradle/wrapper/
|
||||||
|
|
||||||
#branches:
|
branches:
|
||||||
# only:
|
only:
|
||||||
# - master
|
- master
|
||||||
# - 0.7.x
|
- 0.7.x
|
||||||
|
|
||||||
android:
|
android:
|
||||||
licenses:
|
licenses:
|
||||||
|
@ -86,7 +86,7 @@ play {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation('io.github.wulkanowy:api:0.7.4') { exclude module: "threetenbp" }
|
implementation('com.github.wulkanowy:api:383ff93') { exclude module: "threetenbp" }
|
||||||
|
|
||||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||||
implementation "androidx.appcompat:appcompat:1.0.2"
|
implementation "androidx.appcompat:appcompat:1.0.2"
|
||||||
|
1356
app/schemas/io.github.wulkanowy.data.db.AppDatabase/13.json
Normal file
1356
app/schemas/io.github.wulkanowy.data.db.AppDatabase/13.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
|||||||
|
package io.github.wulkanowy.data.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.testing.MigrationTestHelper
|
||||||
|
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import io.github.wulkanowy.data.db.AppDatabase
|
||||||
|
import org.junit.Rule
|
||||||
|
|
||||||
|
abstract class AbstractMigrationTest {
|
||||||
|
|
||||||
|
val dbName = "migration-test"
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val helper: MigrationTestHelper = MigrationTestHelper(
|
||||||
|
InstrumentationRegistry.getInstrumentation(),
|
||||||
|
AppDatabase::class.java.canonicalName,
|
||||||
|
FrameworkSQLiteOpenHelperFactory()
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getMigratedRoomDatabase(): AppDatabase {
|
||||||
|
val database = Room.databaseBuilder(ApplicationProvider.getApplicationContext(),
|
||||||
|
AppDatabase::class.java, dbName)
|
||||||
|
.addMigrations(Migration12(), Migration13())
|
||||||
|
.build()
|
||||||
|
// close the database and release any stream resources when the test finishes
|
||||||
|
helper.closeWhenFinished(database)
|
||||||
|
return database
|
||||||
|
}
|
||||||
|
}
|
@ -2,33 +2,17 @@ package io.github.wulkanowy.data.db.migrations
|
|||||||
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.database.sqlite.SQLiteDatabase.CONFLICT_FAIL
|
import android.database.sqlite.SQLiteDatabase.CONFLICT_FAIL
|
||||||
import androidx.room.Room
|
|
||||||
import androidx.room.testing.MigrationTestHelper
|
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
|
|
||||||
import androidx.test.core.app.ApplicationProvider
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
|
||||||
import io.github.wulkanowy.data.db.AppDatabase
|
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class Migration12Test {
|
class Migration12Test : AbstractMigrationTest() {
|
||||||
|
|
||||||
private val dbName = "migration-test"
|
|
||||||
|
|
||||||
@get:Rule
|
|
||||||
val helper: MigrationTestHelper = MigrationTestHelper(
|
|
||||||
InstrumentationRegistry.getInstrumentation(),
|
|
||||||
AppDatabase::class.java.canonicalName,
|
|
||||||
FrameworkSQLiteOpenHelperFactory()
|
|
||||||
)
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun migrate11To12_twoNotRelatedStudents() {
|
fun twoNotRelatedStudents() {
|
||||||
helper.createDatabase(dbName, 11).apply {
|
helper.createDatabase(dbName, 11).apply {
|
||||||
// user 1
|
// user 1
|
||||||
createStudent(this, 1, true)
|
createStudent(this, 1, true)
|
||||||
@ -61,7 +45,7 @@ class Migration12Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun migrate11To12_removeStudentsWithoutClassId() {
|
fun removeStudentsWithoutClassId() {
|
||||||
helper.createDatabase(dbName, 11).apply {
|
helper.createDatabase(dbName, 11).apply {
|
||||||
// user 1
|
// user 1
|
||||||
createStudent(this, 1, true)
|
createStudent(this, 1, true)
|
||||||
@ -85,7 +69,7 @@ class Migration12Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun migrate11To12_ensureThereIsOnlyOneCurrentStudent() {
|
fun ensureThereIsOnlyOneCurrentStudent() {
|
||||||
helper.createDatabase(dbName, 11).apply {
|
helper.createDatabase(dbName, 11).apply {
|
||||||
// user 1
|
// user 1
|
||||||
createStudent(this, 1, true)
|
createStudent(this, 1, true)
|
||||||
@ -146,14 +130,4 @@ class Migration12Test {
|
|||||||
put("unit_id", "99")
|
put("unit_id", "99")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMigratedRoomDatabase(): AppDatabase {
|
|
||||||
val database = Room.databaseBuilder(ApplicationProvider.getApplicationContext(),
|
|
||||||
AppDatabase::class.java, dbName)
|
|
||||||
.addMigrations(Migration12())
|
|
||||||
.build()
|
|
||||||
// close the database and release any stream resources when the test finishes
|
|
||||||
helper.closeWhenFinished(database)
|
|
||||||
return database
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,171 @@
|
|||||||
|
package io.github.wulkanowy.data.db.migrations
|
||||||
|
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.database.sqlite.SQLiteDatabase
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Test
|
||||||
|
import org.threeten.bp.LocalDate.of
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
class Migration13Test : AbstractMigrationTest() {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun studentsWithSchoolNameWithClassName() {
|
||||||
|
helper.createDatabase(dbName, 12).apply {
|
||||||
|
createStudent(this, 1, "Klasa A - Publiczna szkoła Wulkanowego nr 1 w fakelog.cf", 1, 1)
|
||||||
|
createStudent(this, 2, "Klasa B - Publiczna szkoła Wulkanowego-fejka nr 1 w fakelog.cf", 2, 1)
|
||||||
|
createStudent(this, 2, "Klasa C - Publiczna szkoła Wulkanowego-fejka nr 2 w fakelog.cf", 1, 2)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.runMigrationsAndValidate(dbName, 13, true, Migration13())
|
||||||
|
|
||||||
|
val db = getMigratedRoomDatabase()
|
||||||
|
val students = db.studentDao.loadAll().blockingGet()
|
||||||
|
|
||||||
|
assertEquals(3, students.size)
|
||||||
|
|
||||||
|
students[0].run {
|
||||||
|
assertEquals(1, studentId)
|
||||||
|
assertEquals("A", className)
|
||||||
|
assertEquals("Publiczna szkoła Wulkanowego nr 1 w fakelog.cf", schoolName)
|
||||||
|
}
|
||||||
|
|
||||||
|
students[1].run {
|
||||||
|
assertEquals(2, studentId)
|
||||||
|
assertEquals("B", className)
|
||||||
|
assertEquals("Publiczna szkoła Wulkanowego-fejka nr 1 w fakelog.cf", schoolName)
|
||||||
|
}
|
||||||
|
|
||||||
|
students[2].run {
|
||||||
|
assertEquals(2, studentId)
|
||||||
|
assertEquals("C", className)
|
||||||
|
assertEquals("Publiczna szkoła Wulkanowego-fejka nr 2 w fakelog.cf", schoolName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun studentsWithSchoolNameWithoutClassName() {
|
||||||
|
helper.createDatabase(dbName, 12).apply {
|
||||||
|
createStudent(this, 1, "Publiczna szkoła Wulkanowego nr 1 w fakelog.cf", 1)
|
||||||
|
createStudent(this, 2, "Publiczna szkoła Wulkanowego-fejka nr 1 w fakelog.cf", 1)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.runMigrationsAndValidate(dbName, 13, true, Migration13())
|
||||||
|
|
||||||
|
val db = getMigratedRoomDatabase()
|
||||||
|
val students = db.studentDao.loadAll().blockingGet()
|
||||||
|
|
||||||
|
assertEquals(2, students.size)
|
||||||
|
|
||||||
|
students[0].run {
|
||||||
|
assertEquals(1, studentId)
|
||||||
|
assertEquals("", className)
|
||||||
|
assertEquals("Publiczna szkoła Wulkanowego nr 1 w fakelog.cf", schoolName)
|
||||||
|
}
|
||||||
|
|
||||||
|
students[1].run {
|
||||||
|
assertEquals(2, studentId)
|
||||||
|
assertEquals("", className)
|
||||||
|
assertEquals("Publiczna szkoła Wulkanowego-fejka nr 1 w fakelog.cf", schoolName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun markAtLeastAndOnlyOneSemesterAtCurrent() {
|
||||||
|
helper.createDatabase(dbName, 12).apply {
|
||||||
|
createStudent(this, 1, "", 5)
|
||||||
|
createSemester(this, 1, 5, 1, 1, false)
|
||||||
|
createSemester(this, 1, 5, 2, 1, false)
|
||||||
|
createSemester(this, 1, 5, 3, 2, false)
|
||||||
|
createSemester(this, 1, 5, 4, 2, false)
|
||||||
|
|
||||||
|
createStudent(this, 2, "", 5)
|
||||||
|
createSemester(this, 2, 5, 5, 5, true)
|
||||||
|
createSemester(this, 2, 5, 6, 5, true)
|
||||||
|
createSemester(this, 2, 5, 7, 55, true)
|
||||||
|
createSemester(this, 2, 5, 8, 55, true)
|
||||||
|
|
||||||
|
createStudent(this, 3, "", 5)
|
||||||
|
createSemester(this, 3, 5, 11, 99, false)
|
||||||
|
createSemester(this, 3, 5, 12, 99, false)
|
||||||
|
createSemester(this, 3, 5, 13, 100, false)
|
||||||
|
createSemester(this, 3, 5, 14, 100, true)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.runMigrationsAndValidate(dbName, 13, true, Migration13())
|
||||||
|
|
||||||
|
val db = getMigratedRoomDatabase()
|
||||||
|
|
||||||
|
val semesters1 = db.semesterDao.loadAll(1, 5).blockingGet()
|
||||||
|
assertTrue { semesters1.single { it.isCurrent }.isCurrent }
|
||||||
|
semesters1[0].run {
|
||||||
|
assertFalse(isCurrent)
|
||||||
|
assertEquals(1, semesterId)
|
||||||
|
assertEquals(1, diaryId)
|
||||||
|
}
|
||||||
|
semesters1[2].run {
|
||||||
|
assertFalse(isCurrent)
|
||||||
|
assertEquals(3, semesterId)
|
||||||
|
assertEquals(2, diaryId)
|
||||||
|
}
|
||||||
|
semesters1[3].run {
|
||||||
|
assertTrue(isCurrent)
|
||||||
|
assertEquals(4, semesterId)
|
||||||
|
assertEquals(2, diaryId)
|
||||||
|
}
|
||||||
|
|
||||||
|
db.semesterDao.loadAll(2, 5).blockingGet().let {
|
||||||
|
assertTrue { it.single { it.isCurrent }.isCurrent }
|
||||||
|
assertEquals(1970, it[0].schoolYear)
|
||||||
|
assertEquals(of(1970, 1, 1), it[0].end)
|
||||||
|
assertEquals(of(1970, 1, 1), it[0].start)
|
||||||
|
assertFalse(it[0].isCurrent)
|
||||||
|
assertFalse(it[1].isCurrent)
|
||||||
|
assertFalse(it[2].isCurrent)
|
||||||
|
assertTrue(it[3].isCurrent)
|
||||||
|
}
|
||||||
|
|
||||||
|
db.semesterDao.loadAll(2, 5).blockingGet().let {
|
||||||
|
assertTrue { it.single { it.isCurrent }.isCurrent }
|
||||||
|
assertFalse(it[0].isCurrent)
|
||||||
|
assertFalse(it[1].isCurrent)
|
||||||
|
assertFalse(it[2].isCurrent)
|
||||||
|
assertTrue(it[3].isCurrent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createStudent(db: SupportSQLiteDatabase, studentId: Int, schoolName: String = "", classId: Int = -1, schoolId: Int = 123) {
|
||||||
|
db.insert("Students", SQLiteDatabase.CONFLICT_FAIL, ContentValues().apply {
|
||||||
|
put("endpoint", "https://fakelog.cf")
|
||||||
|
put("loginType", "STANDARD")
|
||||||
|
put("email", "jan@fakelog.cf")
|
||||||
|
put("password", "******")
|
||||||
|
put("symbol", "Default")
|
||||||
|
put("student_id", studentId)
|
||||||
|
put("class_id", classId)
|
||||||
|
put("student_name", "Jan Kowalski")
|
||||||
|
put("school_id", schoolId)
|
||||||
|
put("school_name", schoolName)
|
||||||
|
put("is_current", false)
|
||||||
|
put("registration_date", "0")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createSemester(db: SupportSQLiteDatabase, studentId: Int, classId: Int, semesterId: Int, diaryId: Int, isCurrent: Boolean = false) {
|
||||||
|
db.insert("Semesters", SQLiteDatabase.CONFLICT_FAIL, ContentValues().apply {
|
||||||
|
put("student_id", studentId)
|
||||||
|
put("diary_id", diaryId)
|
||||||
|
put("diary_name", "IA")
|
||||||
|
put("semester_id", semesterId)
|
||||||
|
put("semester_name", "1")
|
||||||
|
put("is_current", isCurrent)
|
||||||
|
put("class_id", classId)
|
||||||
|
put("unit_id", "99")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ import org.junit.Before
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.threeten.bp.LocalDate
|
import org.threeten.bp.LocalDate
|
||||||
|
import org.threeten.bp.LocalDate.now
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@ -40,7 +41,7 @@ class AttendanceLocalTest {
|
|||||||
))
|
))
|
||||||
|
|
||||||
val attendance = attendanceLocal
|
val attendance = attendanceLocal
|
||||||
.getAttendance(Semester(1, 2, "", 1, 3, true, 1, 1),
|
.getAttendance(Semester(1, 2, "", 1, 3, 2019, true, now(), now(), 1, 1),
|
||||||
LocalDate.of(2018, 9, 10),
|
LocalDate.of(2018, 9, 10),
|
||||||
LocalDate.of(2018, 9, 14)
|
LocalDate.of(2018, 9, 14)
|
||||||
)
|
)
|
||||||
|
@ -41,7 +41,7 @@ class CompletedLessonsLocalTest {
|
|||||||
))
|
))
|
||||||
|
|
||||||
val completed = completedLessonsLocal
|
val completed = completedLessonsLocal
|
||||||
.getCompletedLessons(Semester(1, 2, "", 1, 3, true, 1, 1),
|
.getCompletedLessons(Semester(1, 2, "", 1, 3, 2019, true, LocalDate.now(), LocalDate.now(), 1, 1),
|
||||||
LocalDate.of(2018, 9, 10),
|
LocalDate.of(2018, 9, 10),
|
||||||
LocalDate.of(2018, 9, 14)
|
LocalDate.of(2018, 9, 14)
|
||||||
)
|
)
|
||||||
|
@ -40,7 +40,7 @@ class ExamLocalTest {
|
|||||||
))
|
))
|
||||||
|
|
||||||
val exams = examLocal
|
val exams = examLocal
|
||||||
.getExams(Semester(1, 2, "", 1, 3, true, 1, 1),
|
.getExams(Semester(1, 2, "", 1, 3, 2019, true, LocalDate.now(), LocalDate.now(), 1, 1),
|
||||||
LocalDate.of(2018, 9, 10),
|
LocalDate.of(2018, 9, 10),
|
||||||
LocalDate.of(2018, 9, 14)
|
LocalDate.of(2018, 9, 14)
|
||||||
)
|
)
|
||||||
|
@ -10,6 +10,7 @@ import org.junit.Before
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.threeten.bp.LocalDate
|
import org.threeten.bp.LocalDate
|
||||||
|
import org.threeten.bp.LocalDate.now
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@ -39,8 +40,10 @@ class GradeLocalTest {
|
|||||||
createGradeLocal(3, 5.0, LocalDate.of(2019, 2, 28), "", 2)
|
createGradeLocal(3, 5.0, LocalDate.of(2019, 2, 28), "", 2)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
val semester = Semester(1, 2, "", 2019, 2, 1, true, now(), now(), 1, 1)
|
||||||
|
|
||||||
val grades = gradeLocal
|
val grades = gradeLocal
|
||||||
.getGrades(Semester(1, 2, "", 2, 3, true, 1, 1))
|
.getGrades(semester)
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
|
|
||||||
assertEquals(2, grades.size)
|
assertEquals(2, grades.size)
|
||||||
|
@ -10,6 +10,7 @@ import org.junit.After
|
|||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
import org.threeten.bp.LocalDate
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@ -39,7 +40,7 @@ class GradeStatisticsLocalTest {
|
|||||||
))
|
))
|
||||||
|
|
||||||
val stats = gradeStatisticsLocal.getGradesStatistics(
|
val stats = gradeStatisticsLocal.getGradesStatistics(
|
||||||
Semester(2, 2, "", 1, 2, true, 1, 1), false,
|
Semester(2, 2, "", 2019, 1, 2, true, LocalDate.now(), LocalDate.now(), 1, 1), false,
|
||||||
"Matematyka"
|
"Matematyka"
|
||||||
).blockingGet()
|
).blockingGet()
|
||||||
assertEquals(1, stats.size)
|
assertEquals(1, stats.size)
|
||||||
@ -55,7 +56,7 @@ class GradeStatisticsLocalTest {
|
|||||||
))
|
))
|
||||||
|
|
||||||
val stats = gradeStatisticsLocal.getGradesStatistics(
|
val stats = gradeStatisticsLocal.getGradesStatistics(
|
||||||
Semester(2, 2, "", 1, 2, true, 1, 1), false,
|
Semester(2, 2, "", 2019, 1, 2, true, LocalDate.now(), LocalDate.now(), 1, 1), false,
|
||||||
"Wszystkie"
|
"Wszystkie"
|
||||||
).blockingGet()
|
).blockingGet()
|
||||||
assertEquals(1, stats.size)
|
assertEquals(1, stats.size)
|
||||||
|
@ -36,7 +36,7 @@ class LuckyNumberLocalTest {
|
|||||||
fun saveAndReadTest() {
|
fun saveAndReadTest() {
|
||||||
luckyNumberLocal.saveLuckyNumber(LuckyNumber(1, LocalDate.of(2019, 1, 20), 14))
|
luckyNumberLocal.saveLuckyNumber(LuckyNumber(1, LocalDate.of(2019, 1, 20), 14))
|
||||||
|
|
||||||
val luckyNumber = luckyNumberLocal.getLuckyNumber(Semester(1, 1, "", 1, 3, true, 1, 1),
|
val luckyNumber = luckyNumberLocal.getLuckyNumber(Semester(1, 1, "", 1, 3, 2019, true, LocalDate.now(), LocalDate.now(), 1, 1),
|
||||||
LocalDate.of(2019, 1, 20)
|
LocalDate.of(2019, 1, 20)
|
||||||
).blockingGet()
|
).blockingGet()
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class RecipientLocalTest {
|
|||||||
))
|
))
|
||||||
|
|
||||||
val recipients = recipientLocal.getRecipients(
|
val recipients = recipientLocal.getRecipients(
|
||||||
Student("fakelog.cf", "AUTO", "", "", "", 1, "", "", "", 1, true, LocalDateTime.now()),
|
Student("fakelog.cf", "AUTO", "", "", "", 1, "", "", "", "", 1, true, LocalDateTime.now()),
|
||||||
2,
|
2,
|
||||||
ReportingUnit(1, 4, "", 0, "", emptyList())
|
ReportingUnit(1, 4, "", 0, "", emptyList())
|
||||||
).blockingGet()
|
).blockingGet()
|
||||||
|
@ -39,7 +39,7 @@ class StudentLocalTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun saveAndReadTest() {
|
fun saveAndReadTest() {
|
||||||
studentLocal.saveStudent(Student(email = "test", password = "test123", schoolSymbol = "23", endpoint = "fakelog.cf", loginType = "AUTO", isCurrent = true, studentName = "", schoolName = "", studentId = 0, classId = 1, symbol = "", registrationDate = now()))
|
studentLocal.saveStudent(Student(email = "test", password = "test123", schoolSymbol = "23", endpoint = "fakelog.cf", loginType = "AUTO", isCurrent = true, studentName = "", schoolName = "", studentId = 0, classId = 1, symbol = "", registrationDate = now(), className = ""))
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
|
|
||||||
val student = studentLocal.getCurrentStudent(true).blockingGet()
|
val student = studentLocal.getCurrentStudent(true).blockingGet()
|
||||||
|
@ -41,7 +41,7 @@ class TimetableLocalTest {
|
|||||||
))
|
))
|
||||||
|
|
||||||
val exams = timetableDb.getTimetable(
|
val exams = timetableDb.getTimetable(
|
||||||
Semester(1, 2, "", 1, 1, true, 1, 1),
|
Semester(1, 2, "", 1, 1, 2019, true, LocalDate.now(), LocalDate.now(), 1, 1),
|
||||||
LocalDate.of(2018, 9, 10),
|
LocalDate.of(2018, 9, 10),
|
||||||
LocalDate.of(2018, 9, 14)
|
LocalDate.of(2018, 9, 14)
|
||||||
).blockingGet()
|
).blockingGet()
|
||||||
|
@ -43,6 +43,7 @@ import io.github.wulkanowy.data.db.entities.Timetable
|
|||||||
import io.github.wulkanowy.data.db.migrations.Migration10
|
import io.github.wulkanowy.data.db.migrations.Migration10
|
||||||
import io.github.wulkanowy.data.db.migrations.Migration11
|
import io.github.wulkanowy.data.db.migrations.Migration11
|
||||||
import io.github.wulkanowy.data.db.migrations.Migration12
|
import io.github.wulkanowy.data.db.migrations.Migration12
|
||||||
|
import io.github.wulkanowy.data.db.migrations.Migration13
|
||||||
import io.github.wulkanowy.data.db.migrations.Migration2
|
import io.github.wulkanowy.data.db.migrations.Migration2
|
||||||
import io.github.wulkanowy.data.db.migrations.Migration3
|
import io.github.wulkanowy.data.db.migrations.Migration3
|
||||||
import io.github.wulkanowy.data.db.migrations.Migration4
|
import io.github.wulkanowy.data.db.migrations.Migration4
|
||||||
@ -81,7 +82,7 @@ import javax.inject.Singleton
|
|||||||
abstract class AppDatabase : RoomDatabase() {
|
abstract class AppDatabase : RoomDatabase() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val VERSION_SCHEMA = 12
|
const val VERSION_SCHEMA = 13
|
||||||
|
|
||||||
fun newInstance(context: Context): AppDatabase {
|
fun newInstance(context: Context): AppDatabase {
|
||||||
return Room.databaseBuilder(context, AppDatabase::class.java, "wulkanowy_database")
|
return Room.databaseBuilder(context, AppDatabase::class.java, "wulkanowy_database")
|
||||||
@ -99,7 +100,8 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
Migration9(),
|
Migration9(),
|
||||||
Migration10(),
|
Migration10(),
|
||||||
Migration11(),
|
Migration11(),
|
||||||
Migration12()
|
Migration12(),
|
||||||
|
Migration13()
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import androidx.room.ColumnInfo
|
|||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
import org.threeten.bp.LocalDate
|
||||||
|
|
||||||
@Entity(tableName = "Semesters", indices = [Index(value = ["student_id", "diary_id", "semester_id"], unique = true)])
|
@Entity(tableName = "Semesters", indices = [Index(value = ["student_id", "diary_id", "semester_id"], unique = true)])
|
||||||
data class Semester(
|
data class Semester(
|
||||||
@ -17,6 +18,9 @@ data class Semester(
|
|||||||
@ColumnInfo(name = "diary_name")
|
@ColumnInfo(name = "diary_name")
|
||||||
val diaryName: String,
|
val diaryName: String,
|
||||||
|
|
||||||
|
@ColumnInfo(name = "school_year")
|
||||||
|
val schoolYear: Int,
|
||||||
|
|
||||||
@ColumnInfo(name = "semester_id")
|
@ColumnInfo(name = "semester_id")
|
||||||
val semesterId: Int,
|
val semesterId: Int,
|
||||||
|
|
||||||
@ -26,6 +30,10 @@ data class Semester(
|
|||||||
@ColumnInfo(name = "is_current")
|
@ColumnInfo(name = "is_current")
|
||||||
val isCurrent: Boolean,
|
val isCurrent: Boolean,
|
||||||
|
|
||||||
|
val start: LocalDate,
|
||||||
|
|
||||||
|
val end: LocalDate,
|
||||||
|
|
||||||
@ColumnInfo(name = "class_id")
|
@ColumnInfo(name = "class_id")
|
||||||
val classId: Int,
|
val classId: Int,
|
||||||
|
|
||||||
|
@ -32,6 +32,9 @@ data class Student(
|
|||||||
@ColumnInfo(name = "school_name")
|
@ColumnInfo(name = "school_name")
|
||||||
val schoolName: String,
|
val schoolName: String,
|
||||||
|
|
||||||
|
@ColumnInfo(name = "class_name")
|
||||||
|
val className: String,
|
||||||
|
|
||||||
@ColumnInfo(name = "class_id")
|
@ColumnInfo(name = "class_id")
|
||||||
val classId: Int,
|
val classId: Int,
|
||||||
|
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package io.github.wulkanowy.data.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
class Migration13 : Migration(12, 13) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
addClassNameToStudents(database, getStudentsIds(database))
|
||||||
|
updateSemestersTable(database)
|
||||||
|
markAtLeastAndOnlyOneSemesterAtCurrent(database, getStudentsAndClassIds(database))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addClassNameToStudents(database: SupportSQLiteDatabase, students: List<Pair<Int, String>>) {
|
||||||
|
database.execSQL("ALTER TABLE Students ADD COLUMN class_name TEXT DEFAULT \"\" NOT NULL")
|
||||||
|
|
||||||
|
students.forEach { (id, name) ->
|
||||||
|
val schoolName = name.substringAfter(" - ")
|
||||||
|
val className = name.substringBefore(" - ", "").replace("Klasa ", "")
|
||||||
|
database.execSQL("UPDATE Students SET class_name = '$className' WHERE id = '$id'")
|
||||||
|
database.execSQL("UPDATE Students SET school_name = '$schoolName' WHERE id = '$id'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getStudentsIds(database: SupportSQLiteDatabase): MutableList<Pair<Int, String>> {
|
||||||
|
val students = mutableListOf<Pair<Int, String>>()
|
||||||
|
val studentsCursor = database.query("SELECT id, school_name FROM Students")
|
||||||
|
if (studentsCursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
students.add(studentsCursor.getInt(0) to studentsCursor.getString(1))
|
||||||
|
} while (studentsCursor.moveToNext())
|
||||||
|
}
|
||||||
|
return students
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateSemestersTable(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE Semesters ADD COLUMN school_year INTEGER DEFAULT 1970 NOT NULL")
|
||||||
|
database.execSQL("ALTER TABLE Semesters ADD COLUMN start INTEGER DEFAULT 0 NOT NULL")
|
||||||
|
database.execSQL("ALTER TABLE Semesters ADD COLUMN `end` INTEGER DEFAULT 0 NOT NULL")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getStudentsAndClassIds(database: SupportSQLiteDatabase): List<Pair<Int, Int>> {
|
||||||
|
val students = mutableListOf<Pair<Int, Int>>()
|
||||||
|
val studentsCursor = database.query("SELECT student_id, class_id FROM Students")
|
||||||
|
if (studentsCursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
students.add(studentsCursor.getInt(0) to studentsCursor.getInt(1))
|
||||||
|
} while (studentsCursor.moveToNext())
|
||||||
|
}
|
||||||
|
return students
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun markAtLeastAndOnlyOneSemesterAtCurrent(database: SupportSQLiteDatabase, students: List<Pair<Int, Int>>) {
|
||||||
|
students.forEach { (studentId, classId) ->
|
||||||
|
database.execSQL("UPDATE Semesters SET is_current = 0 WHERE student_id = '$studentId' AND class_id = '$classId'")
|
||||||
|
database.execSQL("UPDATE Semesters SET is_current = 1 WHERE id = (SELECT id FROM Semesters WHERE student_id = '$studentId' AND class_id = '$classId' ORDER BY semester_id DESC)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,9 +17,12 @@ class SemesterRemote @Inject constructor(private val api: Api) {
|
|||||||
studentId = student.studentId,
|
studentId = student.studentId,
|
||||||
diaryId = semester.diaryId,
|
diaryId = semester.diaryId,
|
||||||
diaryName = semester.diaryName,
|
diaryName = semester.diaryName,
|
||||||
|
schoolYear = semester.schoolYear,
|
||||||
semesterId = semester.semesterId,
|
semesterId = semester.semesterId,
|
||||||
semesterName = semester.semesterNumber,
|
semesterName = semester.semesterNumber,
|
||||||
isCurrent = semester.current,
|
isCurrent = semester.current,
|
||||||
|
start = semester.start,
|
||||||
|
end = semester.end,
|
||||||
classId = semester.classId,
|
classId = semester.classId,
|
||||||
unitId = semester.unitId
|
unitId = semester.unitId
|
||||||
)
|
)
|
||||||
|
@ -21,6 +21,7 @@ class StudentRemote @Inject constructor(private val api: Api) {
|
|||||||
studentName = student.studentName,
|
studentName = student.studentName,
|
||||||
schoolSymbol = student.schoolSymbol,
|
schoolSymbol = student.schoolSymbol,
|
||||||
schoolName = student.schoolName,
|
schoolName = student.schoolName,
|
||||||
|
className = student.className,
|
||||||
classId = student.classId,
|
classId = student.classId,
|
||||||
endpoint = endpoint,
|
endpoint = endpoint,
|
||||||
loginType = student.loginType.name,
|
loginType = student.loginType.name,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.ui.modules.account
|
package io.github.wulkanowy.ui.modules.account
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||||
@ -18,9 +19,10 @@ class AccountItem(val student: Student) : AbstractFlexibleItem<AccountItem.ViewH
|
|||||||
return ViewHolder(view, adapter)
|
return ViewHolder(view, adapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ViewHolder, position: Int, payloads: MutableList<Any>?) {
|
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ViewHolder, position: Int, payloads: MutableList<Any>?) {
|
||||||
holder.apply {
|
holder.apply {
|
||||||
accountItemName.text = student.studentName
|
accountItemName.text = "${student.studentName} ${student.className}"
|
||||||
accountItemSchool.text = student.schoolName
|
accountItemSchool.text = student.schoolName
|
||||||
accountItemImage.setBackgroundResource(if (student.isCurrent) R.drawable.ic_account_circular_border else 0)
|
accountItemImage.setBackgroundResource(if (student.isCurrent) R.drawable.ic_account_circular_border else 0)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.ui.modules.login.studentselect
|
package io.github.wulkanowy.ui.modules.login.studentselect
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||||
@ -18,9 +19,10 @@ class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem<LoginS
|
|||||||
return ItemViewHolder(view, adapter)
|
return ItemViewHolder(view, adapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ItemViewHolder, position: Int, payloads: MutableList<Any>?) {
|
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ItemViewHolder, position: Int, payloads: MutableList<Any>?) {
|
||||||
holder.run {
|
holder.run {
|
||||||
loginItemName.text = student.studentName
|
loginItemName.text = "${student.studentName} ${student.className}"
|
||||||
loginItemSchool.text = student.schoolName
|
loginItemSchool.text = student.schoolName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,10 @@
|
|||||||
android:layout_marginLeft="20dp"
|
android:layout_marginLeft="20dp"
|
||||||
android:layout_toEndOf="@id/accountItemImage"
|
android:layout_toEndOf="@id/accountItemImage"
|
||||||
android:layout_toRightOf="@id/accountItemImage"
|
android:layout_toRightOf="@id/accountItemImage"
|
||||||
android:text="@string/app_name"
|
android:ellipsize="end"
|
||||||
android:textSize="16sp" />
|
android:maxLines="1"
|
||||||
|
android:textSize="16sp"
|
||||||
|
tools:text="@tools:sample/lorem/random" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/accountItemSchool"
|
android:id="@+id/accountItemSchool"
|
||||||
@ -45,6 +47,6 @@
|
|||||||
android:layout_toRightOf="@id/accountItemImage"
|
android:layout_toRightOf="@id/accountItemImage"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:text="@string/app_name"
|
android:textSize="12sp"
|
||||||
android:textSize="12sp" />
|
tools:text="@tools:sample/lorem/random" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.wulkanowy.data.repositories.semester
|
package io.github.wulkanowy.data.repositories.semester
|
||||||
|
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
|
import org.threeten.bp.LocalDate.now
|
||||||
|
|
||||||
fun createSemesterEntity(current: Boolean): Semester {
|
fun createSemesterEntity(current: Boolean): Semester {
|
||||||
return Semester(
|
return Semester(
|
||||||
@ -8,9 +9,12 @@ fun createSemesterEntity(current: Boolean): Semester {
|
|||||||
diaryId = 0,
|
diaryId = 0,
|
||||||
semesterId = 0,
|
semesterId = 0,
|
||||||
diaryName = "",
|
diaryName = "",
|
||||||
|
schoolYear = 1970,
|
||||||
classId = 0,
|
classId = 0,
|
||||||
isCurrent = current,
|
isCurrent = current,
|
||||||
semesterName = 0,
|
semesterName = 0,
|
||||||
unitId = 0
|
unitId = 0,
|
||||||
|
start = now(),
|
||||||
|
end = now()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class StudentRemoteTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testRemoteAll() {
|
fun testRemoteAll() {
|
||||||
doReturn(Single.just(listOf(Student("", "", 1, "test", "", "", 1, Api.LoginType.AUTO))))
|
doReturn(Single.just(listOf(Student("", "", 1, "test", "", "", "", 1, Api.LoginType.AUTO))))
|
||||||
.`when`(mockApi).getStudents()
|
.`when`(mockApi).getStudents()
|
||||||
|
|
||||||
val students = StudentRemote(mockApi).getStudents("", "", "").blockingGet()
|
val students = StudentRemote(mockApi).getStudents("", "", "").blockingGet()
|
||||||
|
@ -86,7 +86,7 @@ class LoginFormPresenterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun loginTest() {
|
fun loginTest() {
|
||||||
val studentTest = Student(email = "test@", password = "123", endpoint = "https://fakelog.cf", loginType = "AUTO", studentName = "", schoolSymbol = "", schoolName = "", studentId = 0, classId = 1, isCurrent = false, symbol = "", registrationDate = now())
|
val studentTest = Student(email = "test@", password = "123", endpoint = "https://fakelog.cf", loginType = "AUTO", studentName = "", schoolSymbol = "", schoolName = "", studentId = 0, classId = 1, isCurrent = false, symbol = "", registrationDate = now(), className = "")
|
||||||
doReturn(Single.just(listOf(studentTest)))
|
doReturn(Single.just(listOf(studentTest)))
|
||||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class LoginStudentSelectPresenterTest {
|
|||||||
|
|
||||||
private lateinit var presenter: LoginStudentSelectPresenter
|
private lateinit var presenter: LoginStudentSelectPresenter
|
||||||
|
|
||||||
private val testStudent by lazy { Student(email = "test", password = "test123", endpoint = "https://fakelog.cf", loginType = "AUTO", symbol = "", isCurrent = false, studentId = 0, schoolName = "", schoolSymbol = "", classId = 1, studentName = "", registrationDate = now()) }
|
private val testStudent by lazy { Student(email = "test", password = "test123", endpoint = "https://fakelog.cf", loginType = "AUTO", symbol = "", isCurrent = false, studentId = 0, schoolName = "", schoolSymbol = "", classId = 1, studentName = "", registrationDate = now(), className = "") }
|
||||||
|
|
||||||
private val testException by lazy { RuntimeException("Problem") }
|
private val testException by lazy { RuntimeException("Problem") }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user