#71 Define Friendship DAO's
This commit is contained in:
		
							parent
							
								
									4419c86b05
								
							
						
					
					
						commit
						75411627ac
					
				
					 3 changed files with 88 additions and 4 deletions
				
			
		|  | @ -0,0 +1,11 @@ | |||
| package be.ugent.sel.studeez.data.local.models | ||||
| 
 | ||||
| import com.google.firebase.Timestamp | ||||
| import com.google.firebase.firestore.DocumentId | ||||
| 
 | ||||
| data class Friendship( | ||||
|     @DocumentId val id: String = "", | ||||
|     val friendId: String = "", | ||||
|     val friendsSince: Timestamp = Timestamp.now(), | ||||
|     val accepted: Boolean = false | ||||
| ) | ||||
|  | @ -0,0 +1,48 @@ | |||
| package be.ugent.sel.studeez.domain | ||||
| 
 | ||||
| import be.ugent.sel.studeez.data.local.models.Friendship | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| 
 | ||||
| /** | ||||
|  * Should be used for interactions between friends. | ||||
|  */ | ||||
| interface FriendshipDAO { | ||||
| 
 | ||||
|     /** | ||||
|      * @return all friendships of the user that is currently logged in. | ||||
|      */ | ||||
|     fun getAllFriendships(): Flow<List<Friendship>> | ||||
| 
 | ||||
|     /** | ||||
|      * @return the amount of friends of the currently logged in user. | ||||
|      * This method should be faster than just counting the length of getAllFriends() | ||||
|      */ | ||||
|     fun getFriendshipCount(): Flow<Int> | ||||
| 
 | ||||
|     /** | ||||
|      * @param id the id of the friendship that you want details of | ||||
|      * @return the details of a Friendship | ||||
|      */ | ||||
|     fun getFriendshipDetails(id: String): Friendship | ||||
| 
 | ||||
|     /** | ||||
|      * Send a friend request to a user. | ||||
|      * @param id of the user that you want to add as a friend | ||||
|      * @return Success/faillure of transaction | ||||
|      */ | ||||
|     fun sendFriendshipRequest(id: String): Boolean | ||||
| 
 | ||||
|     /** | ||||
|      * Accept a friend request that has already been sent. | ||||
|      * @param id of the friendship that you want to update | ||||
|      * @return: Success/faillure of transaction | ||||
|      */ | ||||
|     fun acceptFriendship(id: String): Boolean | ||||
| 
 | ||||
|     /** | ||||
|      * Remove a friend or decline a friendrequest. | ||||
|      * @param id of the friendship that you want to update | ||||
|      * @return: Success/faillure of transaction | ||||
|      */ | ||||
|     fun removeFriendship(id: String): Boolean | ||||
| } | ||||
|  | @ -1,19 +1,44 @@ | |||
| package be.ugent.sel.studeez.domain | ||||
| 
 | ||||
| import be.ugent.sel.studeez.data.local.models.User | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| 
 | ||||
| interface UserDAO { | ||||
| 
 | ||||
|     suspend fun getUser(): User | ||||
|     /** | ||||
|      * @return all users | ||||
|      */ | ||||
|     fun getAllUsers(): Flow<List<User>> | ||||
| 
 | ||||
|     suspend fun saveUser( | ||||
|     /** | ||||
|      * @return all users based on a query, a trimmed down version of getAllUsers() | ||||
|      */ | ||||
|     fun getUsersWithQuery(): Flow<List<User>> | ||||
|     // TODO Add query parameter | ||||
| 
 | ||||
|     /** | ||||
|      * Request information about a user | ||||
|      */ | ||||
|     fun getUserDetails( | ||||
|         userId: String | ||||
|     ): Flow<User> | ||||
| 
 | ||||
|     /** | ||||
|      * @return information on the currently logged in user. | ||||
|      */ | ||||
|     suspend fun getLoggedInUser(): User | ||||
|     // TODO Should be refactored to fun getLoggedInUser(): Flow<User>, without suspend. | ||||
| 
 | ||||
|     suspend fun saveLoggedInUser( | ||||
|         newUsername: String, | ||||
|         newBiography: String = "" | ||||
|     ) | ||||
|     // TODO Should be refactored to fun saveLoggedInUser(...): Boolean, without suspend. | ||||
| 
 | ||||
|     /** | ||||
|      * Delete all references to this user in the database. Similar to the deleteCascade in | ||||
|      * Delete all references to the logged in user in the database. Similar to the deleteCascade in | ||||
|      * relational databases. | ||||
|      */ | ||||
|     suspend fun deleteUserReferences() | ||||
|     suspend fun deleteLoggedInUserReferences() | ||||
|     // TODO Should be refactored to fun deleteLoggedInUserReferences(): Boolean, without suspend. | ||||
| } | ||||
		Reference in a new issue