public async Task <IEnumerable <Cast> > GetMovieCredits(int id) { if (id == 0) { throw new ArgumentNullException(nameof(id)); } _loggerAgent.Information($"Call movie cast for movie id: {id}"); var response = await _httpClient.GetAsync($"MovieCast?code=iu4wd97KvLQV4GlZaRvpljfUllHKReay7G6RosCpsqBRxZvZLu1aLw==&Id={id}"); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var cast = JsonConvert.DeserializeObject <CastResult>(content); if (cast != null) { return(cast.ToModel()); } _loggerAgent.Error($"CastService: GetMovieCredits for movie id {id} deserialize failed"); throw new InvalidCastException(nameof(cast)); } _loggerAgent.Error($"MovieService: GetMovie called with id {id} failed. Status code: {response.StatusCode}"); return(null); }
public async Task <MovieDetail> GetMovie(int id) { if (id == 0) { throw new ArgumentNullException(nameof(id)); } _loggerAgent.Information($"Call movie with id: {id}"); var response = await _httpClient.GetAsync($"MovieDetail?code=jEpGNqiIn9OlAcsNd5gNj2vfAoyqxfKOgt8ZxFqmPhrJJnaPh5vdSQ==&Id={id}"); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var movie = JsonConvert.DeserializeObject <MovieDetailDTO>(content); if (movie != null) { return(movie.ToMovieDetail()); } _loggerAgent.Error($"MovieService: GetMovie with id {id} deserialize failed"); throw new InvalidCastException(nameof(movie)); } else { _loggerAgent.Error($"MovieService: GetMovie called with id {id} failed. Statuscode: {response.StatusCode}"); return(new MovieDetail()); } }