From 069a3deb7cd7f80fa2823c67095ce094ad05e76e Mon Sep 17 00:00:00 2001 From: Andres Date: Thu, 18 Apr 2024 21:54:02 +0200 Subject: [PATCH] chore: add episodes endpoint to podcasts service, add types --- src/services/podcasts/podcasts.service.ts | 21 +++++++++- src/services/podcasts/podcasts.types.ts | 48 ++++++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/services/podcasts/podcasts.service.ts b/src/services/podcasts/podcasts.service.ts index a498189..a101b1b 100644 --- a/src/services/podcasts/podcasts.service.ts +++ b/src/services/podcasts/podcasts.service.ts @@ -1,4 +1,4 @@ -import { TopPodcastsResponse } from "./podcasts.types"; +import { GetEpisodesResponse, GetTopPodcastsResponse } from "./podcasts.types"; import { PodcastDTO } from "./podcast.dto"; class PodcastsService { @@ -8,10 +8,27 @@ class PodcastsService { const response = await fetch( `${this.baseUrl}/us/rss/toppodcasts/limit=100/genre=1310/json`, ); - const data: TopPodcastsResponse = await response.json(); + const data: GetTopPodcastsResponse = await response.json(); return data.feed.entry.map((podcast) => new PodcastDTO(podcast)); } + + async getEpisodesByPodcastId(podcastId: string) { + const url = new URL(`${this.baseUrl}/lookup`); + const params = { + id: podcastId, + media: "podcast", + entity: "podcastEpisode", + limit: "20", + }; + url.search = new URLSearchParams(params).toString(); + + const response = await fetch(url); + const data: GetEpisodesResponse = await response.json(); + + //TODO: add dto + return data; + } } export const podcastsService = new PodcastsService(); diff --git a/src/services/podcasts/podcasts.types.ts b/src/services/podcasts/podcasts.types.ts index 43c1c32..94f02d0 100644 --- a/src/services/podcasts/podcasts.types.ts +++ b/src/services/podcasts/podcasts.types.ts @@ -1,4 +1,4 @@ -export interface TopPodcastsResponse { +export interface GetTopPodcastsResponse { feed: Feed; } @@ -162,3 +162,49 @@ export interface Attributes9 { export interface Id2 { label: string; } + +export interface GetEpisodesResponse { + resultCount: number; + results: PodcastDetails[]; +} + +export interface PodcastDetails { + wrapperType: string; + kind: string; + collectionId: number; + trackId: number; + artistName?: string; + collectionName: string; + trackName: string; + collectionCensoredName?: string; + trackCensoredName?: string; + collectionViewUrl: string; + feedUrl: string; + trackViewUrl: string; + artworkUrl30?: string; + artworkUrl60: string; + artworkUrl100?: string; + collectionPrice?: number; + trackPrice?: number; + collectionHdPrice?: number; + releaseDate: string; + collectionExplicitness?: string; + trackExplicitness?: string; + trackCount?: number; + trackTimeMillis: number; + country: string; + currency?: string; + primaryGenreName?: string; + contentAdvisoryRating: string; + artworkUrl600: string; + genreIds?: string[]; + closedCaptioning?: string; + shortDescription?: string; + episodeUrl?: string; + episodeGuid?: string; + description?: string; + artworkUrl160?: string; + episodeContentType?: string; + episodeFileExtension?: string; + previewUrl?: string; +}