Skip to content

Commit

Permalink
move InvestmentVO to model class
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Jun 29, 2024
1 parent 44e7cc7 commit 61009b8
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 68 deletions.
68 changes: 68 additions & 0 deletions lib/ui/models/investment_vo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:wealth_wave/contract/risk_level.dart';
import 'package:wealth_wave/domain/models/investment.dart';
import 'package:wealth_wave/ui/models/sip_vo.dart';
import 'package:wealth_wave/ui/models/transaction_vo.dart';

class InvestmentVO {
final int id;
final String name;
final String? description;
final RiskLevel riskLevel;
final double irr;
final double investedValue;
final double currentValue;
final DateTime? valueUpdatedDate;
final double qty;
final double valuePerQty;
final DateTime? maturityDate;
final int? basketId;
final String? basketName;
final List<SipVO> sips;
final List<TransactionVO> transactions;
final int taggedGoalCount;
final bool hasScript;

int get transactionCount => transactions.length;
int get sipCount => sips.length;
String get valueUpdateDate => valueUpdatedDate?.toIso8601String() ?? 'Not Updated';

InvestmentVO._(
{required this.id,
required this.name,
required this.description,
required this.riskLevel,
required this.irr,
required this.basketId,
required this.basketName,
required this.investedValue,
required this.currentValue,
required this.valueUpdatedDate,
required this.qty,
required this.valuePerQty,
required this.maturityDate,
required this.transactions,
required this.sips,
required this.hasScript,
required this.taggedGoalCount});

factory InvestmentVO.from({required final Investment investment}) {
return InvestmentVO._(
id: investment.id,
name: investment.name,
description: investment.description,
riskLevel: investment.riskLevel,
irr: investment.getIRR(),
investedValue: investment.getTotalInvestedAmount(),
currentValue: investment.getValue(),
valueUpdatedDate: investment.valueUpdatedOn,
qty: investment.qty,
valuePerQty: investment.getValuePerUnit(),
basketId: investment.basketId,
basketName: investment.basketName,
transactions: investment.transactions.map((e) => TransactionVO.from(transaction: e)).toList(),
sips: investment.sips.map((e) => SipVO.from(transaction: e)).toList(),
taggedGoalCount: investment.goalsCount,
hasScript: investment.script != null,
maturityDate: investment.maturityDate);
}
}
35 changes: 35 additions & 0 deletions lib/ui/models/sip_vo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:wealth_wave/contract/frequency.dart';
import 'package:wealth_wave/domain/models/sip.dart';

class SipVO {
final int id;
final int investmentId;
final String? description;
final double amount;
final DateTime startDate;
final DateTime? endDate;
final Frequency frequency;
final DateTime? executedTill;

SipVO._(
{required this.id,
required this.investmentId,
required this.description,
required this.amount,
required this.startDate,
required this.endDate,
required this.frequency,
required this.executedTill});

factory SipVO.from({required final Sip transaction}) {
return SipVO._(
id: transaction.id,
investmentId: transaction.investmentId,
description: transaction.description,
amount: transaction.amount,
startDate: transaction.startDate,
endDate: transaction.endDate,
frequency: transaction.frequency,
executedTill: transaction.executedTill);
}
}
28 changes: 28 additions & 0 deletions lib/ui/models/transaction_vo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:wealth_wave/domain/models/transaction.dart';

class TransactionVO {
final int id;
final int investmentId;
final int? sipId;
final String? description;
final double amount;
final DateTime createdOn;

TransactionVO._(
{required this.id,
required this.investmentId,
required this.sipId,
required this.description,
required this.amount,
required this.createdOn});

factory TransactionVO.from({required final Transaction transaction}) {
return TransactionVO._(
id: transaction.id,
investmentId: transaction.investmentId,
sipId: transaction.sipId,
description: transaction.description,
amount: transaction.amount,
createdOn: transaction.createdOn);
}
}
1 change: 1 addition & 0 deletions lib/ui/pages/investments_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/rendering.dart';
import 'package:intl/intl.dart';
import 'package:wealth_wave/contract/risk_level.dart';
import 'package:wealth_wave/core/page_state.dart';
import 'package:wealth_wave/ui/models/investment_vo.dart';
import 'package:wealth_wave/ui/presentation/investments_presenter.dart';
import 'package:wealth_wave/ui/app_dimen.dart';
import 'package:wealth_wave/ui/nav_path.dart';
Expand Down
69 changes: 1 addition & 68 deletions lib/ui/presentation/investments_presenter.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'package:wealth_wave/contract/risk_level.dart';
import 'package:wealth_wave/core/presenter.dart';
import 'package:wealth_wave/domain/models/investment.dart';
import 'package:wealth_wave/domain/models/sip.dart';
import 'package:wealth_wave/domain/models/transaction.dart';
import 'package:wealth_wave/domain/services/investment_service.dart';
import 'package:wealth_wave/ui/models/investment_vo.dart';

class InvestmentsPresenter extends Presenter<InvestmentsViewState> {
final InvestmentService _investmentService;
Expand Down Expand Up @@ -107,70 +104,6 @@ class InvestmentsViewState {
}
}

class InvestmentVO {
final int id;
final String name;
final String? description;
final RiskLevel riskLevel;
final double irr;
final double investedValue;
final double currentValue;
final DateTime? valueUpdatedDate;
final double qty;
final double valuePerQty;
final DateTime? maturityDate;
final int? basketId;
final String? basketName;
final List<Sip> sips;
final List<Transaction> transactions;
final int taggedGoalCount;
final bool hasScript;

int get transactionCount => transactions.length;
int get sipCount => sips.length;
String get valueUpdateDate => valueUpdatedDate?.toIso8601String() ?? 'Not Updated';

InvestmentVO._(
{required this.id,
required this.name,
required this.description,
required this.riskLevel,
required this.irr,
required this.basketId,
required this.basketName,
required this.investedValue,
required this.currentValue,
required this.valueUpdatedDate,
required this.qty,
required this.valuePerQty,
required this.maturityDate,
required this.transactions,
required this.sips,
required this.hasScript,
required this.taggedGoalCount});

factory InvestmentVO.from({required final Investment investment}) {
return InvestmentVO._(
id: investment.id,
name: investment.name,
description: investment.description,
riskLevel: investment.riskLevel,
irr: investment.getIRR(),
investedValue: investment.getTotalInvestedAmount(),
currentValue: investment.getValue(),
valueUpdatedDate: investment.valueUpdatedOn,
qty: investment.qty,
valuePerQty: investment.getValuePerUnit(),
basketId: investment.basketId,
basketName: investment.basketName,
transactions: investment.transactions,
sips: investment.sips,
taggedGoalCount: investment.goalsCount,
hasScript: investment.script != null,
maturityDate: investment.maturityDate);
}
}

enum SortBy {
name,
value,
Expand Down

0 comments on commit 61009b8

Please sign in to comment.