-
Notifications
You must be signed in to change notification settings - Fork 0
115 add command to return my balance balance for all users #129
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: mig
Are you sure you want to change the base?
115 add command to return my balance balance for all users #129
Conversation
add exception in user_balance_helper add new labels for user_balance_helper and all_user_balance_helper
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| # ToDo: If both chat and user's id are none, raise error | ||
|
|
||
| if chat is None and chat_id is None: | ||
| raise Exception("You haven't any balance") |
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.
In this case the more appropriate error would be "The chat is not defined"
| if chat is None and chat_id is None: | ||
| raise Exception("You haven't any balance") | ||
| if not chat: | ||
| response_descr = 0 |
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.
It's a string
| if not chat: | ||
| response_descr = 0 | ||
| chat = Chat.objects.filter(chat_id=chat_id) | ||
| for user in chat: |
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.
Chat represents the user. You don't have to iterate throught them - it returns a list of chats, but you have to take only the first one or return an error if there is len(chat) != 1
|
|
||
| response = f'Your balance is: $ {amount}' | ||
| # ToDo: use labels, add english and russian translations with appropriate label to /helpers/translationHelper.py. Use get_label("text") | ||
| if language == 'russian': |
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 take a look at it, it's equal. Just response_descr = get_label('user_balance', language) without 2 if's
| def all_users_balance_helper(): | ||
| # ToDO #115: Add code to retrieve all users balance. | ||
|
|
||
| response_descr = 0 |
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.
Same, string here
| init_balance = 0 | ||
| amount = "{:.2f}".format(init_balance - all_expenses) | ||
|
|
||
| if language == 'russian': |
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.
Same here, no need to have if conditions as getlabel already resolves that for you, you just pass the language
| response_descr = get_label('user_balance', language) | ||
| elif language == 'english': | ||
| response_descr = get_label('user_balance', language) | ||
| response = f'{response_descr}: $ {amount}' |
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.
We need to return the all_expences here. Please move this block one step left and return the correct output
| def test_endpoint(request, *args, **kwargs): | ||
| if request.method == "GET": | ||
| results = all_users_balance_helper() # ToDo: for test purposes only change here. | ||
| results = all_users_balance_helper() |
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.
No need to change this file as it was only for test purposes
|
@NastyaKolbina well done, not so much to fix and the code is pretty far close to what it requires to do. Just a little bit of fixes and it'll be all good |
No description provided.