diff --git a/app/src/androidTest/java/com/github/se/assocify/AssociationAPITest.kt b/app/src/androidTest/java/com/github/se/assocify/AssociationAPITest.kt index 9a46baf8d..2b67eb1aa 100644 --- a/app/src/androidTest/java/com/github/se/assocify/AssociationAPITest.kt +++ b/app/src/androidTest/java/com/github/se/assocify/AssociationAPITest.kt @@ -65,7 +65,7 @@ class AssociationAPITest { .thenReturn(listOf(asso)) Mockito.`when`(documentSnapshot.toObject(Association::class.java)).thenReturn(asso) var result: List? = null - assoAPI.getAssociations(){associations -> result = associations} + assoAPI.getAssociations() { associations -> result = associations } Mockito.verify(db).collection(assoAPI.collectionName) Mockito.verify(db.collection(assoAPI.collectionName)).get() diff --git a/app/src/androidTest/java/com/github/se/assocify/UserAPITest.kt b/app/src/androidTest/java/com/github/se/assocify/UserAPITest.kt index c3d6db119..9aaac530c 100644 --- a/app/src/androidTest/java/com/github/se/assocify/UserAPITest.kt +++ b/app/src/androidTest/java/com/github/se/assocify/UserAPITest.kt @@ -42,7 +42,7 @@ class UserAPITest { Mockito.`when`(db.collection(Mockito.any()).document(Mockito.any())) .thenReturn(documentReference) var result: User? = null - userAPI.getUser(user.uid){user: User -> result = user} + userAPI.getUser(user.uid) { user: User -> result = user } Mockito.verify(db).collection(userAPI.collectionName) Mockito.verify(db.collection(userAPI.collectionName)).document(user.uid) @@ -62,7 +62,7 @@ class UserAPITest { .thenReturn(listOf(user)) Mockito.`when`(documentSnapshot.toObject(User::class.java)).thenReturn(user) var result: List = emptyList() - userAPI.getAllUsers(){users -> result = users} + userAPI.getAllUsers() { users -> result = users } Mockito.verify(db).collection(userAPI.collectionName) Mockito.verify(db.collection(userAPI.collectionName)).get() assert(result.size == 1) diff --git a/app/src/main/java/com/github/se/assocify/model/associations/AssociationUtils.kt b/app/src/main/java/com/github/se/assocify/model/associations/AssociationUtils.kt index 1d5fa4279..8abc64c27 100644 --- a/app/src/main/java/com/github/se/assocify/model/associations/AssociationUtils.kt +++ b/app/src/main/java/com/github/se/assocify/model/associations/AssociationUtils.kt @@ -18,7 +18,8 @@ class AssociationUtils( } fun update() { - if (assocId != "") associationDatabase.getAssociation(assocId){ assoc -> _associationState = assoc } + if (assocId != "") + associationDatabase.getAssociation(assocId) { assoc -> _associationState = assoc } } fun getAssocId(): String { @@ -131,9 +132,9 @@ class AssociationUtils( fun getAllAssociations(): List { if (_associationState == null) return emptyList() - var result : List? = null - associationDatabase.getAssociations(){associations -> result = associations} - + var result: List? = null + associationDatabase.getAssociations() { associations -> result = associations } + return result!! } diff --git a/app/src/main/java/com/github/se/assocify/model/database/AssociationAPI.kt b/app/src/main/java/com/github/se/assocify/model/database/AssociationAPI.kt index ca0d7d7b0..658120ae5 100644 --- a/app/src/main/java/com/github/se/assocify/model/database/AssociationAPI.kt +++ b/app/src/main/java/com/github/se/assocify/model/database/AssociationAPI.kt @@ -18,21 +18,21 @@ class AssociationAPI(db: FirebaseFirestore) : FirebaseApi(db) { * @param callback the callback to call with the association * @return the association with the given id */ - fun getAssociation(id: String, callback : (Association) -> Unit ) { + fun getAssociation(id: String, callback: (Association) -> Unit) { - db.collection(collectionName).document(id).get().continueWith { task -> - if (task.isSuccessful) { - val document = task.result - if (document != null && document.exists()) { - val doc = document.toObject(Association::class.java) - callback(doc!!) - } else { - throw Exception("No Asso found with ID: $id") - } + db.collection(collectionName).document(id).get().continueWith { task -> + if (task.isSuccessful) { + val document = task.result + if (document != null && document.exists()) { + val doc = document.toObject(Association::class.java) + callback(doc!!) } else { - throw task.exception ?: Exception("Unknown error occurred") + throw Exception("No Asso found with ID: $id") } + } else { + throw task.exception ?: Exception("Unknown error occurred") } + } } /** @@ -41,15 +41,16 @@ class AssociationAPI(db: FirebaseFirestore) : FirebaseApi(db) { * @param callback the callback to call with the list of associations * @return a list of all associations */ - fun getAssociations(callback : (List) -> Unit) { - db.collection(collectionName).get().continueWith { task -> - if (task.isSuccessful) { - val associations = task.result!!.documents.map { document -> document.toObject(Association::class.java)!! } - callback(associations) - } else { - throw task.exception ?: Exception("Unknown error occurred") - } + fun getAssociations(callback: (List) -> Unit) { + db.collection(collectionName).get().continueWith { task -> + if (task.isSuccessful) { + val associations = + task.result!!.documents.map { document -> document.toObject(Association::class.java)!! } + callback(associations) + } else { + throw task.exception ?: Exception("Unknown error occurred") } + } } /** diff --git a/app/src/main/java/com/github/se/assocify/model/database/UserAPI.kt b/app/src/main/java/com/github/se/assocify/model/database/UserAPI.kt index ec9916983..6524eed72 100644 --- a/app/src/main/java/com/github/se/assocify/model/database/UserAPI.kt +++ b/app/src/main/java/com/github/se/assocify/model/database/UserAPI.kt @@ -1,8 +1,6 @@ package com.github.se.assocify.model.database import com.github.se.assocify.model.entities.User -import com.google.android.gms.tasks.Task -import com.google.android.gms.tasks.Tasks import com.google.firebase.firestore.FirebaseFirestore /** @@ -21,7 +19,7 @@ class UserAPI(db: FirebaseFirestore) : FirebaseApi(db) { * @param callback the callback to call with the user * @return the user with the given id */ - fun getUser(id: String, callback : (User) -> Unit ){ + fun getUser(id: String, callback: (User) -> Unit) { db.collection(collectionName).document(id).get().continueWith { task -> if (task.isSuccessful) { val document = task.result @@ -42,16 +40,17 @@ class UserAPI(db: FirebaseFirestore) : FirebaseApi(db) { * @param callback the callback to call with the list of users * @return a list of all users */ - fun getAllUsers(callback : (List)->Unit) { + fun getAllUsers(callback: (List) -> Unit) { - db.collection(collectionName).get().continueWith { task -> - if (task.isSuccessful) { - val users = task.result!!.documents.map { document -> document.toObject(User::class.java)!! } - callback(users) - } else { - throw task.exception ?: Exception("Unknown error occurred") - } - } + db.collection(collectionName).get().continueWith { task -> + if (task.isSuccessful) { + val users = + task.result!!.documents.map { document -> document.toObject(User::class.java)!! } + callback(users) + } else { + throw task.exception ?: Exception("Unknown error occurred") + } + } } /**