diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/SessionReport.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/SessionReport.kt new file mode 100644 index 0000000..af6b1c0 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/SessionReport.kt @@ -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) + ) \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/di/DatabaseModule.kt b/app/src/main/java/be/ugent/sel/studeez/di/DatabaseModule.kt index e3c466c..1b696fe 100644 --- a/app/src/main/java/be/ugent/sel/studeez/di/DatabaseModule.kt +++ b/app/src/main/java/be/ugent/sel/studeez/di/DatabaseModule.kt @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/SessionDAO.kt b/app/src/main/java/be/ugent/sel/studeez/domain/SessionDAO.kt new file mode 100644 index 0000000..77087d2 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/SessionDAO.kt @@ -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> + + fun saveSession(newSessionReport: SessionReport) + + fun deleteSession(newTimer: TimerInfo) + +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FireBaseSessionDAO.kt b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FireBaseSessionDAO.kt new file mode 100644 index 0000000..07afdda --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FireBaseSessionDAO.kt @@ -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> { + 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) + +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseCollectionRoutes.kt b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseCollectionRoutes.kt new file mode 100644 index 0000000..2471301 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseCollectionRoutes.kt @@ -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" + +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseTimerDAO.kt b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseTimerDAO.kt index a25c37c..901f9d6 100644 --- a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseTimerDAO.kt +++ b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseTimerDAO.kt @@ -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) } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeViewModel.kt index 7db6f8d..b27f995 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeViewModel.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeViewModel.kt @@ -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