-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { RESTDataSource } from "@apollo/datasource-rest"; | ||
import { Playlist } from "../types"; | ||
import { PlaylistModel } from "../models"; | ||
|
||
export class SpotifyAPI extends RESTDataSource { | ||
baseURL = "https://spotify-demo-api-fe224840a08c.herokuapp.com/v1/"; | ||
|
||
async getFeaturedPlaylists(): Promise<Playlist[]> { | ||
async getFeaturedPlaylists(): Promise<PlaylistModel[]> { | ||
const response = await this.get<{ | ||
playlists: { | ||
items: Playlist[] | ||
items: PlaylistModel[] | ||
} | ||
}>("browse/featured-playlists"); | ||
return response?.playlists?.items ?? []; | ||
} | ||
|
||
getPlaylist(playlistId: string): Promise<Playlist> { | ||
getPlaylist(playlistId: string): Promise<PlaylistModel> { | ||
return this.get(`playlists/${playlistId}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Represents a playlist object returned by the REST API | ||
export type PlaylistModel = { | ||
id: string; | ||
name: string; | ||
description: string; | ||
tracks: { | ||
items: { | ||
track: TrackModel | ||
}[]; | ||
} | ||
}; | ||
|
||
export type TrackModel = { | ||
id: string; | ||
name: string; | ||
duration_ms: number; | ||
explicit: boolean; | ||
uri: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters