forked from github/wulkanowy-mirror
Filter lucky numbers by school shortcut (#708)
This commit is contained in:
parent
8aaa066142
commit
87107ec474
@ -122,7 +122,7 @@ configurations.all {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "io.github.wulkanowy:sdk:6789442"
|
||||
implementation "io.github.wulkanowy:sdk:b3cdb3f"
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation "androidx.core:core-ktx:1.2.0"
|
||||
|
1658
app/schemas/io.github.wulkanowy.data.db.AppDatabase/22.json
Normal file
1658
app/schemas/io.github.wulkanowy.data.db.AppDatabase/22.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,11 +6,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import io.github.wulkanowy.data.db.AppDatabase
|
||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.threeten.bp.LocalDate
|
||||
import org.threeten.bp.LocalDateTime.now
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@ -36,7 +38,7 @@ class LuckyNumberLocalTest {
|
||||
fun saveAndReadTest() {
|
||||
luckyNumberLocal.saveLuckyNumber(LuckyNumber(1, LocalDate.of(2019, 1, 20), 14))
|
||||
|
||||
val luckyNumber = luckyNumberLocal.getLuckyNumber(Semester(1, 1, "", 1, 3, 2019, LocalDate.now(), LocalDate.now(), 1, 1),
|
||||
val luckyNumber = luckyNumberLocal.getLuckyNumber(Student("", "", "", "", "", "", false, "", "", "", 1, 1, "", "", "", "", "", 1, false, now()),
|
||||
LocalDate.of(2019, 1, 20)
|
||||
).blockingGet()
|
||||
|
||||
|
@ -42,7 +42,7 @@ class RecipientLocalTest {
|
||||
))
|
||||
|
||||
val recipients = recipientLocal.getRecipients(
|
||||
Student("fakelog.cf", "AUTO", "", "", "", "", false, "", "", "", 1, 0, "", "", "", "", 1, true, LocalDateTime.now()),
|
||||
Student("fakelog.cf", "AUTO", "", "", "", "", false, "", "", "", 1, 0, "", "", "", "", "", 1, true, LocalDateTime.now()),
|
||||
2,
|
||||
ReportingUnit(1, 4, "", 0, "", emptyList())
|
||||
).blockingGet()
|
||||
|
@ -39,7 +39,7 @@ class StudentLocalTest {
|
||||
|
||||
@Test
|
||||
fun saveAndReadTest() {
|
||||
studentLocal.saveStudents(listOf(Student(email = "test", password = "test123", schoolSymbol = "23", scrapperBaseUrl = "fakelog.cf", loginType = "AUTO", isCurrent = true, studentName = "", schoolName = "", studentId = 0, classId = 1, symbol = "", registrationDate = now(), className = "", loginMode = "API", certificateKey = "", privateKey = "", mobileBaseUrl = "", userLoginId = 0, isParent = false)))
|
||||
studentLocal.saveStudents(listOf(Student(email = "test", password = "test123", schoolSymbol = "23", scrapperBaseUrl = "fakelog.cf", loginType = "AUTO", isCurrent = true, studentName = "", schoolShortName = "", schoolName = "", studentId = 0, classId = 1, symbol = "", registrationDate = now(), className = "", loginMode = "API", certificateKey = "", privateKey = "", mobileBaseUrl = "", userLoginId = 0, isParent = false)))
|
||||
.blockingGet()
|
||||
|
||||
val student = studentLocal.getCurrentStudent(true).blockingGet()
|
||||
|
@ -62,6 +62,7 @@ import io.github.wulkanowy.data.db.migrations.Migration19
|
||||
import io.github.wulkanowy.data.db.migrations.Migration2
|
||||
import io.github.wulkanowy.data.db.migrations.Migration20
|
||||
import io.github.wulkanowy.data.db.migrations.Migration21
|
||||
import io.github.wulkanowy.data.db.migrations.Migration22
|
||||
import io.github.wulkanowy.data.db.migrations.Migration3
|
||||
import io.github.wulkanowy.data.db.migrations.Migration4
|
||||
import io.github.wulkanowy.data.db.migrations.Migration5
|
||||
@ -103,7 +104,7 @@ import javax.inject.Singleton
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
companion object {
|
||||
const val VERSION_SCHEMA = 21
|
||||
const val VERSION_SCHEMA = 22
|
||||
|
||||
fun getMigrations(sharedPrefProvider: SharedPrefProvider): Array<Migration> {
|
||||
return arrayOf(
|
||||
@ -126,7 +127,8 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
Migration18(),
|
||||
Migration19(sharedPrefProvider),
|
||||
Migration20(),
|
||||
Migration21()
|
||||
Migration21(),
|
||||
Migration22()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,9 @@ data class Student(
|
||||
@ColumnInfo(name = "school_id")
|
||||
val schoolSymbol: String,
|
||||
|
||||
@ColumnInfo(name ="school_short")
|
||||
val schoolShortName: String,
|
||||
|
||||
@ColumnInfo(name = "school_name")
|
||||
val schoolName: String,
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
package io.github.wulkanowy.data.db.migrations
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration22 : Migration(21, 22) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN school_short TEXT NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package io.github.wulkanowy.data.repositories.luckynumber
|
||||
|
||||
import io.github.wulkanowy.data.db.dao.LuckyNumberDao
|
||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.reactivex.Maybe
|
||||
import org.threeten.bp.LocalDate
|
||||
import javax.inject.Inject
|
||||
@ -23,7 +23,7 @@ class LuckyNumberLocal @Inject constructor(private val luckyNumberDb: LuckyNumbe
|
||||
luckyNumberDb.deleteAll(listOf(luckyNumber))
|
||||
}
|
||||
|
||||
fun getLuckyNumber(semester: Semester, date: LocalDate): Maybe<LuckyNumber> {
|
||||
return luckyNumberDb.load(semester.studentId, date)
|
||||
fun getLuckyNumber(student: Student, date: LocalDate): Maybe<LuckyNumber> {
|
||||
return luckyNumberDb.load(student.studentId, date)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.github.wulkanowy.data.repositories.luckynumber
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Maybe
|
||||
import org.threeten.bp.LocalDate
|
||||
@ -11,14 +11,13 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
class LuckyNumberRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getLuckyNumber(semester: Semester): Maybe<LuckyNumber> {
|
||||
return sdk.getLuckyNumber()
|
||||
.map {
|
||||
LuckyNumber(
|
||||
studentId = semester.studentId,
|
||||
date = LocalDate.now(),
|
||||
luckyNumber = it
|
||||
)
|
||||
}
|
||||
fun getLuckyNumber(student: Student): Maybe<LuckyNumber> {
|
||||
return sdk.getLuckyNumber(student.schoolShortName).map {
|
||||
LuckyNumber(
|
||||
studentId = student.studentId,
|
||||
date = LocalDate.now(),
|
||||
luckyNumber = it
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.github.wulkanowy.data.repositories.luckynumber
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
|
||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Maybe
|
||||
import org.threeten.bp.LocalDate
|
||||
@ -18,14 +18,14 @@ class LuckyNumberRepository @Inject constructor(
|
||||
private val remote: LuckyNumberRemote
|
||||
) {
|
||||
|
||||
fun getLuckyNumber(semester: Semester, forceRefresh: Boolean = false, notify: Boolean = false): Maybe<LuckyNumber> {
|
||||
return local.getLuckyNumber(semester, LocalDate.now()).filter { !forceRefresh }
|
||||
fun getLuckyNumber(student: Student, forceRefresh: Boolean = false, notify: Boolean = false): Maybe<LuckyNumber> {
|
||||
return local.getLuckyNumber(student, LocalDate.now()).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMapMaybe {
|
||||
if (it) remote.getLuckyNumber(semester)
|
||||
if (it) remote.getLuckyNumber(student)
|
||||
else Maybe.error(UnknownHostException())
|
||||
}.flatMap { new ->
|
||||
local.getLuckyNumber(semester, LocalDate.now())
|
||||
local.getLuckyNumber(student, LocalDate.now())
|
||||
.doOnSuccess { old ->
|
||||
if (new != old) {
|
||||
local.deleteLuckyNumber(old)
|
||||
@ -39,13 +39,13 @@ class LuckyNumberRepository @Inject constructor(
|
||||
if (notify) isNotified = false
|
||||
})
|
||||
}
|
||||
}.flatMap({ local.getLuckyNumber(semester, LocalDate.now()) }, { Maybe.error(it) },
|
||||
{ local.getLuckyNumber(semester, LocalDate.now()) })
|
||||
}.flatMap({ local.getLuckyNumber(student, LocalDate.now()) }, { Maybe.error(it) },
|
||||
{ local.getLuckyNumber(student, LocalDate.now()) })
|
||||
)
|
||||
}
|
||||
|
||||
fun getNotNotifiedLuckyNumber(semester: Semester): Maybe<LuckyNumber> {
|
||||
return local.getLuckyNumber(semester, LocalDate.now()).filter { !it.isNotified }
|
||||
fun getNotNotifiedLuckyNumber(student: Student): Maybe<LuckyNumber> {
|
||||
return local.getLuckyNumber(student, LocalDate.now()).filter { !it.isNotified }
|
||||
}
|
||||
|
||||
fun updateLuckyNumber(luckyNumber: LuckyNumber): Completable {
|
||||
|
@ -22,6 +22,7 @@ class StudentRemote @Inject constructor(private val sdk: Sdk) {
|
||||
userLoginId = student.userLoginId,
|
||||
studentName = student.studentName,
|
||||
schoolSymbol = student.schoolSymbol,
|
||||
schoolShortName = student.schoolShortName,
|
||||
schoolName = student.schoolName,
|
||||
className = student.className,
|
||||
classId = student.classId,
|
||||
|
@ -29,8 +29,8 @@ class LuckyNumberWork @Inject constructor(
|
||||
) : Work {
|
||||
|
||||
override fun create(student: Student, semester: Semester): Completable {
|
||||
return luckyNumberRepository.getLuckyNumber(semester, true, preferencesRepository.isNotificationsEnable)
|
||||
.flatMap { luckyNumberRepository.getNotNotifiedLuckyNumber(semester) }
|
||||
return luckyNumberRepository.getLuckyNumber(student, true, preferencesRepository.isNotificationsEnable)
|
||||
.flatMap { luckyNumberRepository.getNotNotifiedLuckyNumber(student) }
|
||||
.flatMapCompletable {
|
||||
notify(it)
|
||||
luckyNumberRepository.updateLuckyNumber(it.apply { isNotified = true })
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.github.wulkanowy.ui.modules.luckynumber
|
||||
|
||||
import io.github.wulkanowy.data.repositories.luckynumber.LuckyNumberRepository
|
||||
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
@ -15,7 +14,6 @@ class LuckyNumberPresenter @Inject constructor(
|
||||
errorHandler: ErrorHandler,
|
||||
studentRepository: StudentRepository,
|
||||
private val luckyNumberRepository: LuckyNumberRepository,
|
||||
private val semesterRepository: SemesterRepository,
|
||||
private val analytics: FirebaseAnalyticsHelper
|
||||
) : BasePresenter<LuckyNumberView>(errorHandler, studentRepository, schedulers) {
|
||||
|
||||
@ -38,7 +36,6 @@ class LuckyNumberPresenter @Inject constructor(
|
||||
disposable.apply {
|
||||
clear()
|
||||
add(studentRepository.getCurrentStudent()
|
||||
.flatMap { semesterRepository.getCurrentSemester(it) }
|
||||
.flatMapMaybe { luckyNumberRepository.getLuckyNumber(it, forceRefresh) }
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
|
@ -18,7 +18,6 @@ import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||
import io.github.wulkanowy.data.exceptions.NoCurrentStudentException
|
||||
import io.github.wulkanowy.data.repositories.luckynumber.LuckyNumberRepository
|
||||
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
@ -32,9 +31,6 @@ class LuckyNumberWidgetProvider : AppWidgetProvider() {
|
||||
@Inject
|
||||
lateinit var studentRepository: StudentRepository
|
||||
|
||||
@Inject
|
||||
lateinit var semesterRepository: SemesterRepository
|
||||
|
||||
@Inject
|
||||
lateinit var luckyNumberRepository: LuckyNumberRepository
|
||||
|
||||
@ -156,7 +152,6 @@ class LuckyNumberWidgetProvider : AppWidgetProvider() {
|
||||
else -> Maybe.empty()
|
||||
}
|
||||
}
|
||||
.flatMap { semesterRepository.getCurrentSemester(it).toMaybe() }
|
||||
.flatMap { luckyNumberRepository.getLuckyNumber(it) }
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.blockingGet()
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.wulkanowy.data.repositories.luckynumber
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
@ -18,7 +18,7 @@ class LuckyNumberRemoteTest {
|
||||
private var mockSdk = Sdk()
|
||||
|
||||
@MockK
|
||||
private lateinit var semesterMock: Semester
|
||||
private lateinit var studentMock: Student
|
||||
|
||||
@Before
|
||||
fun initApi() {
|
||||
@ -27,18 +27,18 @@ class LuckyNumberRemoteTest {
|
||||
|
||||
@Test
|
||||
fun getLuckyNumberTest() {
|
||||
every { mockSdk.getLuckyNumber() } returns Maybe.just(14)
|
||||
every { mockSdk.getLuckyNumber("test") } returns Maybe.just(14)
|
||||
|
||||
every { mockSdk.diaryId } returns 1
|
||||
every { semesterMock.studentId } returns 1
|
||||
every { semesterMock.diaryId } returns 1
|
||||
every { studentMock.studentId } returns 1
|
||||
every { studentMock.schoolShortName } returns "test"
|
||||
|
||||
val luckyNumber = LuckyNumberRemote(mockSdk)
|
||||
.getLuckyNumber(semesterMock)
|
||||
.getLuckyNumber(studentMock)
|
||||
.blockingGet()
|
||||
|
||||
assertEquals(14, luckyNumber.luckyNumber)
|
||||
assertEquals(LocalDate.now(), luckyNumber.date)
|
||||
assertEquals(semesterMock.studentId, luckyNumber.studentId)
|
||||
assertEquals(studentMock.studentId, luckyNumber.studentId)
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ class StudentRemoteTest {
|
||||
userLoginId = 0,
|
||||
studentName = name,
|
||||
schoolSymbol = "",
|
||||
schoolShortName = "",
|
||||
schoolName = "",
|
||||
className = "",
|
||||
classId = 0,
|
||||
|
@ -32,7 +32,7 @@ class GradeAverageProviderTest {
|
||||
|
||||
private lateinit var gradeAverageProvider: GradeAverageProvider
|
||||
|
||||
private val student = Student("", "", "", "SCRAPPER", "", "", false, "", "", "", 101, 0, "", "", "", "", 1, true, LocalDateTime.now())
|
||||
private val student = Student("", "", "", "SCRAPPER", "", "", false, "", "", "", 101, 0, "", "", "", "", "", 1, true, LocalDateTime.now())
|
||||
|
||||
private val semesters = mutableListOf(
|
||||
createSemesterEntity(10, 21, of(2019, 1, 31), of(2019, 6, 23)),
|
||||
|
@ -86,7 +86,7 @@ class LoginFormPresenterTest {
|
||||
|
||||
@Test
|
||||
fun loginTest() {
|
||||
val studentTest = Student(email = "test@", password = "123", scrapperBaseUrl = "https://fakelog.cf", loginType = "AUTO", studentName = "", schoolSymbol = "", schoolName = "", studentId = 0, classId = 1, isCurrent = false, symbol = "", registrationDate = now(), className = "", mobileBaseUrl = "", privateKey = "", certificateKey = "", loginMode = "", userLoginId = 0, isParent = false)
|
||||
val studentTest = Student(email = "test@", password = "123", scrapperBaseUrl = "https://fakelog.cf", loginType = "AUTO", studentName = "", schoolSymbol = "", schoolName = "", studentId = 0, classId = 1, isCurrent = false, symbol = "", registrationDate = now(), className = "", mobileBaseUrl = "", privateKey = "", certificateKey = "", loginMode = "", userLoginId = 0, schoolShortName = "", isParent = false)
|
||||
doReturn(Single.just(listOf(studentTest))).`when`(repository).getStudentsScrapper(anyString(), anyString(), anyString(), anyString())
|
||||
|
||||
`when`(loginFormView.formUsernameValue).thenReturn("@")
|
||||
|
@ -32,7 +32,7 @@ class LoginStudentSelectPresenterTest {
|
||||
|
||||
private lateinit var presenter: LoginStudentSelectPresenter
|
||||
|
||||
private val testStudent by lazy { Student(email = "test", password = "test123", scrapperBaseUrl = "https://fakelog.cf", loginType = "AUTO", symbol = "", isCurrent = false, studentId = 0, schoolName = "", schoolSymbol = "", classId = 1, studentName = "", registrationDate = now(), className = "", loginMode = "", certificateKey = "", privateKey = "", mobileBaseUrl = "", userLoginId = 1, isParent = false) }
|
||||
private val testStudent by lazy { Student(email = "test", password = "test123", scrapperBaseUrl = "https://fakelog.cf", loginType = "AUTO", symbol = "", isCurrent = false, studentId = 0, schoolName = "", schoolSymbol = "", classId = 1, studentName = "", registrationDate = now(), className = "", loginMode = "", certificateKey = "", privateKey = "", mobileBaseUrl = "", schoolShortName = "", userLoginId = 1, isParent = false) }
|
||||
|
||||
private val testException by lazy { RuntimeException("Problem") }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user