Skip to content

Commit df4e083

Browse files
ReWorked The Watchlist System & Improved Overall Performance
1 parent e598a22 commit df4e083

File tree

123 files changed

+1554
-3098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+1554
-3098
lines changed

lib/config/router/app_router.gr.dart

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/api/authenticated_interceptor.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import 'package:tmda/features/shared/domain/usecases/get_session_id_usecase.dart
77
@lazySingleton
88
class AuthenticatedInterceptor extends Interceptor{
99
final GetSessionIdUseCase _getSessionIdUseCase;
10-
11-
const AuthenticatedInterceptor(this._getSessionIdUseCase);
10+
String _sessionId = '';
11+
AuthenticatedInterceptor(this._getSessionIdUseCase);
1212
@override
1313
void onRequest(RequestOptions options, RequestInterceptorHandler handler) async{
14-
options.queryParameters['session_id'] = await _getSessionIdUseCase();
14+
if(_sessionId.isEmpty){
15+
_sessionId = await _getSessionIdUseCase();
16+
}
1517
if (kDebugMode) {
1618
print('REQUEST[${options.method}] => PATH: ${options.path}');
1719
}
1820
options.headers[ApiConstants.headerContentType] = ApiConstants.headerContentTypeValue;
21+
options.queryParameters['session_id'] = _sessionId;
1922
super.onRequest(options, handler);
2023
}
2124

lib/core/api/dio_consumer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import 'package:flutter/foundation.dart';
55
import 'package:dio/dio.dart';
66
import 'package:tmda/core/api/api_consumer.dart';
77
import 'package:tmda/core/api/api_status_code.dart';
8-
import 'package:tmda/core/api/authenticated_interceptor.dart';
98
import 'package:tmda/core/api/dio_logger.dart';
9+
import 'package:tmda/core/api/unauthenticated_interceptor.dart';
1010
import 'package:tmda/core/constants/api_constants.dart';
1111
import 'package:tmda/core/error/exception.dart';
1212
import 'package:tmda/injection_container.dart';
@@ -34,7 +34,7 @@ class DioApiConsumer extends ApiConsumer {
3434
if(interceptor != null){
3535
dioClient.interceptors.add(interceptor!);
3636
}else{
37-
dioClient.interceptors.add(getIt<AuthenticatedInterceptor>());
37+
dioClient.interceptors.add(getIt<UnAuthenticatedInterceptor>());
3838
}
3939

4040
if (kDebugMode) {

lib/core/constants/api_constants.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
final class ApiConstants {
22
//! Core Api
3-
static const String apiKey = '45fe17b977fb94a0c0c099b894af2c74';
4-
static const String accountId = '15269101';
3+
static const String apiKey = 'YOUR_API_KEY';
4+
static const String accountId = 'YOUR_ACCOUNT_ID';
55
static const String apiKeyQuery = 'api_key';
66
static const String baseUrl = 'https://api.themoviedb.org/3';
77
static const String baseImageUrl = 'https://image.tmdb.org/t/p/w500';
@@ -14,7 +14,7 @@ final class ApiConstants {
1414
static const String headerContentTypeValue = 'application/json';
1515
static const String headerContentType = 'Content-Type';
1616
static const String personEndPointAppendedToResponse = 'movie_credits,tv_credits';
17-
static const String endPointsAppendedToResponse = 'videos,account_states,credits,similar,reviews,recommendations';
17+
static const String detailsEndPointsAppendedToResponse = 'videos,credits,similar,reviews,recommendations';
1818
static const String movieMediaTypeTitle = 'movie';
1919
static const String tvMediaTypeTitle = 'tv';
2020
//! Auth Endpoints & Urls

lib/features/account/data/datasources/account_data_source.dart

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,8 @@ import 'package:tmda/core/api/api_consumer.dart';
33
import 'package:tmda/core/constants/api_constants.dart';
44
import 'package:tmda/core/error/exception.dart';
55
import 'package:tmda/features/account/data/models/account_model.dart';
6-
import 'package:tmda/features/account/data/models/account_states_model.dart';
7-
import 'package:tmda/features/account/data/models/watchlist_movie_model.dart';
8-
import 'package:tmda/features/account/data/models/watchlist_tv_show_model.dart';
9-
106
abstract class AccountDataSource{
117
Future<AccountModel> getAccountDetails();
12-
Future<List<WatchListMovieModel>> getMoviesWatchList();
13-
Future<List<WatchListTvShowModel>> getTvShowsWatchList();
14-
Future<List<WatchListMovieModel>> getAllMoviesWatchList({required int pageNumber});
15-
Future<List<WatchListTvShowModel>> getAllTvShowsWatchList({ required int pageNumber});
16-
Future<AccountStatesModel> removeTvShowFromWatchList({required int contentId});
17-
Future<AccountStatesModel> removeMovieFromWatchList({required int contentId});
18-
Future<AccountStatesModel> getTvShowWatchListStates({required int contentId});
19-
Future<AccountStatesModel> getMovieWatchListStates({required int contentId});
208
Future<void> accountLogOut({required String sessionId});
219
}
2210

@@ -31,100 +19,6 @@ class AccountDataSourceImpl extends AccountDataSource{
3119
return AccountModel.fromJson(accountDetails);
3220
}
3321

34-
@override
35-
Future<List<WatchListMovieModel>> getMoviesWatchList() async{
36-
final listOfMovies =
37-
await _apiConsumer.get('${ApiConstants.accountEndPoint}${ApiConstants.accountMoviesWatchListPath}');
38-
return List<WatchListMovieModel>.from(
39-
(listOfMovies['results'] as List).map(
40-
(watchlistMovie) => WatchListMovieModel.fromJson(watchlistMovie),
41-
),
42-
);
43-
}
44-
45-
@override
46-
Future<List<WatchListTvShowModel>> getTvShowsWatchList() async{
47-
final listOfTvShows = await _apiConsumer.get('${ApiConstants.accountEndPoint}${ApiConstants.accountTvWatchListPath}');
48-
return List<WatchListTvShowModel>.from(
49-
(listOfTvShows['results'] as List).map(
50-
(watchlistTvShow) => WatchListTvShowModel.fromJson(watchlistTvShow),
51-
),
52-
);
53-
}
54-
55-
@override
56-
Future<List<WatchListMovieModel>> getAllMoviesWatchList({required int pageNumber}) async{
57-
final listOfMovies = await _apiConsumer.get('${ApiConstants.accountEndPoint}${ApiConstants.accountMoviesWatchListPath}', queryParameters: {
58-
'page': pageNumber,
59-
});
60-
final movieIds = listOfMovies['results'].map((movie) => movie['id']).toList();
61-
final movieStatuses = await Future.wait(movieIds.map((id) => _apiConsumer.get('${ApiConstants.movieDetailsEndPoint}$id${ApiConstants.accountStatusPath}')).toList().cast<Future<dynamic>>());
62-
return List<WatchListMovieModel>.generate(movieIds.length, (index) {
63-
final Map<String, dynamic> movie = listOfMovies['results'][index];
64-
movie.addAll({'account_status' : movieStatuses[index]});
65-
return WatchListMovieModel.fromJson(movie);
66-
});
67-
}
68-
69-
@override
70-
Future<List<WatchListTvShowModel>> getAllTvShowsWatchList({required int pageNumber}) async{
71-
final listOfTvShows = await _apiConsumer.get('${ApiConstants.accountEndPoint}${ApiConstants.accountTvWatchListPath}', queryParameters: {
72-
'page': pageNumber,
73-
});
74-
final tvShowsIds = listOfTvShows['results'].map((movie) => movie['id']).toList();
75-
final tvShowsStatuses = await Future.wait(tvShowsIds.map((id) => _apiConsumer.get('${ApiConstants.tvShowDetailsEndPoint}$id${ApiConstants.accountStatusPath}')).toList().cast<Future<dynamic>>());
76-
return List<WatchListTvShowModel>.generate(tvShowsIds.length, (index) {
77-
final Map<String, dynamic> tvShow = listOfTvShows['results'][index];
78-
tvShow.addAll({'account_status' : tvShowsStatuses[index]});
79-
return WatchListTvShowModel.fromJson(tvShow);
80-
});
81-
}
82-
83-
@override
84-
Future<AccountStatesModel> removeTvShowFromWatchList({required int contentId}) async{
85-
final response = await _apiConsumer.post(ApiConstants.addOrRemoveFromWatchListEndPoint,
86-
body: {
87-
'media_type': 'tv',
88-
"media_id": contentId,
89-
"watchlist": false
90-
},
91-
);
92-
if (response['success'] == true) {
93-
return AccountStatesModel(inWatchList: false, contentId: contentId);
94-
} else {
95-
throw ServerException('${response['status_message']}');
96-
}
97-
}
98-
@override
99-
Future<AccountStatesModel> removeMovieFromWatchList({required int contentId}) async{
100-
final response = await _apiConsumer.post(ApiConstants.addOrRemoveFromWatchListEndPoint,
101-
body: {
102-
'media_type': 'movie',
103-
"media_id": contentId,
104-
"watchlist": false
105-
},
106-
);
107-
if (response['success'] == true) {
108-
return AccountStatesModel(inWatchList: false, contentId: contentId);
109-
} else {
110-
throw ServerException('${response['status_message']}');
111-
}
112-
}
113-
114-
@override
115-
Future<AccountStatesModel> getTvShowWatchListStates({required int contentId}) async{
116-
final Map<String, dynamic> watchListStates = await _apiConsumer.get('${ApiConstants.tvShowDetailsEndPoint}$contentId${ApiConstants.accountStatusPath}');
117-
watchListStates.addAll({'content_id' : contentId});
118-
return AccountStatesModel.fromJson(watchListStates);
119-
}
120-
121-
@override
122-
Future<AccountStatesModel> getMovieWatchListStates({required int contentId}) async{
123-
final Map<String, dynamic> watchListStates = await _apiConsumer.get('${ApiConstants.movieDetailsEndPoint}$contentId${ApiConstants.accountStatusPath}');
124-
watchListStates.addAll({'content_id' : contentId});
125-
return AccountStatesModel.fromJson(watchListStates);
126-
}
127-
12822
@override
12923
Future<void> accountLogOut({required String sessionId}) async{
13024
final response = await _apiConsumer.delete(ApiConstants.accountLogoutEndPoint, body: {

lib/features/account/data/models/watchlist_genres_model.dart

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/features/account/data/models/watchlist_movie_model.dart

Lines changed: 0 additions & 55 deletions
This file was deleted.

lib/features/account/data/models/watchlist_tv_show_model.dart

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)