Files
Lazuli/src/routes/api/users/[userId]/recommendations/+server.ts

19 lines
799 B
TypeScript
Raw Normal View History

2024-02-03 02:47:23 -05:00
import type { RequestHandler } from '@sveltejs/kit'
import { Connections } from '$lib/server/connections'
2024-02-03 02:47:23 -05:00
// This is temporary functionally for the sake of developing the app.
2024-02-04 01:01:37 -05:00
// In the future will implement more robust algorithm for offering recommendations
export const GET: RequestHandler = async ({ params }) => {
2024-02-18 00:01:54 -05:00
const userId = params.userId!
2024-02-03 02:47:23 -05:00
2024-04-03 23:28:38 -04:00
const recommendations: (Song | Album | Artist | Playlist)[] = []
for (const connection of Connections.getUserConnections(userId)) {
await connection
.getRecommendations()
.then((connectionRecommendations) => recommendations.push(...connectionRecommendations))
.catch((reason) => console.log(`Failed to fetch recommendations: ${reason}`))
2024-02-03 02:47:23 -05:00
}
2024-02-04 01:01:37 -05:00
return Response.json({ recommendations })
2024-02-03 02:47:23 -05:00
}