Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Post ID in User Model's Attribute posts Whenever a User Posts Something #146

Closed
Alpha17-2 opened this issue May 26, 2024 · 0 comments · Fixed by #147
Closed

Save Post ID in User Model's Attribute posts Whenever a User Posts Something #146

Alpha17-2 opened this issue May 26, 2024 · 0 comments · Fixed by #147

Comments

@Alpha17-2
Copy link
Collaborator

Description

Implement functionality to save the post ID in the posts attribute of the user model whenever a user creates a new post. This ensures that each user maintains a list of their post IDs for easy reference and retrieval.

Requirements

  1. Update User Model:

    • Ensure the user model includes an attribute posts, which is an array to store post IDs.
  2. Save Post ID:

    • When a user creates a new post, the post ID should be added to the posts array of the user who created the post.
  3. Firestore Structure:

    • User Document: { userId: string, posts: array of post IDs, ...other attributes }
    • Post Document: { postId: string, userId: string, ...other attributes }

Implementation Steps

  1. Update User Model:

    • Modify the Firestore user document structure to include a posts array if not already present.
  2. Create Post and Update User Document:

    • Implement functionality to create a new post document in Firestore.
    • After creating the post, retrieve the post ID.
    • Add the post ID to the posts array in the corresponding user document.
  3. Ensure Atomicity:

    • Use Firestore transactions or batch writes to ensure that both the post creation and user document update occur atomically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant