fix: create basic debt class structure

This commit is contained in:
Matyáš Caras 2024-07-17 16:44:02 +02:00
parent 94eb563217
commit d93eac4f04
Signed by: hernik
GPG key ID: 2A3175F98820C5C6
16 changed files with 186 additions and 35 deletions

View file

@ -18,7 +18,7 @@ class WalletCategory {
required this.color, required this.color,
}); });
/// Connects the generated fromJson method /// Generates a class instance from a Map
factory WalletCategory.fromJson(Map<String, dynamic> json) => factory WalletCategory.fromJson(Map<String, dynamic> json) =>
_$WalletCategoryFromJson(json); _$WalletCategoryFromJson(json);
@ -36,7 +36,7 @@ class WalletCategory {
@JsonKey(fromJson: _colorFromJson, toJson: _colorToJson) @JsonKey(fromJson: _colorFromJson, toJson: _colorToJson)
Color color; Color color;
/// Connects the generated toJson method /// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$WalletCategoryToJson(this); Map<String, dynamic> toJson() => _$WalletCategoryToJson(this);
@override @override

View file

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
//
// SPDX-License-Identifier: AGPL-3.0-only
// GENERATED CODE - DO NOT MODIFY BY HAND // GENERATED CODE - DO NOT MODIFY BY HAND
part of 'category.dart'; part of 'category.dart';
@ -13,9 +9,9 @@ part of 'category.dart';
WalletCategory _$WalletCategoryFromJson(Map<String, dynamic> json) => WalletCategory _$WalletCategoryFromJson(Map<String, dynamic> json) =>
WalletCategory( WalletCategory(
name: json['name'] as String, name: json['name'] as String,
id: json['id'] as int, id: (json['id'] as num).toInt(),
icon: _iconDataFromJson(json['icon'] as Map<String, dynamic>), icon: _iconDataFromJson(json['icon'] as Map<String, dynamic>),
color: _colorFromJson(json['color'] as int), color: _colorFromJson((json['color'] as num).toInt()),
); );
Map<String, dynamic> _$WalletCategoryToJson(WalletCategory instance) => Map<String, dynamic> _$WalletCategoryToJson(WalletCategory instance) =>

38
lib/api/debt_entry.dart Normal file
View file

@ -0,0 +1,38 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:prasule/api/debt_person.dart';
part 'debt_entry.g.dart';
/// Single transaction
///
/// The debt will be split between people who are not in [whoPayed]
@JsonSerializable()
class DebtEntry {
/// Single transaction
///
/// The debt will be split between people who are not in [whoPayed]
DebtEntry({
required this.id,
required this.amount,
required this.name,
required this.whoPayed,
}) : assert(whoPayed.isNotEmpty, "There has to be at least one payer");
/// Generates a class instance from a Map
factory DebtEntry.fromJson(Map<String, dynamic> json) =>
_$DebtEntryFromJson(json);
/// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$DebtEntryToJson(this);
/// Unique identifier
final int id;
/// The payed amount
int amount;
/// User-friendly identifier for the transaction
String name;
/// List of people who payed
List<DebtPerson> whoPayed;
}

23
lib/api/debt_entry.g.dart Normal file
View file

@ -0,0 +1,23 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'debt_entry.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
DebtEntry _$DebtEntryFromJson(Map<String, dynamic> json) => DebtEntry(
id: (json['id'] as num).toInt(),
amount: (json['amount'] as num).toInt(),
name: json['name'] as String,
whoPayed: (json['whoPayed'] as List<dynamic>)
.map((e) => DebtPerson.fromJson(e as Map<String, dynamic>))
.toList(),
);
Map<String, dynamic> _$DebtEntryToJson(DebtEntry instance) => <String, dynamic>{
'id': instance.id,
'amount': instance.amount,
'name': instance.name,
'whoPayed': instance.whoPayed,
};

23
lib/api/debt_person.dart Normal file
View file

@ -0,0 +1,23 @@
import 'package:json_annotation/json_annotation.dart';
part 'debt_person.g.dart';
@JsonSerializable()
/// Represents a single person in a debt scenario
class DebtPerson {
/// Represents a single person in a debt scenario
DebtPerson({required this.id, required this.name});
/// Generates a class instance from a Map
factory DebtPerson.fromJson(Map<String, dynamic> json) =>
_$DebtPersonFromJson(json);
/// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$DebtPersonToJson(this);
/// Unique identifier
final int id;
/// Identifier that the user will see
String name;
}

View file

@ -0,0 +1,18 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'debt_person.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
DebtPerson _$DebtPersonFromJson(Map<String, dynamic> json) => DebtPerson(
id: (json['id'] as num).toInt(),
name: json['name'] as String,
);
Map<String, dynamic> _$DebtPersonToJson(DebtPerson instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
};

View file

@ -0,0 +1,39 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:prasule/api/debt_entry.dart';
import 'package:prasule/api/debt_person.dart';
part 'debt_scenario.g.dart';
/// A folder for different entries and people
@JsonSerializable()
class DebtScenario {
/// A folder for different entries and people
DebtScenario({
required this.id,
required this.name,
required this.isArchived,
this.entries = const [],
this.people = const [],
});
/// Generates a class instance from a Map
factory DebtScenario.fromJson(Map<String, dynamic> json) =>
_$DebtScenarioFromJson(json);
/// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$DebtScenarioToJson(this);
/// Unique identified
final int id;
/// User-friendly identifier
String name;
/// Whether this scenario should be shown under archived ones
bool isArchived;
/// All entries
List<DebtEntry> entries;
/// All people
List<DebtPerson> people;
}

View file

@ -0,0 +1,30 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'debt_scenario.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
DebtScenario _$DebtScenarioFromJson(Map<String, dynamic> json) => DebtScenario(
id: (json['id'] as num).toInt(),
name: json['name'] as String,
isArchived: json['isArchived'] as bool,
entries: (json['entries'] as List<dynamic>?)
?.map((e) => DebtEntry.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
people: (json['people'] as List<dynamic>?)
?.map((e) => DebtPerson.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
);
Map<String, dynamic> _$DebtScenarioToJson(DebtScenario instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
'isArchived': instance.isArchived,
'entries': instance.entries,
'people': instance.people,
};

View file

@ -11,7 +11,7 @@ class EntryData {
/// Contains raw data /// Contains raw data
EntryData({required this.name, required this.amount, this.description = ""}); EntryData({required this.name, required this.amount, this.description = ""});
/// Connects the generated fromJson method /// Generates a class instance from a Map
factory EntryData.fromJson(Map<String, dynamic> json) => factory EntryData.fromJson(Map<String, dynamic> json) =>
_$EntryDataFromJson(json); _$EntryDataFromJson(json);
@ -24,6 +24,6 @@ class EntryData {
/// Amount for entry /// Amount for entry
double amount; double amount;
/// Connects the generated toJson method /// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$EntryDataToJson(this); Map<String, dynamic> toJson() => _$EntryDataToJson(this);
} }

View file

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
//
// SPDX-License-Identifier: AGPL-3.0-only
// GENERATED CODE - DO NOT MODIFY BY HAND // GENERATED CODE - DO NOT MODIFY BY HAND
part of 'entry_data.dart'; part of 'entry_data.dart';

View file

@ -24,11 +24,11 @@ class RecurringWalletEntry extends WalletSingleEntry {
this.repeatAfter = 1, this.repeatAfter = 1,
}); });
/// Connects the generated fromJson method /// Generates a class instance from a Map
factory RecurringWalletEntry.fromJson(Map<String, dynamic> json) => factory RecurringWalletEntry.fromJson(Map<String, dynamic> json) =>
_$RecurringWalletEntryFromJson(json); _$RecurringWalletEntryFromJson(json);
/// Connects the generated toJson method /// Converts the data in this instance into a Map
@override @override
Map<String, dynamic> toJson() => _$RecurringWalletEntryToJson(this); Map<String, dynamic> toJson() => _$RecurringWalletEntryToJson(this);

