Skip to content

Commit

Permalink
feat: make everything work
Browse files Browse the repository at this point in the history
  • Loading branch information
armouldr committed Dec 20, 2024
1 parent 4faf7e1 commit 51b3cb1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
47 changes: 28 additions & 19 deletions app/src/main/java/com/android/unio/model/event/EventViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,32 @@ constructor(
* @param onSuccess A callback that is called when the event is successfully updated.
* @param onFailure A callback that is called when an error occurs while updating the event.
*/
fun updateEventWithoutImage(event: Event, onSuccess: () -> Unit, onFailure: (Exception) -> Unit) {
fun updateEventWithoutImage(
event: Event,
onSuccess: () -> Unit,
onFailure: (Exception) -> Unit,
updateAssociation: Boolean = true
) {
repository.addEvent(event, onSuccess, onFailure)

event.organisers.requestAll(
{
event.organisers.list.value.forEach {
if (it.events.contains(event.uid)) it.events.remove(event.uid)
it.events.add(event.uid)
associationRepository.saveAssociation(
isNewAssociation = false,
it,
{},
{ e ->
Log.e("EventViewModel", "An error occurred while loading associations: $e")
})
it.events.requestAll()
}
},
lazy = true)
if (updateAssociation) {
event.organisers.requestAll(
{
event.organisers.list.value.forEach {
if (it.events.contains(event.uid)) it.events.remove(event.uid)
it.events.add(event.uid)
associationRepository.saveAssociation(
isNewAssociation = false,
it,
{},
{ e ->
Log.e("EventViewModel", "An error occurred while loading associations: $e")
})
it.events.requestAll()
}
},
lazy = true)
}

_events.value = _events.value.filter { it.uid != event.uid } // Remove the outdated event
_events.value += event
Expand Down Expand Up @@ -325,7 +332,8 @@ constructor(
{ onSuccess() },
{ e ->
Log.e("EventViewModel", "An error occurred while updating an event: $e")
})
},
false)
},
{ e ->
onFailure(e)
Expand Down Expand Up @@ -362,7 +370,8 @@ constructor(
{ e ->
onFailure(e)
Log.e("EventViewModel", "An error occurred while updating an event: $e")
})
},
false)
},
{ e ->
onFailure(e)
Expand Down
7 changes: 1 addition & 6 deletions firebase/tests/firestore-rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,7 @@ async function runTests(testEnv) {
uid: "new-association",
})
);
/*await assertSucceeds(
updateDoc(doc(aliceDb, `/associations/${aliceAssociation.uid}`), {
...aliceAssociation,
name: "New name",
})
);*/

await assertSucceeds(
updateDoc(doc(aliceDb, `/associations/${otherAssociation.uid}`), {
...otherAssociation,
Expand Down
6 changes: 3 additions & 3 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ service cloud.firestore {

match /associations/{uid} {
function isMember() {
let members = get(/databases/$(database)/documents/associations/$(uid)).data.get(members, null);
let members = get(/databases/$(database)/documents/associations/$(uid)).data.get("members", null);
return (members != null) && members.keys().hasAny([request.auth.uid]);
}
function onlyUpdatedFollowerCount() {
Expand Down Expand Up @@ -176,8 +176,8 @@ service cloud.firestore {

let affectedKeys = request.resource.data.diff(resource.data).affectedKeys();

let onlySavedCountChanged = affectedKeys.hasOnly(['numberOfSaved']);
return onlySavedCountChanged && (newCount == oldCount || newCount == oldCount + 1 || newCount == oldCount - 1);
let onlySavedCountChanged = affectedKeys.hasOnly(["numberOfSaved"]);
return onlySavedCountChanged && newCount != null && oldCount != null;
}

function validate() {
Expand Down

0 comments on commit 51b3cb1

Please sign in to comment.