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..ae6ec4e --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/SessionReport.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.data.local.models + +class SessionReport { +} \ 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..59faa6b --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/SessionDAO.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.domain + +interface SessionDAO { +} \ 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..1fbe2cb --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FireBaseSessionDAO.kt @@ -0,0 +1,43 @@ +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(USER_COLLECTION) + .document(auth.currentUserId) + .collection(SESSION_COLLECTION) + + companion object { + private const val SESSION_COLLECTION = "sessions" + private const val USER_COLLECTION = "users" + } + +} \ No newline at end of file