Skip to content

Commit

Permalink
style(association-manager): format using ktmft formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelien9Code committed Dec 20, 2024
1 parent 70c5067 commit 9e40150
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 359 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ constructor(
return member.user.element
}

/**
* Adds a new role to the specified association in the local list. If the role already exists,
* it will not be added again. The association's roles are updated, and if the association is
* selected, the selected association is also updated.
*
* @param associationId The ID of the association to update.
* @param newRole The new role to add to the association.
*/
/**
* Adds a new role to the specified association in the local list. If the role already exists, it
* will not be added again. The association's roles are updated, and if the association is
* selected, the selected association is also updated.
*
* @param associationId The ID of the association to update.
* @param newRole The new role to add to the association.
*/
fun addRoleLocally(associationId: String, newRole: Role) {
val association = _associations.value.find { it.uid == associationId }

Expand All @@ -85,7 +85,6 @@ constructor(
return
}


val updatedRoles = association.roles + newRole
val updatedAssociation = association.copy(roles = updatedRoles)

Expand All @@ -97,20 +96,19 @@ constructor(
if (_selectedAssociation.value?.uid == associationId) {
_selectedAssociation.value = updatedAssociation
}

} else {
Log.e("AssociationViewModel", "Association with ID $associationId not found.")
}
}

/**
* Edits an existing role of a specified association in the local list. If the role is found,
* it is updated with the new role data. If the role doesn't exist, an error is logged.
* If the association is selected, it is also updated.
*
* @param associationId The ID of the association whose role needs to be edited.
* @param role The updated role to set.
*/
/**
* Edits an existing role of a specified association in the local list. If the role is found, it
* is updated with the new role data. If the role doesn't exist, an error is logged. If the
* association is selected, it is also updated.
*
* @param associationId The ID of the association whose role needs to be edited.
* @param role The updated role to set.
*/
fun editRoleLocally(associationId: String, role: Role) {

val association = _associations.value.find { it.uid == associationId }
Expand All @@ -133,19 +131,18 @@ constructor(
if (_selectedAssociation.value?.uid == associationId) {
_selectedAssociation.value = updatedAssociation
}

} else {
Log.e("AssociationViewModel", "Association with ID $associationId not found.")
}
}

/**
* Deletes the specified role from the association's local list of roles. If the role is found,
* it is removed from the association's roles. If the association is selected, it is updated.
*
* @param associationId The ID of the association from which the role will be deleted.
* @param role The role to delete.
*/
/**
* Deletes the specified role from the association's local list of roles. If the role is found, it
* is removed from the association's roles. If the association is selected, it is updated.
*
* @param associationId The ID of the association from which the role will be deleted.
* @param role The role to delete.
*/
fun deleteRoleLocally(associationId: String, role: Role) {
val association = _associations.value.find { it.uid == associationId }

Expand All @@ -167,7 +164,6 @@ constructor(
if (_selectedAssociation.value?.uid == associationId) {
_selectedAssociation.value = updatedAssociation
}

} else {
Log.e("AssociationViewModel", "Association with ID $associationId not found.")
}
Expand Down Expand Up @@ -222,11 +218,11 @@ constructor(
})
}

