mirror of
https://github.com/Dvorinka/1356.git
synced 2026-06-04 03:52:57 +00:00
Added core data models, repositories, and utilities
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class Activity extends Equatable {
|
||||
final String id;
|
||||
final String userId;
|
||||
final String type;
|
||||
final Map<String, dynamic>? payload;
|
||||
final DateTime createdAt;
|
||||
|
||||
const Activity({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.type,
|
||||
this.payload,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
Activity copyWith({
|
||||
String? id,
|
||||
String? userId,
|
||||
String? type,
|
||||
Map<String, dynamic>? payload,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return Activity(
|
||||
id: id ?? this.id,
|
||||
userId: userId ?? this.userId,
|
||||
type: type ?? this.type,
|
||||
payload: payload ?? this.payload,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'user_id': userId,
|
||||
'type': type,
|
||||
'payload': payload,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
factory Activity.fromJson(Map<String, dynamic> json) {
|
||||
return Activity(
|
||||
id: json['id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
type: json['type'] as String,
|
||||
payload: json['payload'] as Map<String, dynamic>?,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, userId, type, payload, createdAt];
|
||||
}
|
||||
@@ -78,4 +78,38 @@ class Goal extends Equatable {
|
||||
createdAt,
|
||||
updatedAt,
|
||||
];
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'owner_id': ownerId,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'progress': progress,
|
||||
'location_lat': locationLat,
|
||||
'location_lng': locationLng,
|
||||
'location_name': locationName,
|
||||
'image_url': imageUrl,
|
||||
'completed': completed,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'updated_at': updatedAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
factory Goal.fromJson(Map<String, dynamic> json) {
|
||||
return Goal(
|
||||
id: json['id'] as String,
|
||||
ownerId: json['owner_id'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String?,
|
||||
progress: json['progress'] as int? ?? 0,
|
||||
locationLat: json['location_lat'] as double?,
|
||||
locationLng: json['location_lng'] as double?,
|
||||
locationName: json['location_name'] as String?,
|
||||
imageUrl: json['image_url'] as String?,
|
||||
completed: json['completed'] as bool? ?? false,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class GoalStep extends Equatable {
|
||||
final String id;
|
||||
final String goalId;
|
||||
final String title;
|
||||
final bool isDone;
|
||||
final int orderIndex;
|
||||
final DateTime createdAt;
|
||||
|
||||
const GoalStep({
|
||||
required this.id,
|
||||
required this.goalId,
|
||||
required this.title,
|
||||
required this.isDone,
|
||||
required this.orderIndex,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
GoalStep copyWith({
|
||||
String? id,
|
||||
String? goalId,
|
||||
String? title,
|
||||
bool? isDone,
|
||||
int? orderIndex,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return GoalStep(
|
||||
id: id ?? this.id,
|
||||
goalId: goalId ?? this.goalId,
|
||||
title: title ?? this.title,
|
||||
isDone: isDone ?? this.isDone,
|
||||
orderIndex: orderIndex ?? this.orderIndex,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'goal_id': goalId,
|
||||
'title': title,
|
||||
'is_done': isDone,
|
||||
'order_index': orderIndex,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
factory GoalStep.fromJson(Map<String, dynamic> json) {
|
||||
return GoalStep(
|
||||
id: json['id'] as String,
|
||||
goalId: json['goal_id'] as String,
|
||||
title: json['title'] as String,
|
||||
isDone: json['is_done'] as bool? ?? false,
|
||||
orderIndex: json['order_index'] as int? ?? 0,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, goalId, title, isDone, orderIndex, createdAt];
|
||||
}
|
||||
@@ -76,4 +76,38 @@ class User extends Equatable {
|
||||
createdAt,
|
||||
updatedAt,
|
||||
];
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'username': username,
|
||||
'email': email,
|
||||
'avatar_url': avatarUrl,
|
||||
'bio': bio,
|
||||
'is_public_profile': isPublicProfile,
|
||||
'countdown_start_date': countdownStartDate?.toIso8601String(),
|
||||
'countdown_end_date': countdownEndDate?.toIso8601String(),
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'updated_at': updatedAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) {
|
||||
return User(
|
||||
id: json['id'] as String,
|
||||
username: json['username'] as String,
|
||||
email: json['email'] as String,
|
||||
avatarUrl: json['avatar_url'] as String?,
|
||||
bio: json['bio'] as String?,
|
||||
isPublicProfile: json['is_public_profile'] as bool? ?? false,
|
||||
countdownStartDate: json['countdown_start_date'] != null
|
||||
? DateTime.parse(json['countdown_start_date'] as String)
|
||||
: null,
|
||||
countdownEndDate: json['countdown_end_date'] != null
|
||||
? DateTime.parse(json['countdown_end_date'] as String)
|
||||
: null,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user