Skip to content

Commit b74bd58

Browse files
committed
Временное решение
1 parent 555aa6d commit b74bd58

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

lib/core/models/profile/student/student_data.dart

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,22 @@ class StudentData extends UserData {
4747
notes: userData.notes,
4848
);
4949

50-
factory StudentData.fromJson(JsonMap json) => StudentData.withUserData(
51-
baseEduInfo: BaseEduInfo.fromJson(json),
52-
userData: UserData.fromJson(json),
53-
eduStatus: json[_StudentDataJsonKeys.eduStatus]! as String,
54-
eduYear: json[_StudentDataJsonKeys.eduYear]! as int,
55-
);
50+
factory StudentData.fromJson(JsonMap json) {
51+
final profiles = json['profiles'];
52+
JsonMap firstProfile = {};
53+
if (profiles is List && profiles.isNotEmpty) {
54+
firstProfile = profiles[0];
55+
}
56+
57+
final resultMap = {...firstProfile, ...json};
58+
59+
return StudentData.withUserData(
60+
baseEduInfo: BaseEduInfo.fromJson(resultMap),
61+
userData: UserData.fromJson(resultMap),
62+
eduStatus: resultMap[_StudentDataJsonKeys.eduStatus]! as String,
63+
eduYear: resultMap[_StudentDataJsonKeys.eduYear]! as int,
64+
);
65+
}
5666

5767
@override
5868
JsonMap toJson() => {

lib/core/models/profile/user_data.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class UserData extends UserShortInfo {
4949
);
5050

5151
factory UserData.fromJson(JsonMap json) {
52-
final userJsonMap = (json[_UserDataJsonKeys.user] ?? json) as JsonMap;
52+
final userPart = json[_UserDataJsonKeys.user] as JsonMap?;
53+
final userJsonMap = {...?userPart, ...json};
5354
return UserData.withUserShortInfo(
5455
userShortInfo: UserShortInfo.fromProfileJson(userJsonMap),
5556
userId: userJsonMap[_UserDataJsonKeys.id]! as int,

lib/core/services/implementations/profile/profile_service_impl.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ class ProfileServiceImpl implements ProfileService {
4141
}
4242

4343
final data = response.data as JsonMap;
44+
4445
final userType = data[ProfilesStrings.type] ??
4546
((data[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),
52+
ProfilesStrings.student => StudentData.fromJson(data),
53+
ProfilesStrings.employee => EmployeeData.fromJson(data),
5354
_ => UserData.fromJson(response.data),
5455
};
5556
} catch (error, stackTrace) {
@@ -64,7 +65,7 @@ class ProfileServiceImpl implements ProfileService {
6465
}
6566

6667
@override
67-
Future<UserData?> getProfileByBitrixId(int bitrixId) async {
68+
Future<UserData?> getProfileByBitrixId({required int bitrixId}) async {
6869
final userId = await _getUserIdByBitrixId(bitrixId: bitrixId);
6970
if (userId == null) {
7071
return null;
@@ -74,11 +75,11 @@ class ProfileServiceImpl implements ProfileService {
7475

7576
@override
7677
Future<UserData?> getProfileByAuthorId({required int authorId}) =>
77-
getProfileByBitrixId(authorId);
78+
getProfileByBitrixId(bitrixId: authorId);
7879

7980
@override
8081
Future<UserData?> getProfileByDialogId({required int dialogId}) =>
81-
getProfileByBitrixId(dialogId);
82+
getProfileByBitrixId(bitrixId: dialogId);
8283

8384
Future<int?> _getUserIdByBitrixId({required int bitrixId}) async {
8485
final path =

lib/core/services/interfaces/profile/profile_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract interface class ProfileService {
2323
/// Возвращает [StudentData] или [EmployeeData] — наследников [UserData], или null, если:
2424
/// 1. Не удалось получить userId по bitrixId (ошибка API, отсутствие id в ответе)
2525
/// 2. Не вышло получить профиль по найденному userId (ошибка API, некорректный ответ, ошибка декодирования)
26-
Future<UserData?> getProfileByBitrixId(int bitrixId);
26+
Future<UserData?> getProfileByBitrixId({required int bitrixId});
2727

2828
/// Получает профиль по id автора поста или комменатрия
2929
///

0 commit comments

Comments
 (0)