[Week7 - pky] Task3: Add Tag model with many-to-many Note relationship#55
Open
kunyoungp wants to merge 1 commit into
Open
[Week7 - pky] Task3: Add Tag model with many-to-many Note relationship#55kunyoungp wants to merge 1 commit into
kunyoungp wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tagmodel (id, name String(50) unique, timestamps) andnote_tagsassociation tableNote.tags↔Tag.noteswithlazy="selectin"and CASCADE deletesTagCreate,TagReadschemas; updatedNoteReadto includetags: list[TagRead] = []tagsrouter:GET /tags/,POST /tags/(201, 409 on duplicate),DELETE /tags/{tag_id}(204, 404)POST /notes/{note_id}/tags/{tag_id}(idempotent attach),DELETE /notes/{note_id}/tags/{tag_id}(detach)main.pyseed.sqlwithtagsandnote_tagsCREATE TABLE statementsTest plan
test_create_and_list_tags— create and list tagstest_create_duplicate_tag_returns_409— duplicate name returns 409test_delete_tag— delete returns 204test_delete_tag_not_found— delete non-existent returns 404test_attach_tag_to_note— attach tag, verify in responsetest_attach_tag_idempotent— attaching twice results in single tagtest_detach_tag_from_note— detach tag, verify removedtest_note_read_includes_tags— GET note includes tags fieldtest_cascade_delete_tag_cleans_note_tags— deleting tag removes from note associationsmake test)Notable tradeoffs
lazy="selectin"eagerly loads tags with notes (avoids N+1 but adds overhead for tag-less queries)IntegrityErrorcatch rather than pre-check query🤖 Generated with Claude Code