Skip to content

Commit 2d83d83

Browse files
authored
feat: Implement profile view.
2 parents 1fe4625 + 87886d3 commit 2d83d83

56 files changed

Lines changed: 2955 additions & 366 deletions

Some content is hidden

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

assets/app/icons/lock_filled.svg

Lines changed: 9 additions & 0 deletions
Loading

lib/data/constants/assets.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class AppAssets {
1212
static const String eyeOn = '$_iconsRoot/eye-on.svg';
1313
static const String eyeOff = '$_iconsRoot/eye-off.svg';
1414
static const String lock = '$_iconsRoot/lock.svg';
15+
static const String lockFilled = '$_iconsRoot/lock_filled.svg';
1516
static const String person = '$_iconsRoot/person.svg';
1617
static const String filter = '$_iconsRoot/filter.svg';
1718
static const String bell = '$_iconsRoot/bell.svg';

lib/data/constants/colors.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class AppColors {
1414
static const Color grey10 = Color(0xFFE5E5E5);
1515
static const Color acceptedGreen = Color(0xFF4CAF50);
1616
static const Color errorRed = Color(0xFFEB5757);
17+
static const Color lightBlue = Color(0xFFEFF2FC);
1718
static const Color transparent = Colors.transparent;
1819

1920
static const Color primary = Color(0xFF3366FF);

lib/data/constants/routes.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ class AppRoutes {
1111

1212
// Post-Auth
1313
static const String home = '/home';
14+
static const String updateProfile = '/updatePofile';
1415
}

lib/data/services/local/image_service.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ImageService {
3131
compressQuality: 100,
3232
maxHeight: 1000,
3333
maxWidth: 1000,
34+
cropStyle: CropStyle.circle,
3435
compressFormat: ImageCompressFormat.png,
3536
);
3637
return croppedImage;

lib/data/services/local/storage_service.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class StorageService {
5151
/// Currently logged in user.
5252
static User? get user {
5353
try {
54-
return User.fromJson(json.decode(_get<String>(AppStrings.userKey)!));
55-
} on Exception catch (_) {
54+
return User.fromJson(json.decode(_get<String>(AppStrings.userKey) ?? ''));
55+
} on FormatException catch (_) {
5656
// This just means that the user has not been stored previously.
5757
return null;
5858
}
@@ -81,7 +81,7 @@ class StorageService {
8181
static List<User>? get recentSearches {
8282
try {
8383
return List<User>.from(json
84-
.decode(_get<String>(AppStrings.recentSearchKey)!)
84+
.decode(_get<String>(AppStrings.recentSearchKey) ?? '')
8585
.map((e) => User.fromJson(e)));
8686
} on Exception catch (_) {
8787
return null;

lib/domain/models/following.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ part 'following.g.dart';
66
@freezed
77
class Following with _$Following {
88
factory Following({
9-
required String id,
9+
@JsonKey(name: '_id') required String id,
1010
required String username,
1111
String? fullname,
1212
String? picture,

lib/domain/models/handle.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ part 'handle.g.dart';
66
@freezed
77
class Handle with _$Handle {
88
factory Handle({
9-
@JsonKey(name: 'handle.codechef') String? codechef,
10-
@JsonKey(name: 'handle.codeforces') String? codeforces,
11-
@JsonKey(name: 'handle.hackerrank') String? hackerrank,
12-
@JsonKey(name: 'handle.spoj') String? spoj,
13-
@JsonKey(name: 'handle.leetcode') String? leetcode,
9+
@JsonKey(name: 'codechef') String? codechef,
10+
@JsonKey(name: 'codeforces') String? codeforces,
11+
@JsonKey(name: 'hackerrank') String? hackerrank,
12+
@JsonKey(name: 'spoj') String? spoj,
13+
@JsonKey(name: 'leetcode') String? leetcode,
1414
}) = _Handle;
1515

1616
factory Handle.fromJson(Map<String, dynamic> json) => _$HandleFromJson(json);

lib/domain/models/user.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ class User with _$User {
1515
Handle? handle,
1616
String? id,
1717
String? institute,
18-
int? noOfFollowing,
18+
@JsonKey(name: 'no_of_following') int? noOfFollowing,
1919
String? picture,
2020
UserProfile? profiles,
21-
List<Submission>? recentSubmissions,
21+
@JsonKey(name: 'recent_submissions') List<Submission>? recentSubmissions,
2222
String? username,
23-
SolvedProblemsCount? solvedProblemsCount,
23+
@JsonKey(name: 'solved_problems_count')
24+
SolvedProblemsCount? solvedProblemsCount,
2425
}) = _User;
2526

2627
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);

lib/domain/repositories/user_repository.dart

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import 'dart:convert';
22
import 'dart:io';
33

44
import '../../data/config/config.dart';
5+
import '../../data/constants/strings.dart';
56
import '../../data/services/local/storage_service.dart';
67
import '../../data/services/remote/api_service.dart';
78
import '../../utils/auth_token.dart' as auth_token_utils;
89
import '../../utils/failures.dart';
10+
import '../models/activity_details.dart';
911
import '../models/following.dart';
1012
import '../models/sign_up.dart';
1113
import '../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

Comments
 (0)