Skip to content

Conversation

@NastyaKolbina
Copy link
Collaborator

No description provided.

add exception in user_balance_helper
add new labels for user_balance_helper and all_user_balance_helper
@NastyaKolbina NastyaKolbina added the development New feature or request label May 16, 2023
@NastyaKolbina NastyaKolbina self-assigned this May 16, 2023
@vercel
Copy link

vercel bot commented May 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
planner-ai ✅ Ready (Inspect) Visit Preview May 16, 2023 6:34pm

# 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")
Copy link
Owner

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
Copy link
Owner

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:
Copy link
Owner

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':
Copy link
Owner

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
Copy link
Owner

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':
Copy link
Owner

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}'
Copy link
Owner

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()
Copy link
Owner

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

@Ovaday
Copy link
Owner

Ovaday commented May 20, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

development New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants