-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
137 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:wealth_wave/api/apis/sip_api.dart'; | ||
import 'package:wealth_wave/domain/models/sip.dart'; | ||
|
||
class SipService { | ||
final SipApi _sipApi; | ||
|
||
SipService({final SipApi? sipApi}) : _sipApi = sipApi ?? SipApi(); | ||
|
||
Future<SIP> getBy({required final int id}) async { | ||
return _sipApi.getById(id: id).then((sipDO) { | ||
return SIP.from(sipDO: sipDO); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:wealth_wave/api/apis/transaction_api.dart'; | ||
import 'package:wealth_wave/domain/models/transaction.dart'; | ||
|
||
class TransactionService { | ||
final TransactionApi _transactionApi; | ||
|
||
TransactionService({final TransactionApi? transactionApi}) | ||
: _transactionApi = transactionApi ?? TransactionApi(); | ||
|
||
Future<Transaction> getBy({required final int id}) async { | ||
return _transactionApi.getById(id: id).then((transactionDO) { | ||
return Transaction.from(transactionDO: transactionDO); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,70 @@ | ||
import 'package:wealth_wave/contract/sip_frequency.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/services/investment_service.dart'; | ||
|
||
class SipsPresenter extends Presenter<SipsViewState> { | ||
final Investment _investment; | ||
final int _investmentId; | ||
final InvestmentService _investmentService; | ||
|
||
SipsPresenter({required final Investment investment}) | ||
: _investment = investment, | ||
SipsPresenter( | ||
{required final int investmentId, | ||
final InvestmentService? investmentService}) | ||
: _investmentId = investmentId, | ||
_investmentService = investmentService ?? InvestmentService(), | ||
super(SipsViewState()); | ||
|
||
void getSips() { | ||
_investment.getSips().then((sips) => updateViewState((viewState) { | ||
viewState.sips = sips; | ||
})); | ||
_investmentService | ||
.getBy(id: _investmentId) | ||
.then((investment) => investment.getSips()) | ||
.then((sips) => Future.wait(sips.map((sip) => SIPVO.from(sip: sip)))) | ||
.then((sipVOs) => updateViewState((viewState) { | ||
viewState.sipVOs = sipVOs; | ||
})); | ||
} | ||
|
||
void deleteSip({required final int id}) { | ||
_investment.deleteSIP(sipId: id).then((_) => getSips()); | ||
_investmentService | ||
.getBy(id: _investmentId) | ||
.then((investment) => investment.deleteSIP(sipId: id)) | ||
.then((_) => getSips()); | ||
} | ||
} | ||
|
||
class SipsViewState { | ||
List<SIP> sips = []; | ||
List<SIPVO> sipVOs = []; | ||
} | ||
|
||
class SIPVO { | ||
final int id; | ||
final int investmentId; | ||
final String? description; | ||
final double amount; | ||
final DateTime startDate; | ||
final DateTime? endDate; | ||
final SipFrequency 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}); | ||
|
||
static Future<SIPVO> from({required final SIP sip}) async { | ||
return SIPVO( | ||
id: sip.id, | ||
investmentId: sip.investmentId, | ||
description: sip.description, | ||
amount: sip.amount, | ||
startDate: sip.startDate, | ||
endDate: sip.endDate, | ||
frequency: sip.frequency, | ||
executedTill: sip.executedTill); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters