Угловой сервис фильмов с проблемой Firebase

# #angular #firebase #google-cloud-firestore

Вопрос:

Я пытаюсь получить данные из firebase, используя этот видеосервис.

В моей базе данных с названием коллекции фильмов содержатся следующие данные:

  export const MOVIES: any = {

    1: {
        id: 1,
        title: 'The Crown Hunters',
        season: 'Season 1',
        overview: 'Three Young Men were sent to search for a lost Crown, but unknown to them that the crown could only be recovered by unknown identity',
        poster_path: '/The_Crown_Hunters_SmallEpisode1',
        posterUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/SmartsSmallPoster/The_Crown_Hunters_SmallEpisode1.png',
        backdropUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/BigBackdrop/The_Crown_Hunters_BigPoster.jpg',
        adult: false,
        genre_ids: [
        21, 29, 31
      ],
        backdrop_path: '/The_Crown_Hunters_BigPoster.jpg',
        member_required: true,
        free: false,
        belongs_to_collection: 'movies',
        original_language: 'en',
        popularity: '225',
        vote_count: '3900',
        video: false,
        vote_average: '7.5',
        homepage: '',
        imdb_id: 'aef091076',
        credit_ids: ['52fe43c4c3a36847f806e20d', '52fe43c4c3a36847f806e21d', '52fe43c4c3a36847f806e22d', 
                    '52fe43c4c3a36847f806e23d', '52fe43c4c3a36847f806e24d', '52fe43c4c3a36847f806e25d',
                    '52fe43c4c3a36847f806e26d', '52fe43c4c3a36847f806e27d', '52fe43c4c3a36847f806e28d',
                    '52fe43c4c3a36847f806e29d', '52fe43c4c3a36847f806e30d', '52fe43c4c3a36847f806e31d',
                    '52fe43c4c3a36847f806e32d', '52fe43c4c3a36847f806e33d', '52fe43c4c3a36847f806e34d'  
       ],
       cast_ids: [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
       production_companies: '3smartsflix',
       production_countries: 'NG',
       runtime: '15',
       spoken_languages: 'en',
       status: 'Released',
       release_type: 2,
       category: 'now_playing',
       now_playing: true,
       upcoming: false,
       category_id: 85,
       tagline: 'Hunters Never Quit',
       file_path: '/3smarts-photo-backdrops',
       movieId: 55,
       recomend_id: '',
       categories: ['TRENDING'],
       seqNo: 0,
       url: 'the-journey-part1',
    },

    2: {
        id: 2,
        movieId: 55,
        title: 'The Crown Hunters',
        season: 'Season 1',
        episode: 'Episode 2',
        episode_title: 'Episode Title: The Journey Part II',
        overview: 'Three Young Men were sent to search for a lost Crown, but unknown to them that the crown could only be recovered by unknown identity',
        poster_path: '/The_Crown_Hunters_SmallEpisode2',
        posterUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/SmartsSmallPoster/The_Crown_Hunters_SmallEpisode2.png',
        backdropUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/BigBackdrop/The_Crown_Hunters_BigPoster.jpg',
        adult: false,
        release_date: '21st August, 2021',
        genre_ids: [
        21, 29, 31
      ],
       backdrop_path: '/The_Crown_Hunters_BigPoster.jpg',
       member_required: true,
       free: false,
       belongs_to_collection: null,
       original_language: 'en',
       popularity: null,
       vote_count: '4200',
       video: false,
       vote_average: '7.7',
       homepage: '',
       imdb_id: 'aef091076',
       credit_ids: ['52fe43c4c3a36847f806e20d', '52fe43c4c3a36847f806e21d', '52fe43c4c3a36847f806e22d', 
                    '52fe43c4c3a36847f806e23d', '52fe43c4c3a36847f806e24d', '52fe43c4c3a36847f806e25d',
                    '52fe43c4c3a36847f806e26d', '52fe43c4c3a36847f806e27d', '52fe43c4c3a36847f806e28d',
                    '52fe43c4c3a36847f806e29d', '52fe43c4c3a36847f806e30d', '52fe43c4c3a36847f806e31d',
                    '52fe43c4c3a36847f806e32d', '52fe43c4c3a36847f806e33d', '52fe43c4c3a36847f806e34d'  
       ],
       cast_ids: [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
       production_companies: '3smartsflix',
       production_countries: 'NG',
       runtime: '15',
       spoken_languages: 'en',
       status: 'Released',
       release_type: 2,
       category: 'now_playing',
       now_playing: true,
       upcoming: false,
       category_id: 85,
       tagline: 'Hunters Never Quit',
       file_path: '/3smarts-photo-backdrops',
       recomend_id: ['aef091076' ],
       categories: ['TRENDING'],
       seqNo: 2,
       url: 'the-journey-part2',
       backdrops: ''
    },

    3: {
        id: 3,
        movieId: 55,
        title: 'The Crown Hunters',
        season: 'Season 1',
        episode: 'Episode 3',
        episode_title: 'The Throne Part I',
        overview: 'Three Young Men were sent to search for a lost Crown, but unknown to them that the crown could only be recovered by unknown identity',
        poster_path: '/The_Crown_Hunters_SmallEpisode3',
        posterUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/SmartsSmallPoster/The_Crown_Hunters_SmallEpisode3.png',
        backdropUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/BigBackdrop/The_Crown_Hunters_BigPoster.jpg',
        adult: false,
        release_date: '1st Dec, 2021',
        genre_ids: [
        21, 29, 31
      ],
       backdrop_path: '/The_Crown_Hunters_BigPoster.jpg',
       member_required: true,
       free: false,
       belongs_to_collection: null,
       original_language: 'en',
       popularity: null,
       vote_count: '4300',
       video: false,
       vote_average: '7.8',
       homepage: '',
       imdb_id: 'aef091076',
       credit_ids: ['52fe43c4c3a36847f806e20d', '52fe43c4c3a36847f806e21d', '52fe43c4c3a36847f806e22d', 
                    '52fe43c4c3a36847f806e23d', '52fe43c4c3a36847f806e24d', '52fe43c4c3a36847f806e25d',
                    '52fe43c4c3a36847f806e26d', '52fe43c4c3a36847f806e27d', '52fe43c4c3a36847f806e28d',
                    '52fe43c4c3a36847f806e29d', '52fe43c4c3a36847f806e30d', '52fe43c4c3a36847f806e31d',
                    '52fe43c4c3a36847f806e32d', '52fe43c4c3a36847f806e33d', '52fe43c4c3a36847f806e34d'  
       ],
       cast_ids: [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
       production_companies: '3smartsflix',
       production_countries: 'NG',
       runtime: '15',
       spoken_languages: 'en',
       status: 'Released',
       release_type: 2,
       category: 'now_playing',
       now_playing: true,
       upcoming: false,
       category_id: 85,
       tagline: 'Hunters Never Quit',
       file_path: '/3smarts-photo-backdrops',
       recomend_id: [1, 2, 4 ],
       categories: ['TRENDING'],
       seqNo: 3,
       url: 'the-journey-part3',
    },

    4: {
        id: 4,
        movieId: 55,
        title: 'The Crown Hunters',
        season: 'Season 1',
        episode: 'Episode 4',
        episode_title: 'Episode Title: The Throne Part II',
        overview: 'Three Young Men were sent to search for a lost Crown, but unknown to them that the crown could only be recovered by unknown identity',
        poster_path: '/The_Crown_Hunters_SmallEpisode4',
        posterUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/SmartsSmallPoster/The_Crown_Hunters_SmallEpisode4.png',
        backdropUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/BigBackdrop/The_Crown_Hunters_BigPoster.jpg',
        adult: false,
        release_date: '15th Dec, 2021',
        genre_ids: [
        21, 29, 31
      ],
       backdrop_path: '/The_Crown_Hunters_BigPoster.jpg',
       member_required: true,
       free: false,
       belongs_to_collection: null,
       original_language: 'en',
       popularity: null,
       vote_count: '4400',
       video: false,
       vote_average: '7.9',
       homepage: '',
       imdb_id: 'aef091076',
       credit_ids: ['52fe43c4c3a36847f806e20d', '52fe43c4c3a36847f806e21d', '52fe43c4c3a36847f806e22d', 
                    '52fe43c4c3a36847f806e23d', '52fe43c4c3a36847f806e24d', '52fe43c4c3a36847f806e25d',
                    '52fe43c4c3a36847f806e26d', '52fe43c4c3a36847f806e27d', '52fe43c4c3a36847f806e28d',
                    '52fe43c4c3a36847f806e29d', '52fe43c4c3a36847f806e30d', '52fe43c4c3a36847f806e31d',
                    '52fe43c4c3a36847f806e32d', '52fe43c4c3a36847f806e33d', '52fe43c4c3a36847f806e34d'  
       ],
       cast_ids: [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
       production_companies: '3smartsflix',
       production_countries: 'NG',
       runtime: '15',
       spoken_languages: 'en',
       status: 'Released',
       release_type: 2,
       category: 'now_playing',
       now_playing: true,
       upcoming: false,
       category_id: 85,
       tagline: 'Hunters Never Quit',
       file_path: '/3smarts-photo-backdrops',
       recomend_id: [1, 2, 3 ],
       categories: ['TRENDING'],
       seqNo: 4,
       url: 'the-journey-part4',
    },

    5: {
        id: 5,
        movieId: 66,
        title: 'The Rich Master and The Donkeys',
        season: 'Season 1',
        episode: 'Episode 1',
        episode_title: 'Episode Title: The Man of Wisdom I',
        overview: 'The Donkeys thought thier minds are hidden but unknowing to them that it goes beyond the physical and that there is one who dwells among them and He knows and sees everything beyond the physical',
        poster_path: '/The_RichMaster_SmallEpisode1.png',
        posterUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/SmartsSmallPoster/The_RichMaster_SmallEpisode1.png',
        backdropUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/BigBackdrop/The_RichMaster_BigPoster.jpg',
        adult: false,
        release_date: '3rd March, 2022',
        genre_ids: [
        27, 28, 31
      ],
       backdrop_path: '/The_RichMaster_BigPoster.jpg',
       member_required: true,
       free: false,
       belongs_to_collection: null,
       original_language: 'en',
       popularity: 230,
       vote_count: '4300',
       video: false,
       vote_average: '8.1',
       homepage: '',
       imdb_id: 'aef091080',
       credit_ids: ['52fe43c4c3a36847f807y890', '52fe43c4c3a36847f808y891', '52fe43c4c3a36847f809y892', 
                    '52fe43c4c3a36847f801y893', '52fe43c4c3a36847f802y894', '52fe43c4c3a36847f803y895',
                    '52fe43c4c3a36847f804y896', '52fe43c4c3a36847f805y897', '52fe43c4c3a36847f806y898',
                    '52fe43c4c3a36847f801z899'
                      
       ],
       cast_ids: [
        20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
       production_companies: '3smartsflix',
       production_countries: 'NG',
       runtime: '15',
       spoken_languages: 'en',
       status: 'Upcoming',
       release_type: 3,
       category: 'upcoming',
       upcoming: true,
       now_playing: false,
       category_id: 86,
       tagline: 'Purge Your Mind To House The Goodluck',
       file_path: '/3smarts-photorichmaster-backdrops',
       recomend_id: [6, 7, 8, 1, 2, 3, 4],
       categories: ['UPCOMING'],
       seqNo: 5,
       url: 'the-man-of-wisdom1',
    },

    6: {
        id: 6,
        movieId: 66,
        title: 'The Rich Master amp; The Donkeys',
        season: 'Season 1',
        episode: 'Episode 2',
        episode_title: 'Episode Title: The Man of Wisdom II',
        overview: 'The Donkeys thought thier minds are hidden but unknowing to them that it goes beyond the physical and that there is one who dwells among them and He knows and sees everything beyond the physical',
        poster_path: '/The_RichMaster_SmallEpisode2.png',
        posterUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/SmartsSmallPoster/The_RichMaster_SmallEpisode2.png',
        backdropUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/BigBackdrop/The_RichMaster_BigPoster.jpg',
        adult: false,
        release_date: '20th March, 2022',
        genre_ids: [
        27, 28, 31
      ],
       backdrop_path: '/The_RichMaster_BigPoster.jpg',
       member_required: true,
       free: false,
       belongs_to_collection: null,
       original_language: 'en',
       popularity: null,
       vote_count: '4300',
       video: false,
       vote_average: '8.2',
       homepage: '',
       imdb_id: 'aef091080',
       credit_ids: ['52fe43c4c3a36847f807y890', '52fe43c4c3a36847f808y891', '52fe43c4c3a36847f809y892', 
                    '52fe43c4c3a36847f801y893', '52fe43c4c3a36847f802y894', '52fe43c4c3a36847f803y895',
                    '52fe43c4c3a36847f804y896', '52fe43c4c3a36847f805y897', '52fe43c4c3a36847f806y898',
                    '52fe43c4c3a36847f801z899'  
       ],
       cast_ids: [
        20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
       production_companies: '3smartsflix',
       production_countries: 'NG',
       runtime: '15',
       spoken_languages: 'en',
       status: 'Upcoming',
       release_type: 3,
       category: 'upcoming',
       upcoming: true,
       now_playing: false,
       category_id: 86,
       tagline: 'Purge Your Mind To House The Goodluck',
       file_path: '/3smarts-photorichmaster-backdrops',
       recomend_id: [5, 7, 8, 1, 2, 3, 4],
       categories: ['UPCOMING'],
       seqNo: 6,
       url: 'the-man-of-wisdom2',
    },

    7: {
        id: 7,
        movieId: 66,
        title: 'The Rich Master amp; The Donkeys',
        season: 'Season 1',
        episode: 'Episode 3',
        episode_title: 'Episode Title: The Donkeys Folly I',
        overview: 'The Donkeys thought thier minds are hidden but unknowing to them that it goes beyond the physical and that there is one who dwells among them and He knows and sees everything beyond the physical',
        poster_path: '/The_RichMaster_SmallEpisode3.png',
        posterUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/SmartsSmallPoster/The_RichMaster_SmallEpisode3.png',
        backdropUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/BigBackdrop/The_RichMaster_BigPoster.jpg',
        adult: false,
        release_date: '3rd April, 2022',
        genre_ids: [
        27, 28, 31
      ],
       backdrop_path: '/The_RichMaster_BigPoster.jpg',
       member_required: true,
       free: false,
       belongs_to_collection: null,
       original_language: 'en',
       popularity: null,
       vote_count: '4300',
       video: false,
       vote_average: '8.2',
       homepage: '',
       imdb_id: 'aef091080',
       credit_ids: ['52fe43c4c3a36847f807y890', '52fe43c4c3a36847f808y891', '52fe43c4c3a36847f809y892', 
                    '52fe43c4c3a36847f801y893', '52fe43c4c3a36847f802y894', '52fe43c4c3a36847f803y895',
                    '52fe43c4c3a36847f804y896', '52fe43c4c3a36847f805y897', '52fe43c4c3a36847f806y898',
                    '52fe43c4c3a36847f801z899'  
       ],
       cast_ids: [
        20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
       production_companies: '3smartsflix',
       production_countries: 'NG',
       runtime: '15',
       spoken_languages: 'en',
       status: 'Upcoming',
       release_type: 3,
       category_id: 86,
       category: 'upcoming',
       upcoming: true,
       now_playing: false,
       tagline: 'Purge Your Mind To House The Goodluck',
       file_path: '/3smarts-photorichmaster-backdrops',
       recomend_id: [5, 6, 8, 1, 2, 3, 4],
       categories: ['UPCOMING'],
       seqNo: 7,
       url: 'the-donkeys-folly1',
    },

    8: {
        id: 8,
        movieId: 66,
        title: 'The Rich Master amp; The Donkeys',
        season: 'Season 1',
        episode: 'Episode 4',
        episode_title: 'Episode Title: The Donkeys Folly II',
        overview: 'The Donkeys thought thier minds are hidden but unknowing to them that it goes beyond the physical and that there is one who dwells among them and He knows and sees everything beyond the physical',
        poster_path: '/The_RichMaster_SmallEpisode4.png',
        posterUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/SmartsSmallPoster/The_RichMaster_SmallEpisode4.png',
        backdropUrl: 'https://3smartsflix.s3.us-east-2.amazonaws.com/BigBackdrop/The_RichMaster_BigPoster.jpg',
        adult: false,
        release_date: '1st May, 2022',
        genre_ids: [
        27, 28, 31
      ],
       backdrop_path: '/The_RichMaster_BigPoster.jpg',
       member_required: true,
       free: false,
       belongs_to_collection: null,
       original_language: 'en',
       popularity: null,
       vote_count: '4300',
       video: false,
       vote_average: '8.2',
       homepage: '',
       imdb_id: 'aef091080',
       credit_ids: ['52fe43c4c3a36847f807y890', '52fe43c4c3a36847f808y891', '52fe43c4c3a36847f809y892', 
                    '52fe43c4c3a36847f801y893', '52fe43c4c3a36847f802y894', '52fe43c4c3a36847f803y895',
                    '52fe43c4c3a36847f804y896', '52fe43c4c3a36847f805y897', '52fe43c4c3a36847f806y898',
                    '52fe43c4c3a36847f801z899'  
       ],
       cast_ids: [
        20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
       production_companies: '3smartsflix',
       production_countries: 'NG',
       runtime: '15',
       spoken_languages: 'en',
       status: 'Upcoming',
       release_type: 3,
       category_id: 86,
       category: 'upcoming',
       upcoming: true,
       now_playing: false,
       tagline: 'Purge Your Mind To House The Goodluck',
       file_path: '/3smarts-photorichmaster-backdrops',
       recomend_id: [5, 6, 7, 1, 2, 3, 4],
       categories: ['UPCOMING'],
       seqNo: 8,
       url: 'the-donkeys-folly2',
    },
    
};  
 

Чтобы получить все фильмы, я использовал этот код

 loadAllMovies(): Observable<MovieModel[]> {
          return this.db.collection(
              'movies',
                  ref=> ref.orderBy("seqNo")
              )
              .snapshotChanges()
              .pipe(
                  map(snaps => convertSnaps<MovieModel>(snaps)),
                  first());
      }
  
  
      getMovieById(movieId: string):Observable<MovieModel | null | undefined> {
          return this.db.collection('movies',
              ref=> ref.where("id", "==", movieId))
              .snapshotChanges()
              .pipe(
                  map(snaps => {
  
                      const movies = convertSnaps<MovieModel>(snaps);
  
                      return movies.length == 1 ? movies[0]: undefined;
                  }),
                  first()
              )
      }

      getMovieDetails(movieId: string):Observable<MovieModel | null | undefined> {
        return this.db.collection('movies',
            ref=> ref.where("id", "==", movieId))
            .snapshotChanges()
            .pipe(
                map(snaps => {

                    const movies = convertSnaps<MovieModel>(snaps);

                    return movies.length == 1 ? movies[0]: undefined;
                }),
                first()
            )
    } 
 

Проблема, с которой я сейчас сталкиваюсь, заключается в том, как мне получить следующее:

  • getPersonDetails
  • getPersonCast
  • getCastMovie
  • getMovieByGenre
  • getGenres
  • getMovieCredits
  • getSingleMoviesVideos

Нужно ли мне получить доступ к getPersonDetails, прежде чем я смогу получить доступ к getPersonDetails?

Комментарии:

1. Похоже, у вас нет никаких проблем с кодированием, но с архитектурой данных/кода. Какие проблемы возникают у вас при создании других методов? Они дали вам какую-либо ошибку? Есть ли у вас какая-либо другая коллекция, в которой указаны идентификаторы актеров/жанров? Кроме того, вам не нужно публиковать здесь всю коллекцию целиком. С одной выборкой данных достаточно.

2. Я пытаюсь создать пользовательский api для своего потокового сайта, у Imbd есть свой собственный api, который не будет работать для пользовательского api, поэтому необходимо написать мои собственные службы api. Позвольте мне запустить его и посмотреть, есть ли какие-либо проблемы. Спасибо

3. Вы столкнулись с какими-либо проблемами при запуске пользовательского api?