Skip to content

Commit

Permalink
fix: using map instead of for loop in USERAPI and ASSOCIATIONAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
zizouet committed Apr 6, 2024
1 parent b176df9 commit d639820
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ class AssociationAPI(db: FirebaseFirestore) : FirebaseApi(db) {
return Tasks.await(
db.collection(collectionName).get().continueWith { task ->
if (task.isSuccessful) {
val associations = mutableListOf<Association>()
for (document in task.result!!.documents) {
val association = document.toObject(Association::class.java)
associations.add(association!!)
task.result!!.map { document ->
document.toObject(Association::class.java)
}
associations
} else {
throw task.exception ?: Exception("Unknown error occurred")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ abstract class FirebaseApi(val db: FirebaseFirestore) {
/** The name of the collection in the database */
abstract val collectionName: String


/**
* Gets a new id for a document in the collection
*
* @return the new id
*/
fun getNewId() = db.collection(collectionName).document().id


fun delete(id: String) = db.collection(collectionName).document(id).delete()
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ class UserAPI(db: FirebaseFirestore) : FirebaseApi(db) {
return Tasks.await(
db.collection(collectionName).get().continueWith { task ->
if (task.isSuccessful) {
val users = mutableListOf<User>()
for (document in task.result!!.documents) {
val user = document.toObject(User::class.java)
users.add(user!!)
task.result!!.map { document ->
document.toObject(User::class.java)
}
users
} else {
throw task.exception ?: Exception("Unknown error occurred")
}
Expand Down

0 comments on commit d639820

Please sign in to comment.