cofounderella/lib/models/user_profile.dart

98 lines
3.1 KiB
Dart
Raw Normal View History

2024-05-24 00:30:08 +02:00
import 'package:cloud_firestore/cloud_firestore.dart';
import '../constants.dart';
import '../enumerations.dart';
2024-05-31 23:16:15 +02:00
import '../services/user_service.dart';
2024-05-24 00:30:08 +02:00
import 'language.dart';
import 'location.dart';
class UserProfile {
final String id;
final String uid;
final String email;
2024-05-30 16:37:34 +02:00
String name;
2024-05-24 00:30:08 +02:00
final String firstName;
final String lastName;
2024-05-30 16:37:34 +02:00
String? profilePictureUrl;
String? bio;
Gender? gender;
int? born;
2024-05-31 23:16:15 +02:00
RiskTolerance risk;
AvailabilityOption availability;
CultureOption culture;
2024-05-31 23:55:33 +02:00
CommunicationPreference communication;
2024-05-31 18:31:37 +02:00
List<SkillOption> skills;
List<SkillOption> skillsSought;
2024-05-31 23:16:15 +02:00
List<VisionOption> visions;
List<WorkValueOption> workValues;
List<Language> languages;
Map<String, MyLocation?> locations;
2024-05-24 00:30:08 +02:00
UserProfile({
required this.id,
required this.uid,
required this.email,
required this.name,
required this.firstName,
required this.lastName,
2024-05-30 16:37:34 +02:00
this.profilePictureUrl,
this.bio,
this.gender,
this.born,
2024-05-24 00:30:08 +02:00
required this.risk,
2024-05-31 23:16:15 +02:00
required this.availability,
required this.culture,
2024-05-31 23:55:33 +02:00
required this.communication,
2024-05-24 00:30:08 +02:00
required this.skills,
required this.skillsSought,
2024-05-31 23:16:15 +02:00
required this.visions,
required this.workValues,
2024-05-24 00:30:08 +02:00
required this.languages,
required this.locations,
});
factory UserProfile.fromDocument(DocumentSnapshot doc) {
Map<String, dynamic> data = doc.data() as Map<String, dynamic>;
2024-05-31 18:31:37 +02:00
List<SkillOption> skillsOffered = UserService.convertSkillStringToEnum(
data[Constants.dbFieldUsersSkills]);
List<SkillOption> skillsSought = UserService.convertSkillStringToEnum(
data[Constants.dbFieldUsersSkillsSought]);
2024-05-31 23:16:15 +02:00
List<VisionOption> visions = UserService.convertVisionStringToEnum(
data[Constants.dbFieldUsersVisions]);
List<WorkValueOption> works = UserService.convertWorkValuesStringToEnum(
data[Constants.dbFieldUsersWorkValues]);
RiskTolerance risk =
RiskTolerance.fromString(data[Constants.dbFieldUsersRiskTolerance]);
AvailabilityOption availability =
AvailabilityOption.fromString(data[Constants.dbFieldUsersAvailability]);
CultureOption culture =
CultureOption.fromString(data[Constants.dbFieldUsersCorpCulture]);
2024-05-31 23:55:33 +02:00
CommunicationPreference communication = CommunicationPreference.fromString(
data[Constants.dbFieldUsersCommunication]);
2024-05-31 18:31:37 +02:00
2024-05-24 00:30:08 +02:00
return UserProfile(
id: doc.id,
2024-05-25 13:56:45 +02:00
uid: data[Constants.dbFieldUsersID] ?? '',
2024-05-24 00:30:08 +02:00
email: data[Constants.dbFieldUsersEmail] ?? '',
name: data[Constants.dbFieldUsersName] ?? '',
firstName: data[Constants.dbFieldUsersFirstName] ?? '',
lastName: data[Constants.dbFieldUsersLastName] ?? '',
2024-05-31 18:31:37 +02:00
skills: skillsOffered,
skillsSought: skillsSought,
2024-05-31 23:16:15 +02:00
visions: visions,
risk: risk,
availability: availability,
culture: culture,
2024-05-31 23:55:33 +02:00
communication: communication,
2024-05-31 23:16:15 +02:00
workValues: works,
2024-05-30 16:37:34 +02:00
profilePictureUrl: data[Constants.dbFieldUsersProfilePic],
bio: data[Constants.dbFieldUsersBio],
gender: Gender.values[data[Constants.dbFieldUsersGender] ?? 0],
born: data[Constants.dbFieldUsersYearBorn],
2024-05-24 00:30:08 +02:00
languages: [],
locations: {},
);
}
}