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

Add Update Functionality for Collections #33

Open
mathewmorris opened this issue Dec 29, 2024 · 3 comments · May be fixed by #51
Open

Add Update Functionality for Collections #33

mathewmorris opened this issue Dec 29, 2024 · 3 comments · May be fixed by #51
Assignees

Comments

@mathewmorris
Copy link
Owner

Implement the functionality to update an existing collection. This includes both frontend UI changes and backend API updates to support editing a collection's details. For now, focus on the name and cards fields. Validation logic should be added to ensure updated data is correct and meaningful, but collection names will not be required to be unique for the MVP.

Requirements:

Frontend:
  1. UI Update Form:

    • Create a modal or dedicated page where users can edit a collection.
    • Include input fields for:
      • name: A text input field for the collection name.
      • cards: A multi-select or autocomplete dropdown to manage associated cards.
  2. Form Validation:

    • Ensure the name field is not empty and does not exceed a reasonable character limit (e.g., 50 characters).
    • Validate the cards field to ensure valid card data is submitted.
  3. Submit Changes:

    • Add a button to submit the updated data.
    • Show a loading state and handle success/error notifications.
Backend:
  1. Update API Endpoint:

    • Create or update the tRPC handler for updating collections.
    • Accept and validate name and cards fields from the request.
  2. Validation Logic:

    • Ensure the name field is a valid string and not empty.
    • Ensure the cards field contains valid card IDs (if applicable).
  3. Database Update:

    • Use Prisma to update the collection record:
      const updatedCollection = await prisma.collection.update({
        where: { id: collectionId },
        data: {
          name: newName,
          cards: { set: newCardIds },
        },
      });
    • Note: Prisma automatically handles updating the updatedAt field when configured in the schema.
  4. Error Handling:

    • Handle cases where the collection ID is invalid or the user does not have permission to edit the collection.

Testing:

  • Write unit tests for the backend API to ensure updates are processed correctly.
  • Add frontend tests for form validation and submission workflows.
  • Perform manual testing to confirm end-to-end functionality.

Acceptance Criteria:

  • Users can open an update form, make changes to a collection’s name and cards, and submit them.
  • Updated data is reflected in the database and frontend.
  • Proper error messages are displayed for invalid input or server errors.
  • The updatedAt field is updated automatically whenever a collection is modified.
@mathewmorris mathewmorris moved this to Todo in Magic Vault Dec 29, 2024
@mathewmorris mathewmorris moved this from Todo to Backlog in Magic Vault Dec 29, 2024
@mathewmorris mathewmorris added this to the MVP Completion milestone Dec 29, 2024
@mathewmorris mathewmorris moved this from Backlog to To Do in Magic Vault Dec 29, 2024
@mathewmorris mathewmorris self-assigned this Dec 29, 2024
@mathewmorris mathewmorris moved this from To Do to In Progress in Magic Vault Jan 12, 2025
@mathewmorris mathewmorris linked a pull request Jan 17, 2025 that will close this issue
@mathewmorris
Copy link
Owner Author

This changed a ton.

So, instead of storing a list of strings in a field on the Collection table, I created a join table to store data about the relation and reduce the amount of data that needs to be sent across the network.

There will only ever be one card id to one collection, with a count of how many of this card there are in the collection. When there are none, the relation is removed.

@mathewmorris
Copy link
Owner Author

Some known issues:

  • When updating card counts, the order is changed. It looks like the most recently updated is last. Under the hood, I'm using a Map which stores items in the same order they were added. There might be something going on in the parsing of data from the backend after a mutation. I wonder if we can get the right order before it gets to the frontend?
  • When reloading the page on collections/, you lose the collection information. Nothing is fetched on the first load. I know we're using the router to grab the id and then fetch the collection, but the fetch doesn't happen at all. Seems like it should, but I'll have to do some testing and reading to figure out what exactly is going on.

@mathewmorris
Copy link
Owner Author

prisma.schema

model Card {
  id: uuid
}
model Collection {
  id: uuid
}
model CardsOnCollections {
  cardId: string
  collectionId: string
  @@id([collectionId, cardId])
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

1 participant