Skip to content

Fix hash ID decoding in playlist contents and grant request bodies#757

Merged
rickyrombo merged 4 commits intomainfrom
mjp-fix-hashid-decoding-write-endpoints
Apr 8, 2026
Merged

Fix hash ID decoding in playlist contents and grant request bodies#757
rickyrombo merged 4 commits intomainfrom
mjp-fix-hashid-decoding-write-endpoints

Conversation

@rickyrombo
Copy link
Copy Markdown
Contributor

@rickyrombo rickyrombo commented Apr 8, 2026

Summary

  • Adds trashid.IntId type: accepts hash IDs or raw ints on JSON input, always marshals as a plain integer. Designed for chain metadata fields where the indexer expects numeric IDs.
  • PlaylistTrackInfo.TrackId (stringtrashid.IntId): playlist_contents track IDs are now decoded at the API boundary. Previously hash ID strings were forwarded raw to chain, requiring an indexer workaround.
  • addManagerBody.ManagerUserId (stringtrashid.HashId): removes redundant manual DecodeHashId call, adds struct tag validation
  • approveGrantBody.GrantorUserId (stringtrashid.HashId): removes redundant manual DecodeHashId call, adds struct tag validation

Test plan

  • POST /v1/playlists with hash ID track IDs in playlist_contents — verify chain metadata contains int IDs
  • POST /v1/playlists with raw int track IDs in playlist_contents — verify still works (backward compat)
  • POST /v1/users/:id/managers with hash ID manager_user_id — verify grant created
  • POST /v1/users/:id/managers with missing/zero manager_user_id — verify 400
  • POST /v1/users/:id/approve-grant with hash ID grantor_user_id — verify grant approved
  • POST /v1/users/:id/approve-grant with missing/zero grantor_user_id — verify 400
  • Unit tests for trashid.IntId marshal/unmarshal round-trip

🤖 Generated with Claude Code

- Add trashid.IntId type: decodes hash IDs on input, marshals as plain
  int — for chain metadata where the indexer expects numeric IDs
- PlaylistTrackInfo.TrackId: string → trashid.IntId so playlist_contents
  track IDs are decoded at the API boundary instead of forwarded raw
- addManagerBody.ManagerUserId: string → trashid.HashId (removes manual
  DecodeHashId call)
- approveGrantBody.GrantorUserId: string → trashid.HashId (removes
  manual DecodeHashId call)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates API request decoding so hash IDs are converted at the API boundary for playlist contents and grant-related request bodies, ensuring downstream chain/indexer metadata uses the expected numeric IDs.

Changes:

  • Introduces trashid.IntId to accept either hash IDs or raw integers on JSON input, while always marshaling as a JSON number.
  • Updates playlist playlist_contents[].track_id to use trashid.IntId so track IDs are emitted as integers in chain metadata.
  • Switches manager_user_id / grantor_user_id request fields to trashid.HashId, removing redundant manual decode calls.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
trashid/hashid.go Adds IntId JSON (un)marshal behavior to normalize IDs to integers for chain metadata.
api/v1_playlist.go Changes playlist contents track IDs to trashid.IntId so metadata contains numeric track_ids.
api/v1_grants.go Changes grant request bodies to typed hash IDs and removes manual decoding logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/AudiusProject/api/sessions/1e868cb7-009d-437d-a60f-b0b1a123b27c

Co-authored-by: rickyrombo <3690498+rickyrombo@users.noreply.github.com>
Copilot AI changed the title Fix hash ID decoding in playlist contents and grant request bodies Add unit tests for trashid.IntId Apr 8, 2026
Addresses PR feedback: adds validate:"required,min=1" struct tags to
ManagerUserId and GrantorUserId, and wires up requestValidator.Validate
calls so zero/missing values are rejected before hitting the DB or chain.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rickyrombo rickyrombo changed the title Add unit tests for trashid.IntId Fix hash ID decoding in playlist contents and grant request bodies Apr 8, 2026
@rickyrombo rickyrombo merged commit 6a45fac into main Apr 8, 2026
5 checks passed
@rickyrombo rickyrombo deleted the mjp-fix-hashid-decoding-write-endpoints branch April 8, 2026 22:40
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