forked from fterdal/Capstone-1-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
- Define Sequelize model/controller logic (if not already)
- Create backend route: POST /api/listening-sessions
- Accept payload from the front end:
{
"spotifyTrackId": "123abc",
"title": "Song Name",
"artist": "Artist Name",
"preview_url": "...",
"image_url": "...",
"lat": 40.7128,
"lng": -74.0060,
"timestamp": "optional" // if not sent, use current date
}
In controller/ also known as the Logic of the endpoint:
- Use userId from req.user.id (via JWT)
- Check if the song already exists in Songs table (via spotifyTrackId)
- If not, create it - Save ListeningSession with user_id, song_id, lat, lng, and timestamp
This creates a new entry in our ListeningSessions table that ties:
- the user
- the song
- the location
- the time
The app triggers this request after the user logs in, and you’ve collected:
- their geolocation
- their currently playing or recently played track
Remember we have 2 separate tables:
Songs — a master list of unique songs (one row per track)
ListeningSessions — every time a user listens to a track
This is why we always check if the song exist in our Song Table .. we want to avoid having duplicates.
Tip:
- Get the user’s ID
2.Check if the song exists - If not, create the song
- Create the listening session
- send payload back to the front end :
{
"message": "Listening session saved",
"song": {
"title": "City of Gods",
"artist": "Fivio Foreign",
"preview_url": "...",
"image_url": "..."
},
"session": {
"lat": 40.7527,
"lng": -73.9772,
"timestamp": "2025-07-31T00:00:00.000Z"
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels