Files
base_flutter/lib/features/todos/data/models/todo_model.dart
Phuoc Nguyen 38a33743e6 fix todo
2025-10-03 17:54:39 +07:00

47 lines
1.2 KiB
Dart

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,
);
}