Initial commit
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'user.dart';
|
||||
|
||||
enum BetStatus {
|
||||
active('ACTIVE'),
|
||||
awaitingValidation('AWAITING_VALIDATION'),
|
||||
completed('COMPLETED'),
|
||||
expired('EXPIRED');
|
||||
|
||||
final String value;
|
||||
const BetStatus(this.value);
|
||||
|
||||
static BetStatus fromString(String value) {
|
||||
return BetStatus.values.firstWhere(
|
||||
(e) => e.value == value,
|
||||
orElse: () => BetStatus.active,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum BetRole {
|
||||
participant('PARTICIPANT'),
|
||||
observer('OBSERVER');
|
||||
|
||||
final String value;
|
||||
const BetRole(this.value);
|
||||
|
||||
static BetRole fromString(String value) {
|
||||
return BetRole.values.firstWhere(
|
||||
(e) => e.value == value,
|
||||
orElse: () => BetRole.observer,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class BetParticipant extends Equatable {
|
||||
final User user;
|
||||
final BetRole role;
|
||||
|
||||
const BetParticipant({
|
||||
required this.user,
|
||||
required this.role,
|
||||
});
|
||||
|
||||
factory BetParticipant.fromJson(Map<String, dynamic> json) {
|
||||
return BetParticipant(
|
||||
user: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
role: BetRole.fromString(json['role'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'user': user.toJson(),
|
||||
'role': role.value,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [user, role];
|
||||
}
|
||||
|
||||
class Bet extends Equatable {
|
||||
final String id;
|
||||
final String title;
|
||||
final String description;
|
||||
final List<BetParticipant> participants;
|
||||
final BetStatus status;
|
||||
final DateTime startDate;
|
||||
final DateTime? endDate;
|
||||
final bool isPublic;
|
||||
final String? groupId;
|
||||
final String stake;
|
||||
final User? winner;
|
||||
|
||||
const Bet({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.participants,
|
||||
required this.status,
|
||||
required this.startDate,
|
||||
this.endDate,
|
||||
required this.isPublic,
|
||||
this.groupId,
|
||||
required this.stake,
|
||||
this.winner,
|
||||
});
|
||||
|
||||
factory Bet.fromJson(Map<String, dynamic> json) {
|
||||
return Bet(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
participants: (json['participants'] as List)
|
||||
.map((p) => BetParticipant.fromJson(p as Map<String, dynamic>))
|
||||
.toList(),
|
||||
status: BetStatus.fromString(json['status'] as String),
|
||||
startDate: DateTime.parse(json['startDate'] as String),
|
||||
endDate: json['endDate'] != null
|
||||
? DateTime.parse(json['endDate'] as String)
|
||||
: null,
|
||||
isPublic: json['isPublic'] as bool,
|
||||
groupId: json['groupId'] as String?,
|
||||
stake: json['stake'] as String,
|
||||
winner: json['winner'] != null
|
||||
? User.fromJson(json['winner'] as Map<String, dynamic>)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'participants': participants.map((p) => p.toJson()).toList(),
|
||||
'status': status.value,
|
||||
'startDate': startDate.toIso8601String(),
|
||||
'endDate': endDate?.toIso8601String(),
|
||||
'isPublic': isPublic,
|
||||
'groupId': groupId,
|
||||
'stake': stake,
|
||||
'winner': winner?.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
participants,
|
||||
status,
|
||||
startDate,
|
||||
endDate,
|
||||
isPublic,
|
||||
groupId,
|
||||
stake,
|
||||
winner,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'user.dart';
|
||||
|
||||
enum FriendRequestStatus {
|
||||
pending('PENDING');
|
||||
|
||||
final String value;
|
||||
const FriendRequestStatus(this.value);
|
||||
|
||||
static FriendRequestStatus fromString(String value) {
|
||||
return FriendRequestStatus.values.firstWhere(
|
||||
(e) => e.value == value,
|
||||
orElse: () => FriendRequestStatus.pending,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FriendRequest extends Equatable {
|
||||
final String id;
|
||||
final User fromUser;
|
||||
final User toUser;
|
||||
final FriendRequestStatus status;
|
||||
final DateTime createdAt;
|
||||
|
||||
const FriendRequest({
|
||||
required this.id,
|
||||
required this.fromUser,
|
||||
required this.toUser,
|
||||
required this.status,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory FriendRequest.fromJson(Map<String, dynamic> json) {
|
||||
return FriendRequest(
|
||||
id: json['id'] as String,
|
||||
fromUser: User.fromJson(json['fromUser'] as Map<String, dynamic>),
|
||||
toUser: User.fromJson(json['toUser'] as Map<String, dynamic>),
|
||||
status: FriendRequestStatus.fromString(json['status'] as String),
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'fromUser': fromUser.toJson(),
|
||||
'toUser': toUser.toJson(),
|
||||
'status': status.value,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, fromUser, toUser, status, createdAt];
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'user.dart';
|
||||
|
||||
class Group extends Equatable {
|
||||
final String id;
|
||||
final String name;
|
||||
final List<User> members;
|
||||
|
||||
const Group({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.members,
|
||||
});
|
||||
|
||||
factory Group.fromJson(Map<String, dynamic> json) {
|
||||
return Group(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
members: (json['members'] as List)
|
||||
.map((m) => User.fromJson(m as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'members': members.map((m) => m.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
Group copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
List<User>? members,
|
||||
}) {
|
||||
return Group(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
members: members ?? this.members,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, name, members];
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class User extends Equatable {
|
||||
final String id;
|
||||
final String name;
|
||||
final String email;
|
||||
final String avatarUrl;
|
||||
final double score;
|
||||
|
||||
const User({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.email,
|
||||
required this.avatarUrl,
|
||||
required this.score,
|
||||
});
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) {
|
||||
return User(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
email: json['email'] as String,
|
||||
avatarUrl: json['avatarUrl'] as String,
|
||||
score: (json['score'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'email': email,
|
||||
'avatarUrl': avatarUrl,
|
||||
'score': score,
|
||||
};
|
||||
}
|
||||
|
||||
User copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? email,
|
||||
String? avatarUrl,
|
||||
double? score,
|
||||
}) {
|
||||
return User(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
email: email ?? this.email,
|
||||
avatarUrl: avatarUrl ?? this.avatarUrl,
|
||||
score: score ?? this.score,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, name, email, avatarUrl, score];
|
||||
}
|
||||
Reference in New Issue
Block a user