View file

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
//
// SPDX-License-Identifier: AGPL-3.0-only
// GENERATED CODE - DO NOT MODIFY BY HAND // GENERATED CODE - DO NOT MODIFY BY HAND
part of 'recurring_entry.dart'; part of 'recurring_entry.dart';
@ -18,10 +14,10 @@ RecurringWalletEntry _$RecurringWalletEntryFromJson(
date: DateTime.parse(json['date'] as String), date: DateTime.parse(json['date'] as String),
category: category:
WalletCategory.fromJson(json['category'] as Map<String, dynamic>), WalletCategory.fromJson(json['category'] as Map<String, dynamic>),
id: json['id'] as int, id: (json['id'] as num).toInt(),
lastRunDate: DateTime.parse(json['lastRunDate'] as String), lastRunDate: DateTime.parse(json['lastRunDate'] as String),
repeatAfter: json['repeatAfter'] as int,
recurType: $enumDecode(_$RecurTypeEnumMap, json['recurType']), recurType: $enumDecode(_$RecurTypeEnumMap, json['recurType']),
repeatAfter: (json['repeatAfter'] as num?)?.toInt() ?? 1,
); );
Map<String, dynamic> _$RecurringWalletEntryToJson( Map<String, dynamic> _$RecurringWalletEntryToJson(

View file

@ -34,7 +34,7 @@ class Wallet {
this.starterBalance = 0, this.starterBalance = 0,
}); });
/// Connects the generated fromJson method /// Generates a class instance from a Map
factory Wallet.fromJson(Map<String, dynamic> json) => _$WalletFromJson(json); factory Wallet.fromJson(Map<String, dynamic> json) => _$WalletFromJson(json);
/// A list of all [RecurringWalletEntry]s /// A list of all [RecurringWalletEntry]s
@ -58,7 +58,7 @@ class Wallet {
@JsonKey(fromJson: _currencyFromJson) @JsonKey(fromJson: _currencyFromJson)
final Currency currency; final Currency currency;
/// Connects the generated toJson method /// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$WalletToJson(this); Map<String, dynamic> toJson() => _$WalletToJson(this);
/// Getter for the next unused unique number ID in the wallet's **entry** list /// Getter for the next unused unique number ID in the wallet's **entry** list

View file

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
//
// SPDX-License-Identifier: AGPL-3.0-only
// GENERATED CODE - DO NOT MODIFY BY HAND // GENERATED CODE - DO NOT MODIFY BY HAND
part of 'wallet.dart'; part of 'wallet.dart';

View file

@ -21,7 +21,7 @@ class WalletSingleEntry {
required this.id, required this.id,
}); });
/// Connects the generated fromJson method /// Generates a class instance from a Map
factory WalletSingleEntry.fromJson(Map<String, dynamic> json) => factory WalletSingleEntry.fromJson(Map<String, dynamic> json) =>
_$WalletSingleEntryFromJson(json); _$WalletSingleEntryFromJson(json);
@ -40,6 +40,6 @@ class WalletSingleEntry {
/// Unique entry ID /// Unique entry ID
int id; int id;
/// Connects the generated toJson method /// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$WalletSingleEntryToJson(this); Map<String, dynamic> toJson() => _$WalletSingleEntryToJson(this);
} }

View file

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
//
// SPDX-License-Identifier: AGPL-3.0-only
// GENERATED CODE - DO NOT MODIFY BY HAND // GENERATED CODE - DO NOT MODIFY BY HAND
part of 'wallet_entry.dart'; part of 'wallet_entry.dart';
@ -17,7 +13,7 @@ WalletSingleEntry _$WalletSingleEntryFromJson(Map<String, dynamic> json) =>
date: DateTime.parse(json['date'] as String), date: DateTime.parse(json['date'] as String),
category: category:
WalletCategory.fromJson(json['category'] as Map<String, dynamic>), WalletCategory.fromJson(json['category'] as Map<String, dynamic>),
id: json['id'] as int, id: (json['id'] as num).toInt(),
); );
Map<String, dynamic> _$WalletSingleEntryToJson(WalletSingleEntry instance) => Map<String, dynamic> _$WalletSingleEntryToJson(WalletSingleEntry instance) =>