cofounderella/lib/models/user_profile.dart

71 lines
2.0 KiB
Dart
Raw Normal View History

2024-05-24 00:30:08 +02:00
import 'package:cloud_firestore/cloud_firestore.dart';
2024-05-31 18:31:37 +02:00
import 'package:cofounderella/services/user_service.dart';
2024-05-24 00:30:08 +02:00
import '../constants.dart';
import '../enumerations.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-24 00:30:08 +02:00
final String risk;
2024-05-31 18:31:37 +02:00
List<SkillOption> skills;
List<SkillOption> skillsSought;
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,
required this.skills,
required this.skillsSought,
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-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-24 00:30:08 +02:00
risk: data[Constants.dbFieldUsersRiskTolerance] ?? '',
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: {},
);
}
}