fix todo
This commit is contained in:
46
lib/features/todos/data/models/todo_model.dart
Normal file
46
lib/features/todos/data/models/todo_model.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import '../../domain/entities/todo.dart';
|
||||
|
||||
part 'todo_model.freezed.dart';
|
||||
part 'todo_model.g.dart';
|
||||
|
||||
@freezed
|
||||
class TodoModel with _$TodoModel {
|
||||
const factory TodoModel({
|
||||
required int id,
|
||||
required String title,
|
||||
String? description,
|
||||
required bool completed,
|
||||
required String userId,
|
||||
@JsonKey(includeFromJson: false, includeToJson: false) Map<String, dynamic>? user,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) = _TodoModel;
|
||||
|
||||
const TodoModel._();
|
||||
|
||||
factory TodoModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$TodoModelFromJson(json);
|
||||
|
||||
/// Convert to domain entity
|
||||
Todo toEntity() => Todo(
|
||||
id: id,
|
||||
title: title,
|
||||
description: description,
|
||||
completed: completed,
|
||||
userId: userId,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
/// Create from domain entity
|
||||
factory TodoModel.fromEntity(Todo todo) => TodoModel(
|
||||
id: todo.id,
|
||||
title: todo.title,
|
||||
description: todo.description,
|
||||
completed: todo.completed,
|
||||
userId: todo.userId,
|
||||
createdAt: todo.createdAt,
|
||||
updatedAt: todo.updatedAt,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user