forked from github/wulkanowy-mirror
Add WulkanowySdkFactory (#2479)
This commit is contained in:
parent
afb5ae741c
commit
6a8f6f9496
@ -18,17 +18,13 @@ import io.github.wulkanowy.data.api.SchoolsService
|
|||||||
import io.github.wulkanowy.data.db.AppDatabase
|
import io.github.wulkanowy.data.db.AppDatabase
|
||||||
import io.github.wulkanowy.data.db.SharedPrefProvider
|
import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AppInfo
|
import io.github.wulkanowy.utils.AppInfo
|
||||||
import io.github.wulkanowy.utils.RemoteConfigHelper
|
|
||||||
import io.github.wulkanowy.utils.WebkitCookieManagerProxy
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.create
|
import retrofit2.create
|
||||||
import timber.log.Timber
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@ -36,23 +32,6 @@ import javax.inject.Singleton
|
|||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
internal class DataModule {
|
internal class DataModule {
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideSdk(
|
|
||||||
chuckerInterceptor: ChuckerInterceptor,
|
|
||||||
remoteConfig: RemoteConfigHelper,
|
|
||||||
webkitCookieManagerProxy: WebkitCookieManagerProxy,
|
|
||||||
) = Sdk().apply {
|
|
||||||
androidVersion = android.os.Build.VERSION.RELEASE
|
|
||||||
buildTag = android.os.Build.MODEL
|
|
||||||
userAgentTemplate = remoteConfig.userAgentTemplate
|
|
||||||
setSimpleHttpLogger { Timber.d(it) }
|
|
||||||
setAdditionalCookieManager(webkitCookieManagerProxy)
|
|
||||||
|
|
||||||
// for debug only
|
|
||||||
addInterceptor(chuckerInterceptor, network = true)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
fun provideChuckerCollector(
|
fun provideChuckerCollector(
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package io.github.wulkanowy.data
|
||||||
|
|
||||||
|
import com.chuckerteam.chucker.api.ChuckerInterceptor
|
||||||
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
|
import io.github.wulkanowy.sdk.Sdk
|
||||||
|
import io.github.wulkanowy.utils.RemoteConfigHelper
|
||||||
|
import io.github.wulkanowy.utils.WebkitCookieManagerProxy
|
||||||
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class WulkanowySdkFactory @Inject constructor(
|
||||||
|
private val chuckerInterceptor: ChuckerInterceptor,
|
||||||
|
private val remoteConfig: RemoteConfigHelper,
|
||||||
|
private val webkitCookieManagerProxy: WebkitCookieManagerProxy
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val sdk = Sdk().apply {
|
||||||
|
androidVersion = android.os.Build.VERSION.RELEASE
|
||||||
|
buildTag = android.os.Build.MODEL
|
||||||
|
userAgentTemplate = remoteConfig.userAgentTemplate
|
||||||
|
setSimpleHttpLogger { Timber.d(it) }
|
||||||
|
setAdditionalCookieManager(webkitCookieManagerProxy)
|
||||||
|
|
||||||
|
// for debug only
|
||||||
|
addInterceptor(chuckerInterceptor, network = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun create() = sdk
|
||||||
|
|
||||||
|
fun create(student: Student, semester: Semester? = null): Sdk {
|
||||||
|
return create().apply {
|
||||||
|
email = student.email
|
||||||
|
password = student.password
|
||||||
|
symbol = student.symbol
|
||||||
|
schoolSymbol = student.schoolSymbol
|
||||||
|
studentId = student.studentId
|
||||||
|
classId = student.classId
|
||||||
|
emptyCookieJarInterceptor = true
|
||||||
|
|
||||||
|
if (Sdk.Mode.valueOf(student.loginMode) == Sdk.Mode.HEBE) {
|
||||||
|
mobileBaseUrl = student.mobileBaseUrl
|
||||||
|
} else {
|
||||||
|
scrapperBaseUrl = student.scrapperBaseUrl
|
||||||
|
domainSuffix = student.scrapperDomainSuffix
|
||||||
|
loginType = Sdk.ScrapperLoginType.valueOf(student.loginType)
|
||||||
|
}
|
||||||
|
|
||||||
|
mode = Sdk.Mode.valueOf(student.loginMode)
|
||||||
|
mobileBaseUrl = student.mobileBaseUrl
|
||||||
|
keyId = student.certificateKey
|
||||||
|
privatePem = student.privateKey
|
||||||
|
|
||||||
|
if (semester != null) {
|
||||||
|
diaryId = semester.diaryId
|
||||||
|
kindergartenDiaryId = semester.kindergartenDiaryId
|
||||||
|
schoolYear = semester.schoolYear
|
||||||
|
unitId = semester.unitId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.AttendanceDao
|
import io.github.wulkanowy.data.db.dao.AttendanceDao
|
||||||
import io.github.wulkanowy.data.db.dao.TimetableDao
|
import io.github.wulkanowy.data.db.dao.TimetableDao
|
||||||
import io.github.wulkanowy.data.db.entities.Attendance
|
import io.github.wulkanowy.data.db.entities.Attendance
|
||||||
@ -7,14 +8,11 @@ import io.github.wulkanowy.data.db.entities.Semester
|
|||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.sdk.pojo.Absent
|
import io.github.wulkanowy.sdk.pojo.Absent
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.monday
|
import io.github.wulkanowy.utils.monday
|
||||||
import io.github.wulkanowy.utils.sunday
|
import io.github.wulkanowy.utils.sunday
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@ -28,7 +26,7 @@ import javax.inject.Singleton
|
|||||||
class AttendanceRepository @Inject constructor(
|
class AttendanceRepository @Inject constructor(
|
||||||
private val attendanceDb: AttendanceDao,
|
private val attendanceDb: AttendanceDao,
|
||||||
private val timetableDb: TimetableDao,
|
private val timetableDb: TimetableDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -59,8 +57,7 @@ class AttendanceRepository @Inject constructor(
|
|||||||
val lessons = timetableDb.load(
|
val lessons = timetableDb.load(
|
||||||
semester.diaryId, semester.studentId, start.monday, end.sunday
|
semester.diaryId, semester.studentId, start.monday, end.sunday
|
||||||
)
|
)
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getAttendance(start.monday, end.sunday)
|
.getAttendance(start.monday, end.sunday)
|
||||||
.mapToEntities(semester, lessons)
|
.mapToEntities(semester, lessons)
|
||||||
},
|
},
|
||||||
@ -90,8 +87,10 @@ class AttendanceRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun excuseForAbsence(
|
suspend fun excuseForAbsence(
|
||||||
student: Student, semester: Semester,
|
student: Student,
|
||||||
absenceList: List<Attendance>, reason: String? = null
|
semester: Semester,
|
||||||
|
absenceList: List<Attendance>,
|
||||||
|
reason: String? = null
|
||||||
) {
|
) {
|
||||||
val items = absenceList.map { attendance ->
|
val items = absenceList.map { attendance ->
|
||||||
Absent(
|
Absent(
|
||||||
@ -99,8 +98,7 @@ class AttendanceRepository @Inject constructor(
|
|||||||
timeId = attendance.timeId
|
timeId = attendance.timeId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.excuseForAbsence(items, reason)
|
.excuseForAbsence(items, reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import io.github.wulkanowy.data.*
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.AppDatabase
|
import io.github.wulkanowy.data.db.AppDatabase
|
||||||
import io.github.wulkanowy.data.db.dao.AttendanceSummaryDao
|
import io.github.wulkanowy.data.db.dao.AttendanceSummaryDao
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -20,9 +18,9 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class AttendanceSummaryRepository @Inject constructor(
|
class AttendanceSummaryRepository @Inject constructor(
|
||||||
private val attendanceDb: AttendanceSummaryDao,
|
private val attendanceDb: AttendanceSummaryDao,
|
||||||
private val sdk: Sdk,
|
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
private val appDatabase: AppDatabase,
|
private val appDatabase: AppDatabase,
|
||||||
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val saveFetchResultMutex = Mutex()
|
private val saveFetchResultMutex = Mutex()
|
||||||
@ -43,8 +41,7 @@ class AttendanceSummaryRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { attendanceDb.loadAll(semester.diaryId, semester.studentId, subjectId) },
|
query = { attendanceDb.loadAll(semester.diaryId, semester.studentId, subjectId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getAttendanceSummary(subjectId)
|
.getAttendanceSummary(subjectId)
|
||||||
.mapToEntities(semester, subjectId)
|
.mapToEntities(semester, subjectId)
|
||||||
},
|
},
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.CompletedLessonsDao
|
import io.github.wulkanowy.data.db.dao.CompletedLessonsDao
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.monday
|
import io.github.wulkanowy.utils.monday
|
||||||
import io.github.wulkanowy.utils.sunday
|
import io.github.wulkanowy.utils.sunday
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
@ -21,7 +19,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class CompletedLessonsRepository @Inject constructor(
|
class CompletedLessonsRepository @Inject constructor(
|
||||||
private val completedLessonsDb: CompletedLessonsDao,
|
private val completedLessonsDb: CompletedLessonsDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -53,8 +51,7 @@ class CompletedLessonsRepository @Inject constructor(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getCompletedLessons(start.monday, end.sunday)
|
.getCompletedLessons(start.monday, end.sunday)
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.ConferenceDao
|
import io.github.wulkanowy.data.db.dao.ConferenceDao
|
||||||
import io.github.wulkanowy.data.db.entities.Conference
|
import io.github.wulkanowy.data.db.entities.Conference
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@ -21,7 +19,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class ConferenceRepository @Inject constructor(
|
class ConferenceRepository @Inject constructor(
|
||||||
private val conferenceDb: ConferenceDao,
|
private val conferenceDb: ConferenceDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -46,8 +44,7 @@ class ConferenceRepository @Inject constructor(
|
|||||||
conferenceDb.loadAll(semester.diaryId, student.studentId, startDate)
|
conferenceDb.loadAll(semester.diaryId, student.studentId, startDate)
|
||||||
},
|
},
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getConferences()
|
.getConferences()
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
.filter { it.date >= startDate }
|
.filter { it.date >= startDate }
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.ExamDao
|
import io.github.wulkanowy.data.db.dao.ExamDao
|
||||||
import io.github.wulkanowy.data.db.entities.Exam
|
import io.github.wulkanowy.data.db.entities.Exam
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.endExamsDay
|
import io.github.wulkanowy.utils.endExamsDay
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.startExamsDay
|
import io.github.wulkanowy.utils.startExamsDay
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@ -23,7 +21,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class ExamRepository @Inject constructor(
|
class ExamRepository @Inject constructor(
|
||||||
private val examDb: ExamDao,
|
private val examDb: ExamDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -56,8 +54,7 @@ class ExamRepository @Inject constructor(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getExams(start.startExamsDay, start.endExamsDay)
|
.getExams(start.startExamsDay, start.endExamsDay)
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.GradeDao
|
import io.github.wulkanowy.data.db.dao.GradeDao
|
||||||
import io.github.wulkanowy.data.db.dao.GradeDescriptiveDao
|
import io.github.wulkanowy.data.db.dao.GradeDescriptiveDao
|
||||||
import io.github.wulkanowy.data.db.dao.GradeSummaryDao
|
import io.github.wulkanowy.data.db.dao.GradeSummaryDao
|
||||||
@ -10,11 +11,8 @@ import io.github.wulkanowy.data.db.entities.Semester
|
|||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.toLocalDate
|
import io.github.wulkanowy.utils.toLocalDate
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@ -30,7 +28,7 @@ class GradeRepository @Inject constructor(
|
|||||||
private val gradeDb: GradeDao,
|
private val gradeDb: GradeDao,
|
||||||
private val gradeSummaryDb: GradeSummaryDao,
|
private val gradeSummaryDb: GradeSummaryDao,
|
||||||
private val gradeDescriptiveDb: GradeDescriptiveDao,
|
private val gradeDescriptiveDb: GradeDescriptiveDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -63,8 +61,7 @@ class GradeRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetch = {
|
fetch = {
|
||||||
val (details, summary, descriptive) = sdk.init(student)
|
val (details, summary, descriptive) = wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getGrades(semester.semesterId)
|
.getGrades(semester.semesterId)
|
||||||
|
|
||||||
Triple(
|
Triple(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.GradePartialStatisticsDao
|
import io.github.wulkanowy.data.db.dao.GradePartialStatisticsDao
|
||||||
import io.github.wulkanowy.data.db.dao.GradePointsStatisticsDao
|
import io.github.wulkanowy.data.db.dao.GradePointsStatisticsDao
|
||||||
import io.github.wulkanowy.data.db.dao.GradeSemesterStatisticsDao
|
import io.github.wulkanowy.data.db.dao.GradeSemesterStatisticsDao
|
||||||
@ -12,11 +13,8 @@ import io.github.wulkanowy.data.mappers.mapPointsToStatisticsItems
|
|||||||
import io.github.wulkanowy.data.mappers.mapSemesterToStatisticItems
|
import io.github.wulkanowy.data.mappers.mapSemesterToStatisticItems
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@ -28,7 +26,7 @@ class GradeStatisticsRepository @Inject constructor(
|
|||||||
private val gradePartialStatisticsDb: GradePartialStatisticsDao,
|
private val gradePartialStatisticsDb: GradePartialStatisticsDao,
|
||||||
private val gradePointsStatisticsDb: GradePointsStatisticsDao,
|
private val gradePointsStatisticsDb: GradePointsStatisticsDao,
|
||||||
private val gradeSemesterStatisticsDb: GradeSemesterStatisticsDao,
|
private val gradeSemesterStatisticsDb: GradeSemesterStatisticsDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -56,8 +54,7 @@ class GradeStatisticsRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { gradePartialStatisticsDb.loadAll(semester.semesterId, semester.studentId) },
|
query = { gradePartialStatisticsDb.loadAll(semester.semesterId, semester.studentId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getGradesPartialStatistics(semester.semesterId)
|
.getGradesPartialStatistics(semester.semesterId)
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
@ -104,8 +101,7 @@ class GradeStatisticsRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { gradeSemesterStatisticsDb.loadAll(semester.semesterId, semester.studentId) },
|
query = { gradeSemesterStatisticsDb.loadAll(semester.semesterId, semester.studentId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getGradesSemesterStatistics(semester.semesterId)
|
.getGradesSemesterStatistics(semester.semesterId)
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
@ -163,8 +159,7 @@ class GradeStatisticsRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { gradePointsStatisticsDb.loadAll(semester.semesterId, semester.studentId) },
|
query = { gradePointsStatisticsDb.loadAll(semester.semesterId, semester.studentId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getGradesPointsStatistics(semester.semesterId)
|
.getGradesPointsStatistics(semester.semesterId)
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.HomeworkDao
|
import io.github.wulkanowy.data.db.dao.HomeworkDao
|
||||||
import io.github.wulkanowy.data.db.entities.Homework
|
import io.github.wulkanowy.data.db.entities.Homework
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.monday
|
import io.github.wulkanowy.utils.monday
|
||||||
import io.github.wulkanowy.utils.sunday
|
import io.github.wulkanowy.utils.sunday
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
@ -22,7 +20,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class HomeworkRepository @Inject constructor(
|
class HomeworkRepository @Inject constructor(
|
||||||
private val homeworkDb: HomeworkDao,
|
private val homeworkDb: HomeworkDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -55,8 +53,7 @@ class HomeworkRepository @Inject constructor(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getHomework(start.monday, end.sunday)
|
.getHomework(start.monday, end.sunday)
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.LuckyNumberDao
|
import io.github.wulkanowy.data.db.dao.LuckyNumberDao
|
||||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntity
|
import io.github.wulkanowy.data.mappers.mapToEntity
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@ -18,7 +17,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class LuckyNumberRepository @Inject constructor(
|
class LuckyNumberRepository @Inject constructor(
|
||||||
private val luckyNumberDb: LuckyNumberDao,
|
private val luckyNumberDb: LuckyNumberDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val saveFetchResultMutex = Mutex()
|
private val saveFetchResultMutex = Mutex()
|
||||||
@ -33,7 +32,9 @@ class LuckyNumberRepository @Inject constructor(
|
|||||||
shouldFetch = { it == null || forceRefresh },
|
shouldFetch = { it == null || forceRefresh },
|
||||||
query = { luckyNumberDb.load(student.studentId, now()) },
|
query = { luckyNumberDb.load(student.studentId, now()) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student).getLuckyNumber(student.schoolShortName)?.mapToEntity(student)
|
wulkanowySdkFactory.create(student)
|
||||||
|
.getLuckyNumber(student.schoolShortName)
|
||||||
|
?.mapToEntity(student)
|
||||||
},
|
},
|
||||||
saveFetchResult = { oldLuckyNumber, newLuckyNumber ->
|
saveFetchResult = { oldLuckyNumber, newLuckyNumber ->
|
||||||
newLuckyNumber ?: return@networkBoundResource
|
newLuckyNumber ?: return@networkBoundResource
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import io.github.wulkanowy.R
|
import io.github.wulkanowy.R
|
||||||
import io.github.wulkanowy.data.Resource
|
import io.github.wulkanowy.data.Resource
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.SharedPrefProvider
|
import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||||
import io.github.wulkanowy.data.db.dao.MailboxDao
|
import io.github.wulkanowy.data.db.dao.MailboxDao
|
||||||
import io.github.wulkanowy.data.db.dao.MessageAttachmentDao
|
import io.github.wulkanowy.data.db.dao.MessageAttachmentDao
|
||||||
@ -29,11 +30,9 @@ import io.github.wulkanowy.data.pojos.MessageDraft
|
|||||||
import io.github.wulkanowy.data.toFirstResult
|
import io.github.wulkanowy.data.toFirstResult
|
||||||
import io.github.wulkanowy.data.waitForResult
|
import io.github.wulkanowy.data.waitForResult
|
||||||
import io.github.wulkanowy.domain.messages.GetMailboxByStudentUseCase
|
import io.github.wulkanowy.domain.messages.GetMailboxByStudentUseCase
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.sdk.pojo.Folder
|
import io.github.wulkanowy.sdk.pojo.Folder
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@ -48,7 +47,7 @@ class MessageRepository @Inject constructor(
|
|||||||
private val messagesDb: MessagesDao,
|
private val messagesDb: MessagesDao,
|
||||||
private val mutedMessageSendersDao: MutedMessageSendersDao,
|
private val mutedMessageSendersDao: MutedMessageSendersDao,
|
||||||
private val messageAttachmentDao: MessageAttachmentDao,
|
private val messageAttachmentDao: MessageAttachmentDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
private val sharedPrefProvider: SharedPrefProvider,
|
private val sharedPrefProvider: SharedPrefProvider,
|
||||||
@ -82,10 +81,16 @@ class MessageRepository @Inject constructor(
|
|||||||
} else messagesDb.loadMessagesWithMutedAuthor(mailbox.globalKey, folder.id)
|
} else messagesDb.loadMessagesWithMutedAuthor(mailbox.globalKey, folder.id)
|
||||||
},
|
},
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student).getMessages(
|
wulkanowySdkFactory.create(student)
|
||||||
folder = Folder.valueOf(folder.name),
|
.getMessages(
|
||||||
mailboxKey = mailbox?.globalKey,
|
folder = Folder.valueOf(folder.name),
|
||||||
).mapToEntities(student, mailbox, mailboxDao.loadAll(student.email))
|
mailboxKey = mailbox?.globalKey,
|
||||||
|
)
|
||||||
|
.mapToEntities(
|
||||||
|
student = student,
|
||||||
|
mailbox = mailbox,
|
||||||
|
allMailboxes = mailboxDao.loadAll(student.email)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
saveFetchResult = { oldWithAuthors, new ->
|
saveFetchResult = { oldWithAuthors, new ->
|
||||||
val old = oldWithAuthors.map { it.message }
|
val old = oldWithAuthors.map { it.message }
|
||||||
@ -115,10 +120,11 @@ class MessageRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { messagesDb.loadMessageWithAttachment(message.messageGlobalKey) },
|
query = { messagesDb.loadMessageWithAttachment(message.messageGlobalKey) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student).getMessageDetails(
|
wulkanowySdkFactory.create(student)
|
||||||
messageKey = it!!.message.messageGlobalKey,
|
.getMessageDetails(
|
||||||
markAsRead = message.unread && markAsRead,
|
messageKey = it!!.message.messageGlobalKey,
|
||||||
)
|
markAsRead = message.unread && markAsRead,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
saveFetchResult = { old, new ->
|
saveFetchResult = { old, new ->
|
||||||
checkNotNull(old) { "Fetched message no longer exist!" }
|
checkNotNull(old) { "Fetched message no longer exist!" }
|
||||||
@ -159,19 +165,19 @@ class MessageRepository @Inject constructor(
|
|||||||
recipients: List<Recipient>,
|
recipients: List<Recipient>,
|
||||||
mailbox: Mailbox,
|
mailbox: Mailbox,
|
||||||
) {
|
) {
|
||||||
sdk.init(student).sendMessage(
|
wulkanowySdkFactory.create(student)
|
||||||
subject = subject,
|
.sendMessage(
|
||||||
content = content,
|
subject = subject,
|
||||||
recipients = recipients.mapFromEntities(),
|
content = content,
|
||||||
mailboxId = mailbox.globalKey,
|
recipients = recipients.mapFromEntities(),
|
||||||
)
|
mailboxId = mailbox.globalKey,
|
||||||
|
)
|
||||||
refreshFolders(student, mailbox, listOf(SENT))
|
refreshFolders(student, mailbox, listOf(SENT))
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun restoreMessages(student: Student, mailbox: Mailbox?, messages: List<Message>) {
|
suspend fun restoreMessages(student: Student, mailbox: Mailbox?, messages: List<Message>) {
|
||||||
sdk.init(student).restoreMessages(
|
wulkanowySdkFactory.create(student)
|
||||||
messages = messages.map { it.messageGlobalKey },
|
.restoreMessages(messages = messages.map { it.messageGlobalKey })
|
||||||
)
|
|
||||||
|
|
||||||
refreshFolders(student, mailbox)
|
refreshFolders(student, mailbox)
|
||||||
}
|
}
|
||||||
@ -182,10 +188,11 @@ class MessageRepository @Inject constructor(
|
|||||||
|
|
||||||
suspend fun deleteMessages(student: Student, messages: List<Message>) {
|
suspend fun deleteMessages(student: Student, messages: List<Message>) {
|
||||||
val firstMessage = messages.first()
|
val firstMessage = messages.first()
|
||||||
sdk.init(student).deleteMessages(
|
wulkanowySdkFactory.create(student)
|
||||||
messages = messages.map { it.messageGlobalKey },
|
.deleteMessages(
|
||||||
removeForever = firstMessage.folderId == TRASHED.id,
|
messages = messages.map { it.messageGlobalKey },
|
||||||
)
|
removeForever = firstMessage.folderId == TRASHED.id,
|
||||||
|
)
|
||||||
|
|
||||||
if (firstMessage.folderId != TRASHED.id) {
|
if (firstMessage.folderId != TRASHED.id) {
|
||||||
val deletedMessages = messages.map {
|
val deletedMessages = messages.map {
|
||||||
@ -230,7 +237,9 @@ class MessageRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { mailboxDao.loadAll(student.email, student.symbol, student.schoolSymbol) },
|
query = { mailboxDao.loadAll(student.email, student.symbol, student.schoolSymbol) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student).getMailboxes().mapToEntities(student)
|
wulkanowySdkFactory.create(student)
|
||||||
|
.getMailboxes()
|
||||||
|
.mapToEntities(student)
|
||||||
},
|
},
|
||||||
saveFetchResult = { old, new ->
|
saveFetchResult = { old, new ->
|
||||||
mailboxDao.deleteAll(old uniqueSubtract new)
|
mailboxDao.deleteAll(old uniqueSubtract new)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.MobileDeviceDao
|
import io.github.wulkanowy.data.db.dao.MobileDeviceDao
|
||||||
import io.github.wulkanowy.data.db.entities.MobileDevice
|
import io.github.wulkanowy.data.db.entities.MobileDevice
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
@ -8,11 +9,8 @@ import io.github.wulkanowy.data.mappers.mapToEntities
|
|||||||
import io.github.wulkanowy.data.mappers.mapToMobileDeviceToken
|
import io.github.wulkanowy.data.mappers.mapToMobileDeviceToken
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.data.pojos.MobileDeviceToken
|
import io.github.wulkanowy.data.pojos.MobileDeviceToken
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -21,7 +19,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class MobileDeviceRepository @Inject constructor(
|
class MobileDeviceRepository @Inject constructor(
|
||||||
private val mobileDb: MobileDeviceDao,
|
private val mobileDb: MobileDeviceDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -42,8 +40,7 @@ class MobileDeviceRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { mobileDb.loadAll(student.userLoginId) },
|
query = { mobileDb.loadAll(student.userLoginId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getRegisteredDevices()
|
.getRegisteredDevices()
|
||||||
.mapToEntities(student)
|
.mapToEntities(student)
|
||||||
},
|
},
|
||||||
@ -57,16 +54,14 @@ class MobileDeviceRepository @Inject constructor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
suspend fun unregisterDevice(student: Student, semester: Semester, device: MobileDevice) {
|
suspend fun unregisterDevice(student: Student, semester: Semester, device: MobileDevice) {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.unregisterDevice(device.deviceId)
|
.unregisterDevice(device.deviceId)
|
||||||
|
|
||||||
mobileDb.deleteAll(listOf(device))
|
mobileDb.deleteAll(listOf(device))
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getToken(student: Student, semester: Semester): MobileDeviceToken {
|
suspend fun getToken(student: Student, semester: Semester): MobileDeviceToken {
|
||||||
return sdk.init(student)
|
return wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getToken()
|
.getToken()
|
||||||
.mapToMobileDeviceToken()
|
.mapToMobileDeviceToken()
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.NoteDao
|
import io.github.wulkanowy.data.db.dao.NoteDao
|
||||||
import io.github.wulkanowy.data.db.entities.Note
|
import io.github.wulkanowy.data.db.entities.Note
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.toLocalDate
|
import io.github.wulkanowy.utils.toLocalDate
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@ -21,7 +19,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class NoteRepository @Inject constructor(
|
class NoteRepository @Inject constructor(
|
||||||
private val noteDb: NoteDao,
|
private val noteDb: NoteDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -45,8 +43,7 @@ class NoteRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { noteDb.loadAll(student.studentId) },
|
query = { noteDb.loadAll(student.studentId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getNotes()
|
.getNotes()
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.RecipientDao
|
import io.github.wulkanowy.data.db.dao.RecipientDao
|
||||||
import io.github.wulkanowy.data.db.entities.Mailbox
|
import io.github.wulkanowy.data.db.entities.Mailbox
|
||||||
import io.github.wulkanowy.data.db.entities.MailboxType
|
import io.github.wulkanowy.data.db.entities.MailboxType
|
||||||
@ -7,10 +8,8 @@ import io.github.wulkanowy.data.db.entities.Message
|
|||||||
import io.github.wulkanowy.data.db.entities.Recipient
|
import io.github.wulkanowy.data.db.entities.Recipient
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@ -18,14 +17,15 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class RecipientRepository @Inject constructor(
|
class RecipientRepository @Inject constructor(
|
||||||
private val recipientDb: RecipientDao,
|
private val recipientDb: RecipientDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val cacheKey = "recipient"
|
private val cacheKey = "recipient"
|
||||||
|
|
||||||
suspend fun refreshRecipients(student: Student, mailbox: Mailbox, type: MailboxType) {
|
suspend fun refreshRecipients(student: Student, mailbox: Mailbox, type: MailboxType) {
|
||||||
val new = sdk.init(student).getRecipients(mailbox.globalKey)
|
val new = wulkanowySdkFactory.create(student)
|
||||||
|
.getRecipients(mailbox.globalKey)
|
||||||
.mapToEntities(mailbox.globalKey)
|
.mapToEntities(mailbox.globalKey)
|
||||||
val old = recipientDb.loadAll(type, mailbox.globalKey)
|
val old = recipientDb.loadAll(type, mailbox.globalKey)
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ class RecipientRepository @Inject constructor(
|
|||||||
): List<Recipient> {
|
): List<Recipient> {
|
||||||
mailbox ?: return emptyList()
|
mailbox ?: return emptyList()
|
||||||
|
|
||||||
return sdk.init(student)
|
return wulkanowySdkFactory.create(student)
|
||||||
.getMessageReplayDetails(message.messageGlobalKey)
|
.getMessageReplayDetails(message.messageGlobalKey)
|
||||||
.sender
|
.sender
|
||||||
.let(::listOf)
|
.let(::listOf)
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class RecoverRepository @Inject constructor(private val sdk: Sdk) {
|
class RecoverRepository @Inject constructor(
|
||||||
|
private val wulkanowySdkFactory: WulkanowySdkFactory
|
||||||
|
) {
|
||||||
|
|
||||||
suspend fun getReCaptchaSiteKey(host: String, symbol: String): Pair<String, String> {
|
suspend fun getReCaptchaSiteKey(host: String, symbol: String): Pair<String, String> =
|
||||||
return sdk.getPasswordResetCaptchaCode(host, symbol)
|
wulkanowySdkFactory.create()
|
||||||
}
|
.getPasswordResetCaptchaCode(host, symbol)
|
||||||
|
|
||||||
suspend fun sendRecoverRequest(
|
suspend fun sendRecoverRequest(
|
||||||
url: String, symbol: String, email: String, reCaptchaResponse: String
|
url: String,
|
||||||
): String = sdk.sendPasswordResetRequest(url, symbol, email, reCaptchaResponse)
|
symbol: String,
|
||||||
|
email: String,
|
||||||
|
reCaptchaResponse: String
|
||||||
|
): String = wulkanowySdkFactory.create()
|
||||||
|
.sendPasswordResetRequest(url, symbol, email, reCaptchaResponse)
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.SchoolAnnouncementDao
|
import io.github.wulkanowy.data.db.dao.SchoolAnnouncementDao
|
||||||
import io.github.wulkanowy.data.db.entities.SchoolAnnouncement
|
import io.github.wulkanowy.data.db.entities.SchoolAnnouncement
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@ -18,7 +17,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class SchoolAnnouncementRepository @Inject constructor(
|
class SchoolAnnouncementRepository @Inject constructor(
|
||||||
private val schoolAnnouncementDb: SchoolAnnouncementDao,
|
private val schoolAnnouncementDb: SchoolAnnouncementDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ class SchoolAnnouncementRepository @Inject constructor(
|
|||||||
schoolAnnouncementDb.loadAll(student.userLoginId)
|
schoolAnnouncementDb.loadAll(student.userLoginId)
|
||||||
},
|
},
|
||||||
fetch = {
|
fetch = {
|
||||||
val sdk = sdk.init(student)
|
val sdk = wulkanowySdkFactory.create(student)
|
||||||
val lastAnnouncements = sdk.getLastAnnouncements().mapToEntities(student)
|
val lastAnnouncements = sdk.getLastAnnouncements().mapToEntities(student)
|
||||||
val directorInformation = sdk.getDirectorInformation().mapToEntities(student)
|
val directorInformation = sdk.getDirectorInformation().mapToEntities(student)
|
||||||
lastAnnouncements + directorInformation
|
lastAnnouncements + directorInformation
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.SchoolDao
|
import io.github.wulkanowy.data.db.dao.SchoolDao
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntity
|
import io.github.wulkanowy.data.mappers.mapToEntity
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@ -17,7 +15,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class SchoolRepository @Inject constructor(
|
class SchoolRepository @Inject constructor(
|
||||||
private val schoolDb: SchoolDao,
|
private val schoolDb: SchoolDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -40,8 +38,7 @@ class SchoolRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { schoolDb.load(semester.studentId, semester.classId) },
|
query = { schoolDb.load(semester.studentId, semester.classId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getSchool()
|
.getSchool()
|
||||||
.mapToEntity(semester)
|
.mapToEntity(semester)
|
||||||
},
|
},
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.api.SchoolsService
|
import io.github.wulkanowy.data.api.SchoolsService
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||||
import io.github.wulkanowy.data.pojos.IntegrityRequest
|
import io.github.wulkanowy.data.pojos.IntegrityRequest
|
||||||
import io.github.wulkanowy.data.pojos.LoginEvent
|
import io.github.wulkanowy.data.pojos.LoginEvent
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.ui.modules.login.LoginData
|
import io.github.wulkanowy.ui.modules.login.LoginData
|
||||||
import io.github.wulkanowy.utils.IntegrityHelper
|
import io.github.wulkanowy.utils.IntegrityHelper
|
||||||
import io.github.wulkanowy.utils.getCurrentOrLast
|
import io.github.wulkanowy.utils.getCurrentOrLast
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import kotlinx.coroutines.withTimeout
|
import kotlinx.coroutines.withTimeout
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
@ -23,7 +21,7 @@ import kotlin.time.Duration.Companion.seconds
|
|||||||
class SchoolsRepository @Inject constructor(
|
class SchoolsRepository @Inject constructor(
|
||||||
private val integrityHelper: IntegrityHelper,
|
private val integrityHelper: IntegrityHelper,
|
||||||
private val schoolsService: SchoolsService,
|
private val schoolsService: SchoolsService,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun logSchoolLogin(loginData: LoginData, students: List<StudentWithSemesters>) {
|
suspend fun logSchoolLogin(loginData: LoginData, students: List<StudentWithSemesters>) {
|
||||||
@ -40,10 +38,9 @@ class SchoolsRepository @Inject constructor(
|
|||||||
private suspend fun logLogin(loginData: LoginData, student: Student, semester: Semester) {
|
private suspend fun logLogin(loginData: LoginData, student: Student, semester: Semester) {
|
||||||
val requestId = UUID.randomUUID().toString()
|
val requestId = UUID.randomUUID().toString()
|
||||||
val token = integrityHelper.getIntegrityToken(requestId) ?: return
|
val token = integrityHelper.getIntegrityToken(requestId) ?: return
|
||||||
|
val updatedStudent = student.copy(password = loginData.password)
|
||||||
|
|
||||||
val schoolInfo = sdk
|
val schoolInfo = wulkanowySdkFactory.create(updatedStudent, semester)
|
||||||
.init(student.copy(password = loginData.password))
|
|
||||||
.switchSemester(semester)
|
|
||||||
.getSchool()
|
.getSchool()
|
||||||
|
|
||||||
schoolsService.logLoginEvent(
|
schoolsService.logLoginEvent(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.SemesterDao
|
import io.github.wulkanowy.data.db.dao.SemesterDao
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
@ -7,7 +8,6 @@ import io.github.wulkanowy.data.mappers.mapToEntities
|
|||||||
import io.github.wulkanowy.sdk.Sdk
|
import io.github.wulkanowy.sdk.Sdk
|
||||||
import io.github.wulkanowy.utils.DispatchersProvider
|
import io.github.wulkanowy.utils.DispatchersProvider
|
||||||
import io.github.wulkanowy.utils.getCurrentOrLast
|
import io.github.wulkanowy.utils.getCurrentOrLast
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.isCurrent
|
import io.github.wulkanowy.utils.isCurrent
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -18,7 +18,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class SemesterRepository @Inject constructor(
|
class SemesterRepository @Inject constructor(
|
||||||
private val semesterDb: SemesterDao,
|
private val semesterDb: SemesterDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val dispatchers: DispatchersProvider,
|
private val dispatchers: DispatchersProvider,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -60,7 +60,10 @@ class SemesterRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun refreshSemesters(student: Student) {
|
private suspend fun refreshSemesters(student: Student) {
|
||||||
val new = sdk.init(student).getSemesters().mapToEntities(student.studentId)
|
val new = wulkanowySdkFactory.create(student)
|
||||||
|
.getSemesters()
|
||||||
|
.mapToEntities(student.studentId)
|
||||||
|
|
||||||
if (new.isEmpty()) return Timber.i("Empty semester list!")
|
if (new.isEmpty()) return Timber.i("Empty semester list!")
|
||||||
|
|
||||||
val old = semesterDb.loadAll(student.studentId, student.classId)
|
val old = semesterDb.loadAll(student.studentId, student.classId)
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.StudentInfoDao
|
import io.github.wulkanowy.data.db.dao.StudentInfoDao
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntity
|
import io.github.wulkanowy.data.mappers.mapToEntity
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@ -15,7 +13,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class StudentInfoRepository @Inject constructor(
|
class StudentInfoRepository @Inject constructor(
|
||||||
private val studentInfoDao: StudentInfoDao,
|
private val studentInfoDao: StudentInfoDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val saveFetchResultMutex = Mutex()
|
private val saveFetchResultMutex = Mutex()
|
||||||
@ -30,9 +28,9 @@ class StudentInfoRepository @Inject constructor(
|
|||||||
shouldFetch = { it == null || forceRefresh },
|
shouldFetch = { it == null || forceRefresh },
|
||||||
query = { studentInfoDao.loadStudentInfo(student.studentId) },
|
query = { studentInfoDao.loadStudentInfo(student.studentId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
.getStudentInfo()
|
||||||
.getStudentInfo().mapToEntity(semester)
|
.mapToEntity(semester)
|
||||||
},
|
},
|
||||||
saveFetchResult = { old, new ->
|
saveFetchResult = { old, new ->
|
||||||
if (old != null && new != old) {
|
if (old != null && new != old) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.AppDatabase
|
import io.github.wulkanowy.data.db.AppDatabase
|
||||||
import io.github.wulkanowy.data.db.dao.SemesterDao
|
import io.github.wulkanowy.data.db.dao.SemesterDao
|
||||||
import io.github.wulkanowy.data.db.dao.StudentDao
|
import io.github.wulkanowy.data.db.dao.StudentDao
|
||||||
@ -14,9 +15,7 @@ import io.github.wulkanowy.data.mappers.mapToPojo
|
|||||||
import io.github.wulkanowy.data.pojos.RegisterUser
|
import io.github.wulkanowy.data.pojos.RegisterUser
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
import io.github.wulkanowy.sdk.Sdk
|
||||||
import io.github.wulkanowy.utils.DispatchersProvider
|
import io.github.wulkanowy.utils.DispatchersProvider
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.security.Scrambler
|
import io.github.wulkanowy.utils.security.Scrambler
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@ -26,7 +25,7 @@ class StudentRepository @Inject constructor(
|
|||||||
private val dispatchers: DispatchersProvider,
|
private val dispatchers: DispatchersProvider,
|
||||||
private val studentDb: StudentDao,
|
private val studentDb: StudentDao,
|
||||||
private val semesterDb: SemesterDao,
|
private val semesterDb: SemesterDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val appDatabase: AppDatabase,
|
private val appDatabase: AppDatabase,
|
||||||
private val scrambler: Scrambler,
|
private val scrambler: Scrambler,
|
||||||
) {
|
) {
|
||||||
@ -37,7 +36,7 @@ class StudentRepository @Inject constructor(
|
|||||||
pin: String,
|
pin: String,
|
||||||
symbol: String,
|
symbol: String,
|
||||||
token: String
|
token: String
|
||||||
): RegisterUser = sdk
|
): RegisterUser = wulkanowySdkFactory.create()
|
||||||
.getStudentsFromHebe(token, pin, symbol, "")
|
.getStudentsFromHebe(token, pin, symbol, "")
|
||||||
.mapToPojo(null)
|
.mapToPojo(null)
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ class StudentRepository @Inject constructor(
|
|||||||
scrapperBaseUrl: String,
|
scrapperBaseUrl: String,
|
||||||
domainSuffix: String,
|
domainSuffix: String,
|
||||||
symbol: String
|
symbol: String
|
||||||
): RegisterUser = sdk
|
): RegisterUser = wulkanowySdkFactory.create()
|
||||||
.getUserSubjectsFromScrapper(email, password, scrapperBaseUrl, domainSuffix, symbol)
|
.getUserSubjectsFromScrapper(email, password, scrapperBaseUrl, domainSuffix, symbol)
|
||||||
.mapToPojo(password)
|
.mapToPojo(password)
|
||||||
|
|
||||||
@ -56,7 +55,7 @@ class StudentRepository @Inject constructor(
|
|||||||
password: String,
|
password: String,
|
||||||
scrapperBaseUrl: String,
|
scrapperBaseUrl: String,
|
||||||
symbol: String
|
symbol: String
|
||||||
): RegisterUser = sdk
|
): RegisterUser = wulkanowySdkFactory.create()
|
||||||
.getStudentsHybrid(email, password, scrapperBaseUrl, "", symbol)
|
.getStudentsHybrid(email, password, scrapperBaseUrl, "", symbol)
|
||||||
.mapToPojo(password)
|
.mapToPojo(password)
|
||||||
|
|
||||||
@ -149,13 +148,11 @@ class StudentRepository @Inject constructor(
|
|||||||
.distinctBy { it.student.studentName }.size == 1
|
.distinctBy { it.student.studentName }.size == 1
|
||||||
|
|
||||||
suspend fun authorizePermission(student: Student, semester: Semester, pesel: String) =
|
suspend fun authorizePermission(student: Student, semester: Semester, pesel: String) =
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.authorizePermission(pesel)
|
.authorizePermission(pesel)
|
||||||
|
|
||||||
suspend fun refreshStudentName(student: Student, semester: Semester) {
|
suspend fun refreshStudentName(student: Student, semester: Semester) {
|
||||||
val newCurrentApiStudent = sdk.init(student)
|
val newCurrentApiStudent = wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getCurrentStudent() ?: return
|
.getCurrentStudent() ?: return
|
||||||
|
|
||||||
val studentName = StudentName(
|
val studentName = StudentName(
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.SubjectDao
|
import io.github.wulkanowy.data.db.dao.SubjectDao
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -18,7 +16,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class SubjectRepository @Inject constructor(
|
class SubjectRepository @Inject constructor(
|
||||||
private val subjectDao: SubjectDao,
|
private val subjectDao: SubjectDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -39,8 +37,7 @@ class SubjectRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { subjectDao.loadAll(semester.diaryId, semester.studentId) },
|
query = { subjectDao.loadAll(semester.diaryId, semester.studentId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getSubjects()
|
.getSubjects()
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.TeacherDao
|
import io.github.wulkanowy.data.db.dao.TeacherDao
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -18,7 +16,7 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class TeacherRepository @Inject constructor(
|
class TeacherRepository @Inject constructor(
|
||||||
private val teacherDb: TeacherDao,
|
private val teacherDb: TeacherDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -39,8 +37,7 @@ class TeacherRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { teacherDb.loadAll(semester.studentId, semester.classId) },
|
query = { teacherDb.loadAll(semester.studentId, semester.classId) },
|
||||||
fetch = {
|
fetch = {
|
||||||
sdk.init(student)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getTeachers()
|
.getTeachers()
|
||||||
.mapToEntities(semester)
|
.mapToEntities(semester)
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.data.db.dao.TimetableAdditionalDao
|
import io.github.wulkanowy.data.db.dao.TimetableAdditionalDao
|
||||||
import io.github.wulkanowy.data.db.dao.TimetableDao
|
import io.github.wulkanowy.data.db.dao.TimetableDao
|
||||||
import io.github.wulkanowy.data.db.dao.TimetableHeaderDao
|
import io.github.wulkanowy.data.db.dao.TimetableHeaderDao
|
||||||
@ -11,14 +12,11 @@ import io.github.wulkanowy.data.db.entities.TimetableHeader
|
|||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.data.pojos.TimetableFull
|
import io.github.wulkanowy.data.pojos.TimetableFull
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.services.alarm.TimetableNotificationSchedulerHelper
|
import io.github.wulkanowy.services.alarm.TimetableNotificationSchedulerHelper
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
|
||||||
import io.github.wulkanowy.utils.monday
|
import io.github.wulkanowy.utils.monday
|
||||||
import io.github.wulkanowy.utils.sunday
|
import io.github.wulkanowy.utils.sunday
|
||||||
import io.github.wulkanowy.utils.switchSemester
|
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@ -33,7 +31,7 @@ class TimetableRepository @Inject constructor(
|
|||||||
private val timetableDb: TimetableDao,
|
private val timetableDb: TimetableDao,
|
||||||
private val timetableAdditionalDb: TimetableAdditionalDao,
|
private val timetableAdditionalDb: TimetableAdditionalDao,
|
||||||
private val timetableHeaderDb: TimetableHeaderDao,
|
private val timetableHeaderDb: TimetableHeaderDao,
|
||||||
private val sdk: Sdk,
|
private val wulkanowySdkFactory: WulkanowySdkFactory,
|
||||||
private val schedulerHelper: TimetableNotificationSchedulerHelper,
|
private val schedulerHelper: TimetableNotificationSchedulerHelper,
|
||||||
private val refreshHelper: AutoRefreshHelper,
|
private val refreshHelper: AutoRefreshHelper,
|
||||||
) {
|
) {
|
||||||
@ -74,8 +72,7 @@ class TimetableRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
query = { getFullTimetableFromDatabase(student, semester, start, end) },
|
query = { getFullTimetableFromDatabase(student, semester, start, end) },
|
||||||
fetch = {
|
fetch = {
|
||||||
val timetableFull = sdk.init(student)
|
val timetableFull = wulkanowySdkFactory.create(student, semester)
|
||||||
.switchSemester(semester)
|
|
||||||
.getTimetable(start.monday, end.sunday)
|
.getTimetable(start.monday, end.sunday)
|
||||||
|
|
||||||
timetableFull.mapToEntities(semester)
|
timetableFull.mapToEntities(semester)
|
||||||
|
@ -10,8 +10,8 @@ import android.webkit.WebViewClient
|
|||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import io.github.wulkanowy.R
|
import io.github.wulkanowy.R
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
import io.github.wulkanowy.databinding.DialogCaptchaBinding
|
import io.github.wulkanowy.databinding.DialogCaptchaBinding
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import io.github.wulkanowy.ui.base.BaseDialogFragment
|
import io.github.wulkanowy.ui.base.BaseDialogFragment
|
||||||
import io.github.wulkanowy.utils.WebkitCookieManagerProxy
|
import io.github.wulkanowy.utils.WebkitCookieManagerProxy
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -21,7 +21,7 @@ import javax.inject.Inject
|
|||||||
class CaptchaDialog : BaseDialogFragment<DialogCaptchaBinding>() {
|
class CaptchaDialog : BaseDialogFragment<DialogCaptchaBinding>() {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var sdk: Sdk
|
lateinit var wulkanowySdkFactory: WulkanowySdkFactory
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var webkitCookieManagerProxy: WebkitCookieManagerProxy
|
lateinit var webkitCookieManagerProxy: WebkitCookieManagerProxy
|
||||||
@ -59,7 +59,7 @@ class CaptchaDialog : BaseDialogFragment<DialogCaptchaBinding>() {
|
|||||||
webView = this
|
webView = this
|
||||||
with(settings) {
|
with(settings) {
|
||||||
javaScriptEnabled = true
|
javaScriptEnabled = true
|
||||||
userAgentString = sdk.userAgent
|
userAgentString = wulkanowySdkFactory.create().userAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
webViewClient = object : WebViewClient() {
|
webViewClient = object : WebViewClient() {
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
package io.github.wulkanowy.utils
|
|
||||||
|
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
fun Sdk.init(student: Student): Sdk {
|
|
||||||
email = student.email
|
|
||||||
password = student.password
|
|
||||||
symbol = student.symbol
|
|
||||||
schoolSymbol = student.schoolSymbol
|
|
||||||
studentId = student.studentId
|
|
||||||
classId = student.classId
|
|
||||||
emptyCookieJarInterceptor = true
|
|
||||||
|
|
||||||
if (Sdk.Mode.valueOf(student.loginMode) == Sdk.Mode.HEBE) {
|
|
||||||
mobileBaseUrl = student.mobileBaseUrl
|
|
||||||
} else {
|
|
||||||
scrapperBaseUrl = student.scrapperBaseUrl
|
|
||||||
domainSuffix = student.scrapperDomainSuffix
|
|
||||||
loginType = Sdk.ScrapperLoginType.valueOf(student.loginType)
|
|
||||||
}
|
|
||||||
|
|
||||||
mode = Sdk.Mode.valueOf(student.loginMode)
|
|
||||||
mobileBaseUrl = student.mobileBaseUrl
|
|
||||||
keyId = student.certificateKey
|
|
||||||
privatePem = student.privateKey
|
|
||||||
|
|
||||||
Timber.d("Sdk in ${student.loginMode} mode reinitialized")
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Sdk.switchSemester(semester: Semester): Sdk {
|
|
||||||
return switchDiary(
|
|
||||||
diaryId = semester.diaryId,
|
|
||||||
kindergartenDiaryId = semester.kindergartenDiaryId,
|
|
||||||
schoolYear = semester.schoolYear,
|
|
||||||
unitId = semester.unitId,
|
|
||||||
)
|
|
||||||
}
|
|
@ -0,0 +1,12 @@
|
|||||||
|
package io.github.wulkanowy
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.WulkanowySdkFactory
|
||||||
|
import io.github.wulkanowy.sdk.Sdk
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
|
|
||||||
|
fun createWulkanowySdkFactoryMock(sdk: Sdk) = mockk<WulkanowySdkFactory>()
|
||||||
|
.apply {
|
||||||
|
every { create() } returns sdk
|
||||||
|
every { create(any(), any()) } answers { callOriginal() }
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.dao.AttendanceDao
|
import io.github.wulkanowy.data.db.dao.AttendanceDao
|
||||||
import io.github.wulkanowy.data.db.dao.TimetableDao
|
import io.github.wulkanowy.data.db.dao.TimetableDao
|
||||||
@ -16,8 +17,8 @@ import io.mockk.coEvery
|
|||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
@ -30,8 +31,8 @@ import io.github.wulkanowy.sdk.pojo.Attendance as SdkAttendance
|
|||||||
|
|
||||||
class AttendanceRepositoryTest {
|
class AttendanceRepositoryTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var attendanceDb: AttendanceDao
|
private lateinit var attendanceDb: AttendanceDao
|
||||||
@ -63,7 +64,8 @@ class AttendanceRepositoryTest {
|
|||||||
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
||||||
coEvery { timetableDb.load(any(), any(), any(), any()) } returns emptyList()
|
coEvery { timetableDb.load(any(), any(), any(), any()) } returns emptyList()
|
||||||
|
|
||||||
attendanceRepository = AttendanceRepository(attendanceDb, timetableDb, sdk, refreshHelper)
|
attendanceRepository =
|
||||||
|
AttendanceRepository(attendanceDb, timetableDb, wulkanowySdkFactory, refreshHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.dao.CompletedLessonsDao
|
import io.github.wulkanowy.data.db.dao.CompletedLessonsDao
|
||||||
import io.github.wulkanowy.data.errorOrNull
|
import io.github.wulkanowy.data.errorOrNull
|
||||||
@ -15,8 +16,8 @@ import io.mockk.coEvery
|
|||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@ -28,8 +29,8 @@ import io.github.wulkanowy.sdk.pojo.CompletedLesson as SdkCompletedLesson
|
|||||||
|
|
||||||
class CompletedLessonsRepositoryTest {
|
class CompletedLessonsRepositoryTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var completedLessonDb: CompletedLessonsDao
|
private lateinit var completedLessonDb: CompletedLessonsDao
|
||||||
@ -58,7 +59,7 @@ class CompletedLessonsRepositoryTest {
|
|||||||
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
||||||
|
|
||||||
completedLessonRepository =
|
completedLessonRepository =
|
||||||
CompletedLessonsRepository(completedLessonDb, sdk, refreshHelper)
|
CompletedLessonsRepository(completedLessonDb, wulkanowySdkFactory, refreshHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.dao.ExamDao
|
import io.github.wulkanowy.data.db.dao.ExamDao
|
||||||
import io.github.wulkanowy.data.errorOrNull
|
import io.github.wulkanowy.data.errorOrNull
|
||||||
@ -15,8 +16,8 @@ import io.mockk.coEvery
|
|||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
@ -28,8 +29,8 @@ import io.github.wulkanowy.sdk.pojo.Exam as SdkExam
|
|||||||
|
|
||||||
class ExamRemoteTest {
|
class ExamRemoteTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var examDb: ExamDao
|
private lateinit var examDb: ExamDao
|
||||||
@ -59,7 +60,7 @@ class ExamRemoteTest {
|
|||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
||||||
|
|
||||||
examRepository = ExamRepository(examDb, sdk, refreshHelper)
|
examRepository = ExamRepository(examDb, wulkanowySdkFactory, refreshHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.dao.GradeDao
|
import io.github.wulkanowy.data.db.dao.GradeDao
|
||||||
import io.github.wulkanowy.data.db.dao.GradeDescriptiveDao
|
import io.github.wulkanowy.data.db.dao.GradeDescriptiveDao
|
||||||
@ -18,8 +19,8 @@ import io.mockk.coEvery
|
|||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
@ -35,8 +36,8 @@ import io.github.wulkanowy.sdk.pojo.Grade as SdkGrade
|
|||||||
|
|
||||||
class GradeRepositoryTest {
|
class GradeRepositoryTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var gradeDb: GradeDao
|
private lateinit var gradeDb: GradeDao
|
||||||
@ -65,7 +66,7 @@ class GradeRepositoryTest {
|
|||||||
gradeDb = gradeDb,
|
gradeDb = gradeDb,
|
||||||
gradeSummaryDb = gradeSummaryDb,
|
gradeSummaryDb = gradeSummaryDb,
|
||||||
gradeDescriptiveDb = gradeDescriptiveDb,
|
gradeDescriptiveDb = gradeDescriptiveDb,
|
||||||
sdk = sdk,
|
wulkanowySdkFactory = wulkanowySdkFactory,
|
||||||
refreshHelper = refreshHelper,
|
refreshHelper = refreshHelper,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.dao.GradePartialStatisticsDao
|
import io.github.wulkanowy.data.db.dao.GradePartialStatisticsDao
|
||||||
import io.github.wulkanowy.data.db.dao.GradePointsStatisticsDao
|
import io.github.wulkanowy.data.db.dao.GradePointsStatisticsDao
|
||||||
@ -13,9 +14,14 @@ import io.github.wulkanowy.sdk.Sdk
|
|||||||
import io.github.wulkanowy.sdk.pojo.GradeStatisticsItem
|
import io.github.wulkanowy.sdk.pojo.GradeStatisticsItem
|
||||||
import io.github.wulkanowy.sdk.pojo.GradeStatisticsSubject
|
import io.github.wulkanowy.sdk.pojo.GradeStatisticsSubject
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.mockk.*
|
import io.mockk.MockKAnnotations
|
||||||
|
import io.mockk.Runs
|
||||||
|
import io.mockk.coEvery
|
||||||
|
import io.mockk.coVerify
|
||||||
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@ -24,8 +30,8 @@ import org.junit.Test
|
|||||||
|
|
||||||
class GradeStatisticsRepositoryTest {
|
class GradeStatisticsRepositoryTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var gradePartialStatisticsDb: GradePartialStatisticsDao
|
private lateinit var gradePartialStatisticsDb: GradePartialStatisticsDao
|
||||||
@ -54,7 +60,7 @@ class GradeStatisticsRepositoryTest {
|
|||||||
gradePartialStatisticsDb = gradePartialStatisticsDb,
|
gradePartialStatisticsDb = gradePartialStatisticsDb,
|
||||||
gradePointsStatisticsDb = gradePointsStatisticsDb,
|
gradePointsStatisticsDb = gradePointsStatisticsDb,
|
||||||
gradeSemesterStatisticsDb = gradeSemesterStatisticsDb,
|
gradeSemesterStatisticsDb = gradeSemesterStatisticsDb,
|
||||||
sdk = sdk,
|
wulkanowySdkFactory = wulkanowySdkFactory,
|
||||||
refreshHelper = refreshHelper,
|
refreshHelper = refreshHelper,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.dao.LuckyNumberDao
|
import io.github.wulkanowy.data.db.dao.LuckyNumberDao
|
||||||
import io.github.wulkanowy.data.errorOrNull
|
import io.github.wulkanowy.data.errorOrNull
|
||||||
@ -12,8 +13,8 @@ import io.mockk.Runs
|
|||||||
import io.mockk.coEvery
|
import io.mockk.coEvery
|
||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
@ -25,8 +26,8 @@ import io.github.wulkanowy.sdk.pojo.LuckyNumber as SdkLuckyNumber
|
|||||||
|
|
||||||
class LuckyNumberRemoteTest {
|
class LuckyNumberRemoteTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var luckyNumberDb: LuckyNumberDao
|
private lateinit var luckyNumberDb: LuckyNumberDao
|
||||||
@ -43,7 +44,7 @@ class LuckyNumberRemoteTest {
|
|||||||
fun setUp() {
|
fun setUp() {
|
||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
|
|
||||||
luckyNumberRepository = LuckyNumberRepository(luckyNumberDb, sdk)
|
luckyNumberRepository = LuckyNumberRepository(luckyNumberDb, wulkanowySdkFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.SharedPrefProvider
|
import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||||
import io.github.wulkanowy.data.db.dao.MailboxDao
|
import io.github.wulkanowy.data.db.dao.MailboxDao
|
||||||
@ -28,10 +29,9 @@ import io.mockk.coEvery
|
|||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
@ -45,11 +45,10 @@ import java.time.Instant
|
|||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
class MessageRepositoryTest {
|
class MessageRepositoryTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var messageDb: MessagesDao
|
private lateinit var messageDb: MessagesDao
|
||||||
@ -102,7 +101,7 @@ class MessageRepositoryTest {
|
|||||||
messagesDb = messageDb,
|
messagesDb = messageDb,
|
||||||
mutedMessageSendersDao = mutesDb,
|
mutedMessageSendersDao = mutesDb,
|
||||||
messageAttachmentDao = messageAttachmentDao,
|
messageAttachmentDao = messageAttachmentDao,
|
||||||
sdk = sdk,
|
wulkanowySdkFactory = wulkanowySdkFactory,
|
||||||
context = context,
|
context = context,
|
||||||
refreshHelper = refreshHelper,
|
refreshHelper = refreshHelper,
|
||||||
sharedPrefProvider = sharedPrefProvider,
|
sharedPrefProvider = sharedPrefProvider,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.dao.MobileDeviceDao
|
import io.github.wulkanowy.data.db.dao.MobileDeviceDao
|
||||||
import io.github.wulkanowy.data.errorOrNull
|
import io.github.wulkanowy.data.errorOrNull
|
||||||
@ -16,8 +17,8 @@ import io.mockk.coEvery
|
|||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
@ -28,8 +29,8 @@ import java.time.ZonedDateTime.of
|
|||||||
|
|
||||||
class MobileDeviceRepositoryTest {
|
class MobileDeviceRepositoryTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var mobileDeviceDb: MobileDeviceDao
|
private lateinit var mobileDeviceDb: MobileDeviceDao
|
||||||
@ -53,7 +54,8 @@ class MobileDeviceRepositoryTest {
|
|||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
||||||
|
|
||||||
mobileDeviceRepository = MobileDeviceRepository(mobileDeviceDb, sdk, refreshHelper)
|
mobileDeviceRepository =
|
||||||
|
MobileDeviceRepository(mobileDeviceDb, wulkanowySdkFactory, refreshHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.db.dao.RecipientDao
|
import io.github.wulkanowy.data.db.dao.RecipientDao
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.getMailboxEntity
|
import io.github.wulkanowy.getMailboxEntity
|
||||||
@ -7,9 +8,14 @@ import io.github.wulkanowy.getStudentEntity
|
|||||||
import io.github.wulkanowy.sdk.Sdk
|
import io.github.wulkanowy.sdk.Sdk
|
||||||
import io.github.wulkanowy.sdk.pojo.MailboxType
|
import io.github.wulkanowy.sdk.pojo.MailboxType
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.mockk.*
|
import io.mockk.MockKAnnotations
|
||||||
|
import io.mockk.Runs
|
||||||
|
import io.mockk.coEvery
|
||||||
|
import io.mockk.coVerify
|
||||||
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@ -18,8 +24,8 @@ import io.github.wulkanowy.sdk.pojo.Recipient as SdkRecipient
|
|||||||
|
|
||||||
class RecipientLocalTest {
|
class RecipientLocalTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var recipientDb: RecipientDao
|
private lateinit var recipientDb: RecipientDao
|
||||||
@ -63,7 +69,7 @@ class RecipientLocalTest {
|
|||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
every { refreshHelper.shouldBeRefreshed(any()) } returns false
|
||||||
|
|
||||||
recipientRepository = RecipientRepository(recipientDb, sdk, refreshHelper)
|
recipientRepository = RecipientRepository(recipientDb, wulkanowySdkFactory, refreshHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
import io.github.wulkanowy.TestDispatchersProvider
|
import io.github.wulkanowy.TestDispatchersProvider
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.db.dao.SemesterDao
|
import io.github.wulkanowy.data.db.dao.SemesterDao
|
||||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.getSemesterEntity
|
import io.github.wulkanowy.getSemesterEntity
|
||||||
@ -12,8 +13,8 @@ import io.mockk.Runs
|
|||||||
import io.mockk.coEvery
|
import io.mockk.coEvery
|
||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@ -24,8 +25,8 @@ import java.time.LocalDate.now
|
|||||||
|
|
||||||
class SemesterRepositoryTest {
|
class SemesterRepositoryTest {
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var semesterDb: SemesterDao
|
private lateinit var semesterDb: SemesterDao
|
||||||
@ -38,7 +39,8 @@ class SemesterRepositoryTest {
|
|||||||
fun initTest() {
|
fun initTest() {
|
||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
|
|
||||||
semesterRepository = SemesterRepository(semesterDb, sdk, TestDispatchersProvider())
|
semesterRepository =
|
||||||
|
SemesterRepository(semesterDb, wulkanowySdkFactory, TestDispatchersProvider())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.data.repositories
|
package io.github.wulkanowy.data.repositories
|
||||||
|
|
||||||
|
import io.github.wulkanowy.createWulkanowySdkFactoryMock
|
||||||
import io.github.wulkanowy.data.dataOrNull
|
import io.github.wulkanowy.data.dataOrNull
|
||||||
import io.github.wulkanowy.data.db.dao.TimetableAdditionalDao
|
import io.github.wulkanowy.data.db.dao.TimetableAdditionalDao
|
||||||
import io.github.wulkanowy.data.db.dao.TimetableDao
|
import io.github.wulkanowy.data.db.dao.TimetableDao
|
||||||
@ -18,9 +19,9 @@ import io.mockk.coEvery
|
|||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.impl.annotations.SpyK
|
|
||||||
import io.mockk.just
|
import io.mockk.just
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
|
import io.mockk.spyk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@ -37,8 +38,8 @@ class TimetableRepositoryTest {
|
|||||||
@MockK(relaxed = true)
|
@MockK(relaxed = true)
|
||||||
private lateinit var timetableNotificationSchedulerHelper: TimetableNotificationSchedulerHelper
|
private lateinit var timetableNotificationSchedulerHelper: TimetableNotificationSchedulerHelper
|
||||||
|
|
||||||
@SpyK
|
private var sdk = spyk<Sdk>()
|
||||||
private var sdk = Sdk()
|
private val wulkanowySdkFactory = createWulkanowySdkFactoryMock(sdk)
|
||||||
|
|
||||||
@MockK
|
@MockK
|
||||||
private lateinit var timetableDb: TimetableDao
|
private lateinit var timetableDb: TimetableDao
|
||||||
@ -71,7 +72,7 @@ class TimetableRepositoryTest {
|
|||||||
timetableDb,
|
timetableDb,
|
||||||
timetableAdditionalDao,
|
timetableAdditionalDao,
|
||||||
timetableHeaderDao,
|
timetableHeaderDao,
|
||||||
sdk,
|
wulkanowySdkFactory,
|
||||||
timetableNotificationSchedulerHelper,
|
timetableNotificationSchedulerHelper,
|
||||||
refreshHelper
|
refreshHelper
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user