From 3c316c7cbaf0a5368958da37bce2384f94400338 Mon Sep 17 00:00:00 2001 From: "Your laurynas.lopata@epfl.ch" Date: Fri, 29 Apr 2022 00:39:18 +0200 Subject: [PATCH] Added docs --- .../ch/sdp/vibester/database/DataGetter.kt | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 18fa7ab62..5de362094 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -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) @@ -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) { @@ -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()) } }) }