Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
laurislopata committed Apr 28, 2022
1 parent 5d0deb6 commit 3c316c7
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions app/src/main/java/ch/sdp/vibester/database/DataGetter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class DataGetter @Inject constructor() {
}
}

/**
* This function creates a new room in the database
* @param roomName the name of the new room
* @param callback function to be called when the room has been created
*/
fun createRoom(roomName: String, callback: (PartyRoom) -> Unit) {
val partyRoom = PartyRoom()
partyRoom.setRoomName(roomName)
Expand Down Expand Up @@ -183,14 +188,25 @@ class DataGetter @Inject constructor() {
})
}

/**
* This functions that updates the users of a room
* @param partyRoom the new room
*/
fun updateRoomUserList(partyRoom: PartyRoom) {
dbRoomRef.child(partyRoom.getRoomID()).child("emailList").setValue(partyRoom.getEmailList())
}

/**
* This functions fetches the data of the given user from the database
* @param roomName the name of the room to retrieve data from
* @param callback the function to be called when the data of the appropriate user is available
*/

fun getRoomData(roomName: String, callback: (PartyRoom) -> Unit) {
val queryRooms = dbRoomRef
.orderByChild("roomName")
.equalTo(roomName)

Log.w("DEBUG LMAO:", "I get to here")
Log.w("DEBUG LMAO:", roomName)

queryRooms.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (snapshot in dataSnapshot.children) {
Expand All @@ -199,14 +215,14 @@ class DataGetter @Inject constructor() {
val currUserEmail = authenticator.getCurrUser()?.email!!
if(!partyRoom.getEmailList().contains(currUserEmail)) {
partyRoom.addUserEmail(currUserEmail)
dbRoomRef.child(partyRoom.getRoomID()).child("emailList").setValue(partyRoom.getEmailList())
updateRoomUserList(partyRoom)
}
callback(partyRoom)
}
}
}
override fun onCancelled(error: DatabaseError) {
Log.w(ContentValues.TAG, "searchByField:onCancelled", error.toException())
Log.w(ContentValues.TAG, "getRoomData:onCancelled", error.toException())
}
})
}
Expand Down

0 comments on commit 3c316c7

Please sign in to comment.