Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More cleanup of the pagination implementation #17

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading