project-standalo-sonic-cloud/.workflow/versions/v004/contexts/api_create_song_share.yml

132 lines
3.6 KiB
YAML

task_id: task_create_api_create_song_share
entity_id: api_create_song_share
generated_at: '2025-12-18T18:15:12.903532'
workflow_version: v004
target:
type: api
definition:
id: api_create_song_share
method: POST
path: /api/share/song/[id]
description: Generate share link for a song
auth:
required: false
description: No authentication required to share content
request_params:
- name: id
type: string
location: path
required: true
description: Song ID to generate share link for
request_body:
- name: platform
type: string
required: false
description: Platform being shared to (twitter, facebook, etc)
responses:
- status: 200
description: Share link created successfully
schema:
shareUrl: string
token: string
type: string
- status: 404
description: Song not found
schema:
error: string
business_logic:
- Verify song exists and is public
- Generate unique 10-character alphanumeric token
- Create Share record with type=SONG
- Return full share URL (https://domain.com/s/[token])
depends_on_models:
- model_share
related:
models:
- id: model_share
definition: &id001
id: model_share
name: Share
table_name: shares
description: Tracks shared content links with analytics
primary_key: id
fields:
- name: id
type: String
constraints:
- primary_key
- cuid
description: Unique identifier for the share
- name: type
type: ShareType
constraints:
- required
description: Type of content being shared (SONG, PLAYLIST, ALBUM)
- name: targetId
type: String
constraints:
- required
description: ID of the shared content (references songs/playlists/albums)
- name: token
type: String
constraints:
- required
- unique
description: Unique URL-safe token for share links
- name: userId
type: String
constraints:
- optional
description: User who created the share (null for anonymous shares)
- name: platform
type: String
constraints:
- optional
description: Platform where content was shared to (twitter, facebook, etc)
- name: clickCount
type: Int
default: 0
description: Number of times the share link was clicked
- name: createdAt
type: DateTime
default: now()
description: Timestamp when the share was created
relations: []
indexes:
- fields:
- token
unique: true
description: Fast lookup by share token
- fields:
- targetId
- type
description: Fast lookup of shares for specific content
timestamps: false
validations:
- field: token
rule: minLength(8)
message: Token must be at least 8 characters
- field: type
rule: enum(SONG, PLAYLIST, ALBUM)
message: Type must be SONG, PLAYLIST, or ALBUM
apis: []
components: []
dependencies:
entity_ids:
- model_share
definitions:
- id: model_share
type: model
definition: *id001
files:
to_create:
- app/api/share/song/[id]/route.ts
reference: []
acceptance:
- criterion: POST /api/share/song/[id] returns success response
verification: curl -X POST /api/share/song/[id]
- criterion: Request validation implemented
verification: Test with invalid data
- criterion: Error responses match contract
verification: Test error scenarios