Skip to content

Commit

Permalink
Added description
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Jan 6, 2024
1 parent 5312ee0 commit 0ba30b7
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/api/apis/goal_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GoalApi {

Future<int> createGoal(
{required final String name,
required final String? description,
required final double amount,
required final DateTime date,
required final double targetAmount,
Expand All @@ -29,6 +30,7 @@ class GoalApi {
return _db.into(_db.goalTable).insert(GoalTableCompanion.insert(
name: name,
amount: amount,
description: Value(description),
date: date,
targetAmount: targetAmount,
targetDate: targetDate,
Expand All @@ -39,6 +41,7 @@ class GoalApi {
Future<int> update(
{required final int id,
required final String name,
required final String? description,
required final double amount,
required final DateTime date,
required final double targetAmount,
Expand All @@ -48,6 +51,7 @@ class GoalApi {
return (_db.update(_db.goalTable)..where((t) => t.id.equals(id))).write(
GoalTableCompanion(
name: Value(name),
description: Value(description),
amount: Value(amount),
date: Value(date),
targetAmount: Value(targetAmount),
Expand Down
8 changes: 8 additions & 0 deletions lib/api/apis/investment_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class InvestmentApi {

Future<int> createInvestment({
required final String name,
required final String? description,
required final int? basketId,
required final RiskLevel riskLevel,
required final double value,
Expand All @@ -42,18 +43,21 @@ class InvestmentApi {
return _db.into(_db.investmentTable).insert(InvestmentTableCompanion.insert(
name: name,
basketId: Value(basketId),
description: Value(description),
value: value,
riskLevel: riskLevel,
valueUpdatedOn: valueUpdatedAt));
}

Future<int> createTransaction(
{required final int investmentId,
required final String? description,
required final double amount,
required final DateTime date}) async {
return _db.into(_db.transactionTable).insert(
TransactionTableCompanion.insert(
investmentId: investmentId,
description: Value(description),
amount: amount,
amountInvestedOn: date));
}
Expand All @@ -66,6 +70,7 @@ class InvestmentApi {
Future<int> updateInvestment({
required final int id,
required final String name,
required final String? description,
required final int? basketId,
required final RiskLevel riskLevel,
required final double value,
Expand All @@ -74,6 +79,7 @@ class InvestmentApi {
return (_db.update(_db.investmentTable)..where((t) => t.id.equals(id)))
.write(InvestmentTableCompanion(
name: Value(name),
description: Value(description),
basketId: Value(basketId),
riskLevel: Value(riskLevel),
value: Value(value),
Expand All @@ -83,11 +89,13 @@ class InvestmentApi {
Future<int> updateTransaction(
{required final int id,
required final int investmentId,
required final String? description,
required final double amount,
required final DateTime date}) async {
return (_db.update(_db.transactionTable)..where((t) => t.id.equals(id)))
.write(TransactionTableCompanion(
investmentId: Value(investmentId),
description: Value(description),
amount: Value(amount),
amountInvestedOn: Value(date),
));
Expand Down
9 changes: 9 additions & 0 deletions lib/presentation/create_goal_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CreateGoalPresenter extends Presenter<CreateGoalViewState> {
}

final name = viewState.name;
final description = viewState.description;
final amount = viewState.amount;
final date = viewState.date;
final targetAmount = viewState.getTargetAmount();
Expand All @@ -34,6 +35,7 @@ class CreateGoalPresenter extends Presenter<CreateGoalViewState> {
.update(
id: goalIdToUpdate,
name: name,
description: description,
amount: amount,
date: date,
targetAmount: targetAmount,
Expand All @@ -46,6 +48,7 @@ class CreateGoalPresenter extends Presenter<CreateGoalViewState> {
_goalApi
.createGoal(
name: name,
description: description,
amount: amount,
date: date,
targetAmount: targetAmount,
Expand All @@ -61,6 +64,10 @@ class CreateGoalPresenter extends Presenter<CreateGoalViewState> {
updateViewState((viewState) => viewState.name = text);
}

void descriptionChanged(String text) {
updateViewState((viewState) => viewState.description = text);
}

void amountChanged(String text) {
updateViewState(
(viewState) => viewState.amount = double.tryParse(text) ?? 0);
Expand All @@ -85,6 +92,7 @@ class CreateGoalPresenter extends Presenter<CreateGoalViewState> {
void setGoal(Goal goalToUpdate) {
updateViewState((viewState) {
viewState.name = goalToUpdate.name;
viewState.description = goalToUpdate.description;
viewState.amount = goalToUpdate.amount;
viewState.inflation = goalToUpdate.inflation;
viewState.importance = goalToUpdate.importance;
Expand All @@ -96,6 +104,7 @@ class CreateGoalPresenter extends Presenter<CreateGoalViewState> {

class CreateGoalViewState {
String name = '';
String? description;
double amount = 0.0;
DateTime date = DateTime.now();
DateTime targetDate = DateTime.now().add(const Duration(days: 365));
Expand Down
16 changes: 12 additions & 4 deletions lib/presentation/create_investment_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CreateInvestmentPresenter extends Presenter<CreateInvestmentViewState> {
}

final name = viewState.name;
final description = viewState.description;
final value = viewState.value;
final valueUpdatedAt = viewState._getValueUpdatedAt();
final basketId = viewState.basketId;
Expand All @@ -40,6 +41,7 @@ class CreateInvestmentPresenter extends Presenter<CreateInvestmentViewState> {
_investmentApi
.updateInvestment(
id: investmentIdToUpdate,
description: description,
name: name,
value: value,
valueUpdatedAt: valueUpdatedAt,
Expand All @@ -51,6 +53,7 @@ class CreateInvestmentPresenter extends Presenter<CreateInvestmentViewState> {
_investmentApi
.createInvestment(
name: name,
description: description,
value: value,
valueUpdatedAt: valueUpdatedAt,
basketId: basketId,
Expand All @@ -64,6 +67,10 @@ class CreateInvestmentPresenter extends Presenter<CreateInvestmentViewState> {
updateViewState((viewState) => viewState.name = text);
}

void descriptionChanged(String text) {
updateViewState((viewState) => viewState.description = text);
}

void valueChanged(String text) {
updateViewState(
(viewState) => viewState.value = double.tryParse(text) ?? 0);
Expand Down Expand Up @@ -94,6 +101,7 @@ class CreateInvestmentPresenter extends Presenter<CreateInvestmentViewState> {

class CreateInvestmentViewState {
String name = '';
String? description;
int? basketId;
RiskLevel riskLevel = RiskLevel.medium;
double value = 0.0;
Expand All @@ -102,10 +110,10 @@ class CreateInvestmentViewState {
List<BasketDO> baskets = List.empty(growable: false);

bool isValid() {
return name.isNotEmpty &&
value > 0 &&
isValidDate(valueUpdatedAt) &&
basketId != null;
return name.isNotEmpty &&
value > 0 &&
isValidDate(valueUpdatedAt) &&
basketId != null;
}

DateTime _getValueUpdatedAt() {
Expand Down
12 changes: 11 additions & 1 deletion lib/presentation/create_transaction_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ class CreateTransactionPresenter extends Presenter<CreateTransactionViewState> {
return;
}

final description = viewState.description;
final amount = viewState.amount;
final investedDate = viewState.getInvestedDate();

if (transactionIdToUpdate != null) {
_investmentApi
.updateTransaction(
id: transactionIdToUpdate,
description: description,
investmentId: investmentId,
amount: amount,
date: investedDate)
Expand All @@ -37,12 +39,19 @@ class CreateTransactionPresenter extends Presenter<CreateTransactionViewState> {
} else {
_investmentApi
.createTransaction(
investmentId: investmentId, amount: amount, date: investedDate)
investmentId: investmentId,
description: description,
amount: amount,
date: investedDate)
.then((_) => updateViewState((viewState) =>
viewState.onTransactionCreated = SingleEvent(null)));
}
}

void onDescriptionChanged(String text) {
updateViewState((viewState) => viewState.description = text);
}

void onAmountChanged(String text) {
updateViewState(
(viewState) => viewState.amount = double.tryParse(text) ?? 0);
Expand All @@ -61,6 +70,7 @@ class CreateTransactionPresenter extends Presenter<CreateTransactionViewState> {
}

class CreateTransactionViewState {
String? description;
double amount = 0.0;
String investedDate = formatDate(DateTime.now());
SingleEvent<void>? onTransactionCreated;
Expand Down
18 changes: 18 additions & 0 deletions lib/ui/widgets/create_goal_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class _CreateGoalDialog extends StatefulWidget {
class _CreateGoalPage extends PageState<CreateGoalViewState, _CreateGoalDialog,
CreateGoalPresenter> {
final _nameController = TextEditingController();
final _descriptionController = TextEditingController();
final _amountController = TextEditingController();
final _currentDateController = TextEditingController();
final _inflationController = TextEditingController();
Expand All @@ -39,6 +40,7 @@ class _CreateGoalPage extends PageState<CreateGoalViewState, _CreateGoalDialog,
Goal? goalToUpdate = widget.goalToUpdate;
if (goalToUpdate != null) {
_nameController.text = goalToUpdate.name;
_descriptionController.text = goalToUpdate.description ?? '';
_amountController.text = goalToUpdate.amount.toString();
_currentDateController.text = formatDate(goalToUpdate.createdDate);
_targetDateController.text = formatDate(goalToUpdate.targetDate);
Expand All @@ -55,6 +57,10 @@ class _CreateGoalPage extends PageState<CreateGoalViewState, _CreateGoalDialog,
presenter.nameChanged(_nameController.text);
});

_descriptionController.addListener(() {
presenter.descriptionChanged(_descriptionController.text);
});

_amountController.addListener(() {
presenter.amountChanged(_amountController.text);
});
Expand Down Expand Up @@ -100,6 +106,18 @@ class _CreateGoalPage extends PageState<CreateGoalViewState, _CreateGoalDialog,
labelText: 'Name', border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
TextFormField(
textInputAction: TextInputAction.next,
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.words,
controller: _descriptionController,
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp(r'[^a-zA-Z0-9\s]'))
],
decoration: const InputDecoration(
labelText: 'Description', border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
TextFormField(
textInputAction: TextInputAction.next,
controller: _amountController,
Expand Down
16 changes: 16 additions & 0 deletions lib/ui/widgets/create_investment_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class _CreateInvestmentDialog extends StatefulWidget {
class _CreateInvestmentPage extends PageState<CreateInvestmentViewState,
_CreateInvestmentDialog, CreateInvestmentPresenter> {
final _nameController = TextEditingController();
final _descriptionController = TextEditingController();
final _valueController = TextEditingController();
final _valueUpdatedDateController = TextEditingController();

Expand All @@ -38,6 +39,7 @@ class _CreateInvestmentPage extends PageState<CreateInvestmentViewState,
Investment? investmentToUpdate = widget.investmentToUpdate;
if (investmentToUpdate != null) {
_nameController.text = investmentToUpdate.name;
_descriptionController.text = investmentToUpdate.description ?? '';
_valueController.text = investmentToUpdate.value.toString();
_valueUpdatedDateController.text =
formatDate(investmentToUpdate.valueUpdatedOn);
Expand All @@ -50,6 +52,10 @@ class _CreateInvestmentPage extends PageState<CreateInvestmentViewState,
presenter.nameChanged(_nameController.text);
});

_descriptionController.addListener(() {
presenter.descriptionChanged(_descriptionController.text);
});

_valueController.addListener(() {
presenter.valueChanged(_valueController.text);
});
Expand Down Expand Up @@ -84,6 +90,16 @@ class _CreateInvestmentPage extends PageState<CreateInvestmentViewState,
labelText: 'Name', border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
TextFormField(
textInputAction: TextInputAction.next,
controller: _descriptionController,
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp(r'[^a-zA-Z0-9\s]'))
],
decoration: const InputDecoration(
labelText: 'Desctiption', border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
TextFormField(
textInputAction: TextInputAction.next,
controller: _valueController,
Expand Down
15 changes: 13 additions & 2 deletions lib/ui/widgets/create_transaction_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class _CreateTransactionDialog extends StatefulWidget {

class _CreateTransactionPage extends PageState<CreateTransactionViewState,
_CreateTransactionDialog, CreateTransactionPresenter> {
final _descriptionController = TextEditingController();
final _valueController = TextEditingController();
final _valueUpdatedDateController = TextEditingController();

Expand All @@ -40,19 +41,23 @@ class _CreateTransactionPage extends PageState<CreateTransactionViewState,

TransactionDO? transactionToUpdate = widget.transactionToUpdate;
if (transactionToUpdate != null) {
_descriptionController.text = transactionToUpdate.description ?? '';
_valueController.text = transactionToUpdate.amount.toString();
_valueUpdatedDateController.text =
formatDate(transactionToUpdate.amountInvestedOn);
presenter.setTransaction(transactionToUpdate);
} else {
_valueUpdatedDateController.text =
formatDate(DateTime.now());
_valueUpdatedDateController.text = formatDate(DateTime.now());
}

_valueController.addListener(() {
presenter.onAmountChanged(_valueController.text);
});

_descriptionController.addListener(() {
presenter.onDescriptionChanged(_descriptionController.text);
});

_valueUpdatedDateController.addListener(() {
presenter.transactionDateChanged(_valueUpdatedDateController.text);
});
Expand Down Expand Up @@ -91,6 +96,12 @@ class _CreateTransactionPage extends PageState<CreateTransactionViewState,
],
content: SingleChildScrollView(
child: Column(children: <Widget>[
TextFormField(
textInputAction: TextInputAction.next,
controller: _descriptionController,
decoration: const InputDecoration(
labelText: 'Description', border: OutlineInputBorder()),
),
TextFormField(
textInputAction: TextInputAction.next,
controller: _valueController,
Expand Down

0 comments on commit 0ba30b7

Please sign in to comment.