/**
* Refreshes the selected association by fetching the association and updating the selected
* association's details including events and members. If the association is not found,
* an error is logged.
*/
/**
* Refreshes the selected association by fetching the association and updating the selected
* association's details including events and members. If the association is not found, an error
* is logged.
*/
fun refreshAssociation() {
if (_selectedAssociation.value == null) {
return
Expand Down Expand Up @@ -330,7 +326,6 @@ constructor(
val selectedAssociation = _selectedAssociation.value
if (selectedAssociation != null) {
selectedAssociation.events.update(event)

} else {
Log.e("AssociationViewModel", "No association selected to add or edit event.")
}
Expand Down Expand Up @@ -391,14 +386,14 @@ constructor(
}
}

/**
* Adds a new role to the selected association. If the role already exists, an error is triggered.
* After adding the role, the association is saved and the local state is updated.
*
* @param role The role to be added to the association.
* @param onSuccess A callback function to be executed after the role is successfully added.
* @param onFailure A callback function to handle errors during the operation.
*/
/**
* Adds a new role to the selected association. If the role already exists, an error is triggered.
* After adding the role, the association is saved and the local state is updated.
*
* @param role The role to be added to the association.
* @param onSuccess A callback function to be executed after the role is successfully added.
* @param onFailure A callback function to handle errors during the operation.
*/
fun addRole(role: Role, onSuccess: () -> Unit, onFailure: (Exception) -> Unit) {
val currentAssociation = _selectedAssociation.value
if (currentAssociation == null) {
Expand Down Expand Up @@ -426,14 +421,14 @@ constructor(
onFailure = onFailure)
}

/**
* Removes the specified role from the selected association. If the role does not exist,
* an error is triggered. After removing the role, the association is saved and the local state is updated.
*
* @param role The role to be removed from the association.
* @param onSuccess A callback function to be executed after the role is successfully removed.
* @param onFailure A callback function to handle errors during the operation.
*/
/**
* Removes the specified role from the selected association. If the role does not exist, an error
* is triggered. After removing the role, the association is saved and the local state is updated.
*
* @param role The role to be removed from the association.
* @param onSuccess A callback function to be executed after the role is successfully removed.
* @param onFailure A callback function to handle errors during the operation.
*/
fun removeRole(role: Role, onSuccess: () -> Unit, onFailure: (Exception) -> Unit) {
val currentAssociation = _selectedAssociation.value
if (currentAssociation == null) {
Expand Down
26 changes: 15 additions & 11 deletions app/src/main/java/com/android/unio/model/event/EventViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,21 @@ constructor(
_events.value += event
}

/**
* Adds an image to the specified event. This method uploads the image to the storage and updates
* the event's image URL once the upload is successful.
*
* This method helps in associating an image with an event, allowing the event to display a visual representation.
*
* @param inputStream The input stream of the image to upload. This is typically the raw data of the image selected by the user.
* @param event The event to which the image will be added.
* @param onSuccess A callback that is triggered if the image upload and event update are successful. It passes the updated event as a parameter.
* @param onFailure A callback that is triggered if the image upload or event update fails. It passes the error that occurred as a parameter.
*/
/**
* Adds an image to the specified event. This method uploads the image to the storage and updates
* the event's image URL once the upload is successful.
*
* This method helps in associating an image with an event, allowing the event to display a visual
* representation.
*
* @param inputStream The input stream of the image to upload. This is typically the raw data of
* the image selected by the user.
* @param event The event to which the image will be added.
* @param onSuccess A callback that is triggered if the image upload and event update are
* successful. It passes the updated event as a parameter.
* @param onFailure A callback that is triggered if the image upload or event update fails. It
* passes the error that occurred as a parameter.
*/
fun addImageToEvent(
inputStream: InputStream,
event: Event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import java.text.SimpleDateFormat
import java.util.Locale
import java.util.TimeZone


/**
* Retrieves the current user's token ID asynchronously.
*
* This function checks if the current user is signed in, and if so, retrieves their Firebase token ID.
* If the user is not signed in, or if there is an issue fetching the token, the `onError` callback is called.
* Otherwise, the `onSuccess` callback is invoked with the token ID.
* This function checks if the current user is signed in, and if so, retrieves their Firebase token
* ID. If the user is not signed in, or if there is an issue fetching the token, the `onError`
* callback is called. Otherwise, the `onSuccess` callback is invoked with the token ID.
*
* @param onSuccess A callback function that is called when the token ID is successfully retrieved.
* @param onError A callback function that is called if an error occurs while retrieving the token ID.
* @param onError A callback function that is called if an error occurs while retrieving the token
* ID.
* @throws Exception If the user is not signed in or token retrieval fails.
*/
private fun giveCurrentUserTokenID(onSuccess: (String) -> Unit, onError: (Exception) -> Unit) {
Expand All @@ -47,8 +47,8 @@ private fun giveCurrentUserTokenID(onSuccess: (String) -> Unit, onError: (Except
/**
* Converts a Firebase [Timestamp] object to a formatted string in ISO 8601 format.
*
* This function takes a [Timestamp] object and converts it to a string formatted as "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'".
* It ensures the timestamp is in UTC time zone.
* This function takes a [Timestamp] object and converts it to a string formatted as
* "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'". It ensures the timestamp is in UTC time zone.
*
* @param timestamp The Firebase [Timestamp] to be converted.
* @return A string representation of the timestamp in ISO 8601 format.
Expand All @@ -62,15 +62,18 @@ fun convertTimestampToString(timestamp: Timestamp): String {
/**
* Adds or edits an event by calling a Firebase Cloud Function to save the event.
*
* This function uploads event details to a Firebase Cloud Function, including the event information and associated data.
* Depending on whether it is a new event or an update, the appropriate action is taken.
* It retrieves the current user's token ID and sends it to the Cloud Function, along with the event data.
* This function uploads event details to a Firebase Cloud Function, including the event information
* and associated data. Depending on whether it is a new event or an update, the appropriate action
* is taken. It retrieves the current user's token ID and sends it to the Cloud Function, along with
* the event data.
*
* @param newEvent The event object to be added or updated.
* @param associationUId The unique identifier of the association to which the event belongs.
* @param onSuccess A callback function that is called when the event is successfully added or updated.
* @param onSuccess A callback function that is called when the event is successfully added or
* updated.
* @param onError A callback function that is called if an error occurs during the process.
* @param isNewEvent A boolean value indicating whether the event is new (true) or being edited (false).
* @param isNewEvent A boolean value indicating whether the event is new (true) or being edited
* (false).
*/
fun addEditEventCloudFunction(
newEvent: Event,
Expand All @@ -82,7 +85,6 @@ fun addEditEventCloudFunction(
try {
giveCurrentUserTokenID(
onSuccess = { tokenId ->

Firebase.functions
.getHttpsCallable("saveEvent")
.call(
Expand Down Expand Up @@ -134,14 +136,17 @@ fun addEditEventCloudFunction(
/**
* Adds or edits a role by calling a Firebase Cloud Function to save the role.
*
* This function uploads role details to a Firebase Cloud Function, including role-specific information
* and permissions. It retrieves the current user's token ID and sends it to the Cloud Function, along with the role data.
* This function uploads role details to a Firebase Cloud Function, including role-specific
* information and permissions. It retrieves the current user's token ID and sends it to the Cloud
* Function, along with the role data.
*
* @param newRole The role object to be added or updated.
* @param associationUId The unique identifier of the association to which the role belongs.
* @param onSuccess A callback function that is called when the role is successfully added or updated.
* @param onSuccess A callback function that is called when the role is successfully added or
* updated.
* @param onError A callback function that is called if an error occurs during the process.
* @param isNewRole A boolean value indicating whether the role is new (true) or being edited (false).
* @param isNewRole A boolean value indicating whether the role is new (true) or being edited
* (false).
*/
fun addEditRoleCloudFunction(
newRole: Role,
Expand All @@ -153,7 +158,6 @@ fun addEditRoleCloudFunction(
try {
giveCurrentUserTokenID(
onSuccess = { tokenId ->

Firebase.functions
.getHttpsCallable("saveRole")
.call(
Expand Down
46 changes: 21 additions & 25 deletions app/src/main/java/com/android/unio/model/search/SearchRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ constructor(

// Add the fresh set of associations to AppSearch
session?.putAsync(PutDocumentsRequest.Builder().addDocuments(associationDocuments).build())

} catch (e: Exception) {
Log.e("SearchRepository", "Failed to refresh associations in AppSearch", e)
}
Expand All @@ -112,9 +111,7 @@ constructor(
*/
fun fetchAssociations() {
associationRepository.getAssociations(
onSuccess = { associations ->
addAssociations(associations)
},
onSuccess = { associations -> addAssociations(associations) },
onFailure = { exception ->
Log.e("SearchRepository", "failed to fetch associations", exception)
})
Expand Down Expand Up @@ -160,12 +157,12 @@ constructor(
}
}

/**
* Extracts and adds the members from the given list of [Association] objects to the search database.
* Each member is associated with their respective association.
*
* @param associations The list of [Association] objects to extract members from.
*/
/**
* Extracts and adds the members from the given list of [Association] objects to the search
* database. Each member is associated with their respective association.
*
* @param associations The list of [Association] objects to extract members from.
*/
private fun addMembersFromAssociations(associations: List<Association>) {
val memberDocuments =
associations.flatMap { association ->
Expand All @@ -174,8 +171,7 @@ constructor(
uid = member.uid,
userUid = member.user.uid,
role = (association.roles.find { it.uid == member.uid }?.displayName ?: ""),
associationUid = association.uid
)
associationUid = association.uid)
}
}
try {
Expand Down Expand Up @@ -250,12 +246,12 @@ constructor(
}
}

/**
* Searches the search database for members that match the given query.
*
* @param query The search query to look for in the database.
* @return A list of [Member] objects that match the search query.
*/
/**
* Searches the search database for members that match the given query.
*
* @param query The search query to look for in the database.
* @return A list of [Member] objects that match the search query.
*/
suspend fun searchMembers(query: String): List<Member> {
return withContext(Dispatchers.IO) {
val searchSpec =
Expand Down Expand Up @@ -332,13 +328,13 @@ constructor(
}
}

/**
* Converts the given [MemberDocument] to a [Member] object.
* This method fetches the full member details using the [AssociationRepository].
*
* @param memberDocument The [MemberDocument] to convert.
* @return The corresponding [Member] object.
*/
/**
* Converts the given [MemberDocument] to a [Member] object. This method fetches the full member
* details using the [AssociationRepository].
*
* @param memberDocument The [MemberDocument] to convert.
* @return The corresponding [Member] object.
*/
private suspend fun memberDocumentToMember(memberDocument: MemberDocument): Member {
return suspendCoroutine { continuation ->
associationRepository.getAssociationWithId(
Expand Down
Loading

0 comments on commit 9e40150

Please sign in to comment.