Commit 98c97045 authored by Nina Rybárová's avatar Nina Rybárová
Browse files

updated model

parent 80977801
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -6,8 +6,7 @@ part 'note.g.dart';
@JsonSerializable(explicitToJson: true, includeIfNull: false)
final class Note implements Identifiable {
  static const TITLE_KEY = 'title';

  static const MESSAGE_KEY = 'message';
  static const DESCRIPTION_KEY = 'description';
  static const CREATED_AT_KEY = 'createdAt';
  static const AUTHOR_KEY = 'username';
  @override
@@ -16,18 +15,32 @@ final class Note implements Identifiable {
  @JsonKey(name: TITLE_KEY)
  final String title;

  @JsonKey(name: MESSAGE_KEY)
  final String message;
  @JsonKey(name: DESCRIPTION_KEY)
  final String description;

  @JsonKey(name: CREATED_AT_KEY)
  final DateTime createdAt;

  const Note({
  Note({
    required this.id,
    required this.title,
    required this.message,
    required this.createdAt,
  });
    required this.description,
    DateTime? createdAt,
  }) : createdAt = createdAt ?? DateTime.now();

  Note copyWith({
    String? id,
    String? title,
    String? description,
    DateTime? createdAt,
  }) {
    return Note(
      id: id ?? this.id,
      title: title ?? this.title,
      description: description ?? this.description,
      createdAt: createdAt ?? this.createdAt,
    );
  }

  @override
  bool operator ==(Object other) =>
+2 −2
Original line number Diff line number Diff line
@@ -9,13 +9,13 @@ part of 'note.dart';
Note _$NoteFromJson(Map<String, dynamic> json) => Note(
      id: json['id'] as String,
      title: json['title'] as String,
      message: json['message'] as String,
      description: json['description'] as String,
      createdAt: DateTime.parse(json['createdAt'] as String),
    );

Map<String, dynamic> _$NoteToJson(Note instance) => <String, dynamic>{
      'id': instance.id,
      'title': instance.title,
      'message': instance.message,
      'description': instance.description,
      'createdAt': instance.createdAt.toIso8601String(),
    };