@@ -8,6 +8,7 @@ import 'package:unn_mobile/core/constants/profiles_strings.dart';
88import 'package:unn_mobile/core/misc/dio_interceptor/response_data_type.dart' ;
99import 'package:unn_mobile/core/misc/dio_interceptor/response_type_interceptor.dart' ;
1010import 'package:unn_mobile/core/misc/dio_options_factory/options_with_expected_type_factory.dart' ;
11+ import 'package:unn_mobile/core/misc/json/json_search.dart' ;
1112import 'package:unn_mobile/core/misc/json/json_utils.dart' ;
1213import 'package:unn_mobile/core/models/profile/employee/employee_data.dart' ;
1314import 'package:unn_mobile/core/models/profile/student/student_data.dart' ;
@@ -40,31 +41,32 @@ class ProfileServiceImpl implements ProfileService {
4041 return null ;
4142 }
4243
43- final data = response.data as JsonMap ;
44- final userType = data [ProfilesStrings .type] ??
45- ((data [ProfilesStrings .profilesKey]! as List )[0 ]
44+ final responseData = response.data as JsonMap ;
45+ final userType = responseData [ProfilesStrings .type] ??
46+ ((responseData [ProfilesStrings .profilesKey]! as List )[0 ]
4647 as JsonMap )[ProfilesStrings .type];
4748
4849 UserData ? userData;
4950 try {
5051 userData = switch (userType) {
51- ProfilesStrings .student => StudentData .fromJson (response.data),
52- ProfilesStrings .employee => EmployeeData .fromJson (response.data),
53- _ => UserData .fromJson (response.data),
52+ ProfilesStrings .student =>
53+ StudentData .fromJson (_getStudentJson (responseData)),
54+ ProfilesStrings .employee =>
55+ EmployeeData .fromJson (_getEmployeeJson (responseData)),
56+ _ => UserData .fromJson (_getUserJson (responseData)),
5457 };
5558 } catch (error, stackTrace) {
5659 _loggerService.logError (
5760 error,
5861 stackTrace,
59- information: [response.data .toString ()],
62+ information: [responseData .toString ()],
6063 );
6164 }
62-
6365 return userData;
6466 }
6567
6668 @override
67- Future <UserData ?> getProfileByBitrixId (int bitrixId) async {
69+ Future <UserData ?> getProfileByBitrixId ({ required int bitrixId} ) async {
6870 final userId = await _getUserIdByBitrixId (bitrixId: bitrixId);
6971 if (userId == null ) {
7072 return null ;
@@ -74,11 +76,11 @@ class ProfileServiceImpl implements ProfileService {
7476
7577 @override
7678 Future <UserData ?> getProfileByAuthorId ({required int authorId}) =>
77- getProfileByBitrixId (authorId);
79+ getProfileByBitrixId (bitrixId : authorId);
7880
7981 @override
8082 Future <UserData ?> getProfileByDialogId ({required int dialogId}) =>
81- getProfileByBitrixId (dialogId);
83+ getProfileByBitrixId (bitrixId : dialogId);
8284
8385 Future <int ?> _getUserIdByBitrixId ({required int bitrixId}) async {
8486 final path =
@@ -108,4 +110,18 @@ class ProfileServiceImpl implements ProfileService {
108110
109111 return id;
110112 }
113+
114+ JsonMap _extractJson (JsonMap json, Set <String > keys) {
115+ final JsonMap results = {};
116+ collectFirstValues (json, keys, results);
117+ return results;
118+ }
119+
120+ JsonMap _getStudentJson (JsonMap json) =>
121+ _extractJson (json, StudentData .jsonKeys);
122+
123+ JsonMap _getEmployeeJson (JsonMap json) =>
124+ _extractJson (json, EmployeeData .jsonKeys);
125+
126+ JsonMap _getUserJson (JsonMap json) => _extractJson (json, UserData .jsonKeys);
111127}
0 commit comments