Each User profile has a like counter that accumulates from all posts.
A user has 10 posts. For each like executed , it should update the post and the total likes on the user’s profile. They are in separate COLLECTIONS
Would I use relationships? This is my execution and is probably not effective.
executeLike(int postLikes, String profileId) async {
int newLikes = postLikes + 1;
//update post
var status = await _databases.updateDocument(
databaseId: '...',
collectionId: 'posts',
documentId: '...',
data: {'likes': newLikes});
//get userprofile
var profileData = await _databases.getDocument(
databaseId: '...', collectionId: 'public_profile', documentId: profileId);
int totalLikes = profileData.data['total_likes'];
int newTotalLikes = totalLikes + 1;
// update poster's total likes
await _databases.updateDocument(
databaseId: '...',
collectionId: 'public_profile',
documentId: profileId,
data: {'total_likes': newTotalLikes});
}
Recommended threads
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...
- Our Appwrite organization is suspended
Please give support regarding this , no app is working now , please solve my issue and give support , no one is replying in message section or email.
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...