-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/transaction details domain data #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
21fb201
453ba32
8ad89a3
218c83d
59a3b51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| import 'package:moneyplus/data/repository/utils/fake_data.dart'; | ||
| import 'package:moneyplus/data/service/supabase_service.dart'; | ||
| import 'package:moneyplus/domain/entity/transaction.dart'; | ||
| import 'package:moneyplus/domain/entity/transaction_category.dart'; | ||
| import 'package:moneyplus/domain/entity/transaction_type.dart'; | ||
| import 'package:moneyplus/domain/repository/model/top_spending_category.dart'; | ||
| import 'package:moneyplus/domain/repository/transaction_repository.dart'; | ||
| import 'package:supabase_flutter/supabase_flutter.dart'; | ||
|
|
||
| class TransactionRepositoryStub implements TransactionRepository { | ||
| final SupabaseService service; | ||
|
|
||
| TransactionRepositoryStub(this.service); | ||
|
|
||
| @override | ||
| Future<bool> addTransaction({ | ||
| required double amount, | ||
|
|
@@ -30,8 +37,17 @@ class TransactionRepositoryStub implements TransactionRepository { | |
| } | ||
|
|
||
| @override | ||
| Future<bool> deleteTransaction(int id) async { | ||
| throw UnimplementedError('deleteTransaction not implemented'); | ||
| Future<void> deleteTransaction(String id) async { | ||
| final client = await service.getClient(); | ||
|
|
||
| final response = await client.rpc( | ||
| 'delete_transaction', | ||
| params: {'p_id': id}, | ||
| ); | ||
| print("respinse of deleting is : $response"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove the print statement |
||
| if(response == null || response['id'] == null){ | ||
| throw Exception("cannot delete transaction with id: $id "); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -44,8 +60,63 @@ class TransactionRepositoryStub implements TransactionRepository { | |
| } | ||
|
|
||
| @override | ||
| Future<Transaction> getTransactionDetails(int id) async { | ||
| throw UnimplementedError('getTransactionDetails not implemented'); | ||
| Future<Transaction> getTransactionDetails(String id) async { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider using our |
||
| final client = await service.getClient(); | ||
| final response = await client.rpc( | ||
| 'get_transaction_details', | ||
| params: {'p_id': id}, | ||
| ); | ||
| final data = response as Map<String, dynamic>; | ||
| if (data.isEmpty) { | ||
| throw Exception("no transaction with that id: $id"); | ||
| } | ||
| final transactionType = ((data['transaction_type'] as int) == 1) | ||
| ? TransactionType.income | ||
| : TransactionType.expense; | ||
| return Transaction( | ||
| id: 0, | ||
| amount: (data['amount'] as num).toDouble(), | ||
| currency: await _getCurrencyAbbreviation(data['currency_id'] as int), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use join on backend to retrive what you need |
||
| type: transactionType, | ||
| date: DateTime.parse(data['created_at']).toLocal(), | ||
| category: TransactionCategory( | ||
| id: data['category_id'] as int, | ||
| name: await _getCategoryName((data['category_id'] as int).toString()), | ||
| ), | ||
| note: data['note'] as String, | ||
| ); | ||
| } | ||
|
|
||
| Future<String> _getCurrencyAbbreviation(int currencyId) async { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for this function |
||
| final client = await service.getClient(); | ||
|
|
||
| final response = await client | ||
| .from('currencies') | ||
| .select('abbreviation') | ||
| .eq('id', currencyId) | ||
| .maybeSingle(); | ||
|
|
||
| if (response == null) { | ||
| throw Exception("No currency found with id: $currencyId"); | ||
| } | ||
|
|
||
| return response['abbreviation'] as String; | ||
| } | ||
|
|
||
| Future<String> _getCategoryName(String categoryId) async { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same , use join delegate all of this to the backend |
||
| final client = await service.getClient(); | ||
|
|
||
| final response = await client | ||
| .from('categories') | ||
| .select('name') | ||
| .eq('id', categoryId) | ||
| .maybeSingle(); | ||
|
|
||
| if (response == null) { | ||
| throw Exception("No category found with id: $categoryId"); | ||
| } | ||
|
|
||
| return response['name'] as String; | ||
| } | ||
|
|
||
| @override | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider extracting rpc functions names to constants, since it might be used in another functin