commit
58d0d4fe91
7 changed files with 75 additions and 10 deletions
|
@ -0,0 +1,10 @@
|
|||
package be.ugent.sel.studeez.data.local.models
|
||||
|
||||
import com.google.firebase.Timestamp
|
||||
import com.google.firebase.firestore.DocumentId
|
||||
|
||||
data class SessionReport(
|
||||
@DocumentId val id: String = "",
|
||||
val studyTime: Int = 0,
|
||||
val endTime: Timestamp = Timestamp(0, 0)
|
||||
)
|
|
@ -19,4 +19,6 @@ abstract class DatabaseModule {
|
|||
@Binds abstract fun provideLogService(impl: LogServiceImpl): LogService
|
||||
|
||||
@Binds abstract fun provideConfigurationService(impl: FirebaseConfigurationService): ConfigurationService
|
||||
|
||||
@Binds abstract fun provideSessionDAO(impl: FireBaseSessionDAO): SessionDAO
|
||||
}
|
15
app/src/main/java/be/ugent/sel/studeez/domain/SessionDAO.kt
Normal file
15
app/src/main/java/be/ugent/sel/studeez/domain/SessionDAO.kt
Normal file
|
@ -0,0 +1,15 @@
|
|||
package be.ugent.sel.studeez.domain
|
||||
|
||||
import be.ugent.sel.studeez.data.local.models.SessionReport
|
||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface SessionDAO {
|
||||
|
||||
fun getSessions(): Flow<List<SessionReport>>
|
||||
|
||||
fun saveSession(newSessionReport: SessionReport)
|
||||
|
||||
fun deleteSession(newTimer: TimerInfo)
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package be.ugent.sel.studeez.domain.implementation
|
||||
|
||||
import be.ugent.sel.studeez.data.local.models.SessionReport
|
||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
||||
import be.ugent.sel.studeez.domain.AccountDAO
|
||||
import be.ugent.sel.studeez.domain.SessionDAO
|
||||
import com.google.firebase.firestore.CollectionReference
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
import com.google.firebase.firestore.ktx.snapshots
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import javax.inject.Inject
|
||||
|
||||
class FireBaseSessionDAO @Inject constructor(
|
||||
private val firestore: FirebaseFirestore,
|
||||
private val auth: AccountDAO
|
||||
) : SessionDAO {
|
||||
|
||||
override fun getSessions(): Flow<List<SessionReport>> {
|
||||
return currentUserSessionsCollection()
|
||||
.snapshots()
|
||||
.map { it.toObjects(SessionReport::class.java) }
|
||||
}
|
||||
|
||||
override fun saveSession(newSessionReport: SessionReport) {
|
||||
currentUserSessionsCollection().add(newSessionReport)
|
||||
}
|
||||
|
||||
override fun deleteSession(newTimer: TimerInfo) {
|
||||
currentUserSessionsCollection().document(newTimer.id).delete()
|
||||
}
|
||||
|
||||
private fun currentUserSessionsCollection(): CollectionReference =
|
||||
firestore.collection(FirebaseCollectionRoutes.USER_COLLECTION)
|
||||
.document(auth.currentUserId)
|
||||
.collection(FirebaseCollectionRoutes.SESSION_COLLECTION)
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package be.ugent.sel.studeez.domain.implementation
|
||||
|
||||
object FirebaseCollectionRoutes {
|
||||
const val SESSION_COLLECTION = "sessions"
|
||||
const val USER_COLLECTION = "users"
|
||||
const val TIMER_COLLECTION = "timers"
|
||||
|
||||
}
|
|
@ -50,14 +50,8 @@ class FirebaseTimerDAO @Inject constructor(
|
|||
}
|
||||
|
||||
private fun currentUserTimersCollection(): CollectionReference =
|
||||
firestore.collection(USER_COLLECTION)
|
||||
firestore.collection(FirebaseCollectionRoutes.USER_COLLECTION)
|
||||
.document(auth.currentUserId)
|
||||
.collection(TIMER_COLLECTION)
|
||||
|
||||
|
||||
companion object {
|
||||
private const val TIMER_COLLECTION = "timers"
|
||||
private const val USER_COLLECTION = "users"
|
||||
}
|
||||
.collection(FirebaseCollectionRoutes.TIMER_COLLECTION)
|
||||
|
||||
}
|
|
@ -3,8 +3,6 @@ package be.ugent.sel.studeez.screens.home
|
|||
import be.ugent.sel.studeez.domain.AccountDAO
|
||||
import be.ugent.sel.studeez.domain.LogService
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN
|
||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
|
Reference in a new issue