Skip to content

Commit

Permalink
fix ktfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zizouet committed Apr 10, 2024
1 parent f3cf2c7 commit 6fc9381
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AssociationAPITest {
.thenReturn(listOf(asso))
Mockito.`when`(documentSnapshot.toObject(Association::class.java)).thenReturn(asso)
var result: List<Association>? = null
assoAPI.getAssociations(){associations -> result = associations}
assoAPI.getAssociations() { associations -> result = associations }

Mockito.verify(db).collection(assoAPI.collectionName)
Mockito.verify(db.collection(assoAPI.collectionName)).get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -62,7 +62,7 @@ class UserAPITest {
.thenReturn(listOf(user))
Mockito.`when`(documentSnapshot.toObject(User::class.java)).thenReturn(user)
var result: List<User> = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -131,9 +132,9 @@ class AssociationUtils(

fun getAllAssociations(): List<Association> {
if (_associationState == null) return emptyList()
var result : List<Association>? = null
associationDatabase.getAssociations(){associations -> result = associations}
var result: List<Association>? = null
associationDatabase.getAssociations() { associations -> result = associations }

return result!!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

/**
Expand All @@ -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<Association>) -> 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<Association>) -> 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")
}
}
}

/**
Expand Down
23 changes: 11 additions & 12 deletions app/src/main/java/com/github/se/assocify/model/database/UserAPI.kt
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -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
Expand All @@ -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<User>)->Unit) {
fun getAllUsers(callback: (List<User>) -> 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")
}
}
}

/**
Expand Down

0 comments on commit 6fc9381

Please sign in to comment.