Line data Source code
1 : class User {
2 : final String id;
3 : final String email;
4 : final String name;
5 : final String role;
6 : final String? profileImage;
7 : final String? clubId;
8 : final String? clubRole;
9 :
10 0 : User({
11 : required this.id,
12 : required this.email,
13 : required this.name,
14 : required this.role,
15 : this.profileImage,
16 : this.clubId,
17 : this.clubRole,
18 : });
19 :
20 : // JSON 데이터로부터 User 객체 생성
21 0 : factory User.fromJson(Map<String, dynamic> json) {
22 0 : return User(
23 0 : id: json['id'] != null ? json['id'].toString() : '',
24 0 : email: json['email'] ?? '',
25 0 : name: json['name'] ?? '',
26 0 : role: json['role'] ?? 'user',
27 0 : profileImage: json['profileImage'],
28 0 : clubId: json['clubId']?.toString(),
29 0 : clubRole: json['clubRole'],
30 : );
31 : }
32 :
33 : // User 객체를 JSON으로 변환
34 0 : Map<String, dynamic> toJson() {
35 0 : return {
36 0 : 'id': id,
37 0 : 'email': email,
38 0 : 'name': name,
39 0 : 'role': role,
40 0 : 'profileImage': profileImage,
41 0 : 'clubId': clubId,
42 0 : 'clubRole': clubRole,
43 : };
44 : }
45 : }
|