forked from fterdal/Capstone-1-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Open
Copy link
Description
- Create a POST endpoint at /auth/spotify/ai-playlist to receive user prompts from the frontend.
2. Prompt Validation
- Validate the incoming prompt:
- If prompt is too short or not music-related (eexample "hi"), return a friendly message suggesting the user send a mood, genre, or vibe.
3. Gemini AI Integration
- Send valid prompts to Gemini AI.
- Parse Gemini’s response to extract a JSON list of
{ song, artist }pairs.
4. Output Validation
- Validate Gemini’s output:
- If output is invalid or empty, return a fallback message to the frontend.
5. Spotify Track Search
- For each
{ song, artist }from Gemini, search Spotify’s API for matching track IDs. - Collect valid Spotify track URIs.
6. Playlist Creation
- Use the authenticated user’s Spotify token to create a new playlist named
AI Playlist: [prompt]. - Add the collected tracks to the playlist via Spotify API.
7. Response Handling
- If playlist creation is successful, return
{ playlistUrl: "https://open.spotify.com/playlist/..." }. - If prompt is invalid or playlist creation fails, return
{ message: "Send a mood, genre, or vibe and I can make a playlist for you." }.
8. Error Handling & Logging
- Log errors at each step for debugging.
- Return appropriate error messages to the frontend.
Reactions are currently unavailable