@@ -3,20 +3,8 @@ import 'package:tmda/core/api/api_consumer.dart';
33import 'package:tmda/core/constants/api_constants.dart' ;
44import 'package:tmda/core/error/exception.dart' ;
55import '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-
106abstract 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: {
0 commit comments