Skip to content

Tagging system for snippets#93

Open
AgilityB wants to merge 2 commits into
SudiptaPaul-31:mainfrom
AgilityB:Tagging-System-for-Snippets
Open

Tagging system for snippets#93
AgilityB wants to merge 2 commits into
SudiptaPaul-31:mainfrom
AgilityB:Tagging-System-for-Snippets

Conversation

@AgilityB
Copy link
Copy Markdown

Tagging System for Snippets
Completes the tagging feature by adding tag discoverability. The core tagging system (DB column, validation, storage, and tag-based filtering) was already in place — this PR adds the missing piece that allows clients to know which tags exist.

Context
Tags were already fully wired through the stack:

tags jsonb column on the snippets table
Zod validation enforcing at least one tag on create
Repository search() filtering via tags @> jsonb
GET /api/snippets?tags=React,DSA already working
The gap was discoverability — no endpoint existed to list available tags, making it impossible to build a tag filter UI without hardcoding values.

What changed
snippet.repository.ts

Added findAllTags() — unnests the tags jsonb array across all non-deleted snippets using jsonb_array_elements_text, groups by tag, and returns each unique tag with its usage count ordered by popularity.

route.ts
(new file)

New GET /api/snippets/tags endpoint that calls findAllTags() and returns:

{
"tags": [
{ "tag": "React", "count": 12 },
{ "tag": "DSA", "count": 7 },
{ "tag": "API", "count": 4 }
],
"total": 3
}
Usage

Discover available tags

GET /api/snippets/tags

Filter snippets by one or more tags (already supported)

GET /api/snippets?tags=React,DSA
No migrations required
The tags column already exists. This PR only adds read logic on top of existing data.

Closes #43

AgilityB added 2 commits May 30, 2026 10:43
- Implement real Stellar SDK integration (submitHashToStellar,
  submitBatchHashToStellar) replacing mock stubs; embeds snippet
  created_at timestamp in on-chain memo for proof-of-existence
- Add DB functions: getSnippetWithHash, storeSnippetHash (immutable,
  rejects overwrites), verifySnippetIntegrity, getVerifiedSnippets
- Update POST /api/snippets/[id]/verify to anchor creation timestamp
  on-chain; return 409 if already verified
- Add migration script for on_chain_hash, transaction_hash, verified_at
  columns with indexes
- Add GET /api/snippets/tags returning all unique tags with usage counts
- Add findAllTags() to SnippetRepository using jsonb_array_elements_text
  to unnest tags array and aggregate counts per tag
@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

@AgilityB is attempting to deploy a commit to the Sudipta 's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Tagging System for Snippets

1 participant