51 lines
2.0 KiB
Dart
51 lines
2.0 KiB
Dart
|
import 'dart:convert';
|
||
|
import 'package:http/http.dart' as http;
|
||
|
import 'package:unit2/model/login_data/employee_info/employee_info.dart';
|
||
|
import 'package:unit2/model/profile/basic_info.dart';
|
||
|
import 'package:unit2/model/profile/basic_information/contact_information.dart';
|
||
|
import 'package:unit2/model/profile/profileInfomation.dart';
|
||
|
import 'package:unit2/utils/request.dart';
|
||
|
import 'package:unit2/utils/urls.dart';
|
||
|
|
||
|
import '../../model/profile/basic_information/primary-information.dart';
|
||
|
|
||
|
class ProfileService {
|
||
|
static final ProfileService _instance = ProfileService();
|
||
|
static ProfileService get instance => _instance;
|
||
|
|
||
|
Future<ProfileInformation?> getProfile(String token, int id) async {
|
||
|
String url = Url.instance.profileInformation();
|
||
|
String path = url + id.toString();
|
||
|
ProfileInformation? _profileInformation;
|
||
|
ContactInfo contactInfo;
|
||
|
List<ContactInfo> contactInformation = [];
|
||
|
PrimaryInformation primaryInformation;
|
||
|
Map<String, String> headers = {
|
||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||
|
'Authorization': "Token $token"
|
||
|
};
|
||
|
try{
|
||
|
http.Response response = await Request.instance
|
||
|
.getRequest(path: path, param: {}, headers: headers);
|
||
|
if (response.statusCode == 200) {
|
||
|
Map data = jsonDecode(response.body);
|
||
|
// get primary information
|
||
|
primaryInformation = PrimaryInformation.fromJson(
|
||
|
data['data']['basic_information']['primary_information']);
|
||
|
// get all contacts
|
||
|
data['data']['basic_information']['contact_information']
|
||
|
.forEach((var contact) {
|
||
|
contactInfo = ContactInfo.fromJson(contact['contact_info']);
|
||
|
contactInformation.add(contactInfo);
|
||
|
});
|
||
|
BasicInfo basicInfo = BasicInfo(contactInformation: contactInformation, primaryInformation: primaryInformation);
|
||
|
ProfileInformation profileInformation = ProfileInformation(basicInfo: basicInfo);
|
||
|
_profileInformation = profileInformation;
|
||
|
}
|
||
|
}catch(e){
|
||
|
throw(e.toString());
|
||
|
}
|
||
|
return _profileInformation;
|
||
|
}
|
||
|
}
|