@@ -2,10 +2,12 @@ import 'dart:convert';
22import 'dart:io' ;
33
44import '../../data/config/config.dart' ;
5+ import '../../data/constants/strings.dart' ;
56import '../../data/services/local/storage_service.dart' ;
67import '../../data/services/remote/api_service.dart' ;
78import '../../utils/auth_token.dart' as auth_token_utils;
89import '../../utils/failures.dart' ;
10+ import '../models/activity_details.dart' ;
911import '../models/following.dart' ;
1012import '../models/sign_up.dart' ;
1113import '../models/submission_status.dart' ;
@@ -191,19 +193,20 @@ class UserRepository {
191193 );
192194
193195 if (response['status_code' ] == 200 ) {
196+ if (response['data' ] == 'null' ) return < Following > [];
197+
194198 return List <Following >.from (
195- json. decode ( response['data' ]) .map ((e) => Following .fromJson (e)),
199+ response['data' ].map ((e) => Following .fromJson (e)),
196200 );
197201 }
198- return null ;
202+
203+ throw Exception (AppStrings .genericError);
199204 }
200205
201206 static Future <bool > verifyHandle (String site, String handle) async {
202207 final endpoint = 'user/verify/$site ?handle=$handle ' ;
203208
204- final response = await ApiService .post (
205- endpoint,
206- );
209+ final response = await ApiService .get (endpoint);
207210
208211 return response['status_code' ] == 200 ;
209212 }
@@ -224,6 +227,7 @@ class UserRepository {
224227 _users.add (User .fromJson (user));
225228 }
226229 }
230+
227231 return _users;
228232 }
229233
@@ -245,7 +249,7 @@ class UserRepository {
245249 return [];
246250 }
247251
248- static Future <List < SubmissionStatus > ?> getSubmissionStatusData (
252+ static Future <SubmissionStatus ?> getSubmissionStatusData (
249253 String id,
250254 ) async {
251255 final endpoint = 'graph/status/$id ' ;
@@ -258,14 +262,34 @@ class UserRepository {
258262 );
259263
260264 if (response['status_code' ] == 200 ) {
261- return List <SubmissionStatus >.from (
262- json.decode (response['data' ])? .map ((e) => SubmissionStatus .fromJson (e)),
265+ return SubmissionStatus .fromJson (response['data' ]);
266+ }
267+
268+ throw Exception (AppStrings .genericError);
269+ }
270+
271+ static Future <List <ActivityDetails >?> getActivityDetails (String id) async {
272+ final endpoint = 'graph/activity/$id ' ;
273+ final headers = < String , dynamic > {};
274+
275+ ApiService .addTokenToHeaders (headers);
276+ final response = await ApiService .get (
277+ endpoint,
278+ headers: headers,
279+ );
280+
281+ if (response['status_code' ] == 200 ) {
282+ if (response['data' ] == 'null' ) return < ActivityDetails > [];
283+
284+ return List <ActivityDetails >.from (
285+ response['data' ].map ((e) => ActivityDetails .fromJson (e)),
263286 );
264287 }
265- return null ;
288+
289+ throw Exception (AppStrings .genericError);
266290 }
267291
268- static Future < int > updatePassword (
292+ static Future updatePassword (
269293 String oldPassword,
270294 String newPassword,
271295 ) async {
@@ -276,21 +300,28 @@ class UserRepository {
276300 final response = await ApiService .post (
277301 endpoint,
278302 headers: headers,
279- data: < String , String > {
303+ data: {
280304 'new_password' : newPassword,
281305 'old_password' : oldPassword,
282306 },
283307 );
284308
285- return response['status_code' ];
309+ switch (response['status_code' ]) {
310+ case 200 :
311+ return ;
312+ case 403 :
313+ throw const IncorrectCredentials ();
314+ default :
315+ throw const InternalFailure ();
316+ }
286317 }
287318
288319 static Future <int > updateUserDetails (Map <String , dynamic >? data) async {
289320 const endpoint = 'user/' ;
290321 final headers = < String , dynamic > {};
291322
292323 ApiService .addTokenToHeaders (headers);
293- final response = await ApiService .post (
324+ final response = await ApiService .put (
294325 endpoint,
295326 headers: headers,
296327 data: data,
0 commit comments