Skip to content

Add apartment tag CRUD endpoints#415

Open
NigelTatem wants to merge 1 commit intocornell-dti:mainfrom
NigelTatem:tag-feature-backend
Open

Add apartment tag CRUD endpoints#415
NigelTatem wants to merge 1 commit intocornell-dti:mainfrom
NigelTatem:tag-feature-backend

Conversation

@NigelTatem
Copy link
Copy Markdown

Title

Apartment tags backend: create, attach/detach, and list

Summary

This PR introduces backend support for tagging apartments. A new tags collection is added in Firestore, and apartments (stored in buildings) now optionally reference tags by ID through a tags array on the document. The goal was to add a reusable Tag entity and minimal endpoints to support creating tags and managing their association with apartments.

Tags are stored with both a name and a normalizedName (trimmed and lowercased) to enforce uniqueness at the application level. Creating a tag with the same normalized name returns the existing tag rather than inserting a duplicate. Apartments attach and detach tag IDs idempotently, meaning repeated operations do not create duplicates or cause errors.

The following endpoints were added:

POST /api/tags to create or return an existing tag

GET /api/apts/:id/tags to list resolved tag objects for an apartment

POST /api/apts/:id/tags/:tagId to attach a tag

DELETE /api/apts/:id/tags/:tagId to detach a tag

Reads tolerate dangling references by skipping missing tag documents rather than failing.

Emulator-compatible initialization was added for test runs so Firebase Admin can run without a service account when NODE_ENV=test or FIRESTORE_EMULATOR_HOST is set. A Tags test suite was added using the Firestore emulator and Supertest to verify tag creation/deduplication, idempotent attach/detach behavior, and correct listing. All backend tests pass locally with yarn workspace backend test.

This PR does not include frontend work, tag-based filtering, authentication changes, or transactional protections against concurrent writes. Tag uniqueness and tag-array updates are currently enforced at the application level rather than through Firestore transactions.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown

@laurenp-2 laurenp-2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really clean PR! The new tag API endpoints align well with the existing project structure and API patterns, and the code is very readable. One small suggestion would be to add more specific error handling in the API calls bc right now everything is wrapped in a catch that returns a general 400 error, so more granular responses could help with debugging and UX. Overall, this looks great. Can’t wait to see how the feature turns out!

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 this pull request may close these issues.

3 participants