Skip to content

Commit

Permalink
More cleanup of the pagination implementation (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
bizz84 authored Apr 11, 2024
1 parent 7c4514d commit f711c33
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 378 deletions.
18 changes: 0 additions & 18 deletions lib/src/features/movies/data/movies_pagination.dart

This file was deleted.

15 changes: 8 additions & 7 deletions lib/src/features/movies/data/movies_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:tmdb_movie_app_riverpod/env/env.dart';
import 'package:tmdb_movie_app_riverpod/src/features/movies/data/movies_pagination.dart';
import 'package:tmdb_movie_app_riverpod/src/features/movies/domain/tmdb_movie.dart';
import 'package:tmdb_movie_app_riverpod/src/features/movies/domain/tmdb_movies_response.dart';
import 'package:tmdb_movie_app_riverpod/src/utils/cancel_token_ref.dart';
import 'package:tmdb_movie_app_riverpod/src/utils/dio_provider.dart';

part 'movies_repository.g.dart';

/// Metadata used when fetching movies with the paginated search API.
typedef MoviesPagination = ({String query, int page});

class MoviesRepository {
MoviesRepository({required this.client, required this.apiKey});
const MoviesRepository({required this.client, required this.apiKey});
final Dio client;
final String apiKey;

Future<TMDBMoviesResponse> searchMovies(
{required int page, String query = '', CancelToken? cancelToken}) async {
{required MoviesPagination pagination, CancelToken? cancelToken}) async {
final url = Uri(
scheme: 'https',
host: 'api.themoviedb.org',
path: '3/search/movie',
queryParameters: {
'api_key': apiKey,
'include_adult': 'false',
'page': '$page',
'query': query,
'page': '${pagination.page}',
'query': pagination.query,
},
).toString();
final response = await client.get(url, cancelToken: cancelToken);
Expand Down Expand Up @@ -131,8 +133,7 @@ Future<TMDBMoviesResponse> fetchMovies(
if (cancelToken.isCancelled) throw AbortedException();
// use search endpoint
return moviesRepo.searchMovies(
page: pagination.page,
query: pagination.query,
pagination: pagination,
cancelToken: cancelToken,
);
}
Expand Down
13 changes: 7 additions & 6 deletions lib/src/features/movies/data/movies_repository.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions lib/src/features/movies/domain/tmdb_movie.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,9 @@ part 'tmdb_movie.g.dart';
@freezed
class TMDBMovie with _$TMDBMovie {
factory TMDBMovie({
@JsonKey(name: 'vote_count') int? voteCount,
required int id,
@Default(false) bool video,
@JsonKey(name: 'vote_average') double? voteAverage,
required String title,
double? popularity,
@JsonKey(name: 'poster_path') String? posterPath,
@JsonKey(name: 'original_language') String? originalLanguage,
@JsonKey(name: 'original_title') String? originalTitle,
@JsonKey(name: 'genre_ids') List<int>? genreIds,
@JsonKey(name: 'backdrop_path') String? backdropPath,
bool? adult,
String? overview,
@JsonKey(name: 'release_date') String? releaseDate,
}) = _TMDBMovieBasic;

Expand Down
Loading

0 comments on commit f711c33

Please sign in to comment.