prasule/lib/api/wallet_entry.dart

51 lines
1.3 KiB
Dart
Raw Normal View History

2024-06-30 20:25:36 +02:00
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
//
// SPDX-License-Identifier: AGPL-3.0-only
2023-09-08 11:50:21 +02:00
import 'package:json_annotation/json_annotation.dart';
import 'package:prasule/api/category.dart';
import 'package:prasule/api/entry_data.dart';
part 'wallet_entry.g.dart';
2023-09-08 11:50:21 +02:00
@JsonSerializable()
/// This is an entry containing a single item
class WalletSingleEntry {
/// This is an entry containing a single item
WalletSingleEntry({
required this.data,
required this.type,
required this.date,
required this.category,
required this.id,
});
2024-07-17 16:44:02 +02:00
/// Generates a class instance from a Map
factory WalletSingleEntry.fromJson(Map<String, dynamic> json) =>
_$WalletSingleEntryFromJson(json);
2023-09-08 11:50:21 +02:00
/// Expense or income
@JsonKey(defaultValue: EntryType.expense)
EntryType type;
/// Actual entry data
@JsonKey(defaultValue: EntryData.unknown)
EntryData data;
/// Date of entry creation
@JsonKey(defaultValue: DateTime.now)
DateTime date;
/// Selected category
@JsonKey(defaultValue: WalletCategory.unknown)
WalletCategory category;
/// Unique entry ID
@JsonKey(required: true, disallowNullValue: true)
final int id;
2024-07-17 16:44:02 +02:00
/// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$WalletSingleEntryToJson(this);
2023-09-08 11:50:21 +02:00
}