Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Send user message after creating baseline record
Browse files Browse the repository at this point in the history
  • Loading branch information
thought-tobi committed Apr 2, 2024
1 parent f47dbfd commit a313aa7
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/handlers/record_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,34 @@ async def baseline_handler(
user_repository, record_repository = get_user_repository(), get_record_repository()
user = user_repository.find_user(update.effective_user.id)
if user.has_baselines_defined():
logging.info(f"Creating baseline record for user {user.user_id}")
record = {metric.name: metric.baseline for metric in user.metrics}
logging.info(f"Creating baseline record for user {user.user_id}: {record}")
record_repository.create_record(
user.user_id,
{
# todo refactor this
metric.name: metric.baseline
for metric in user.metrics
},
record,
datetime.datetime.now().isoformat(),
)
logging.info(f"Baseline record successfully created for user {user.user_id}")
await send(update, text=create_baseline_success_message(record))
else:
logging.error(
f"User {user.user_id} has not defined baselines for all metrics yet."
)
await send(update, text="You have not defined baselines for all metrics yet.")


def create_baseline_success_message(record: dict) -> str:
"""
Creates a success message for the baseline record creation.
:param record: The record that was created.
:return: The success message.
"""
bullet_point_list = ", ".join(
[f"{name.capitalize()} = {value}" for name, value in record.items()]
)
return f"Baseline record successfully created: {bullet_point_list}."


@autowire("user_repository")
def get_user_repository(user_repository: UserRepository):
return user_repository
Expand Down

0 comments on commit a313aa7

Please sign in to comment.