From 1e767d22a4272e67a5dbcb7525f539c680f49903 Mon Sep 17 00:00:00 2001 From: Lukas Barragan Torres Date: Tue, 18 Apr 2023 15:34:41 +0200 Subject: [PATCH] #76 added sessionDAO --- .../data/local/models/SessionReport.kt | 4 ++ .../be/ugent/sel/studeez/domain/SessionDAO.kt | 4 ++ .../implementation/FireBaseSessionDAO.kt | 43 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/SessionReport.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/domain/SessionDAO.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/domain/implementation/FireBaseSessionDAO.kt 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