Changes to database.get_accounts
Function is only fetching account names from db and not whole accounts now Made sorting in that function optional
This commit is contained in:
parent
5991041b35
commit
f299173e56
@ -38,7 +38,11 @@ def _base_handler(
|
|||||||
|
|
||||||
def get_accounts(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
|
def get_accounts(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
|
||||||
_base_handler(bot, mes)
|
_base_handler(bot, mes)
|
||||||
accounts = database.get.get_accounts(engine, mes.from_user.id)
|
accounts = database.get.get_accounts(
|
||||||
|
engine,
|
||||||
|
mes.from_user.id,
|
||||||
|
to_sort=True,
|
||||||
|
)
|
||||||
if not accounts:
|
if not accounts:
|
||||||
return _send_tmp_message(bot, mes.chat.id, "У вас нет аккаунтов")
|
return _send_tmp_message(bot, mes.chat.id, "У вас нет аккаунтов")
|
||||||
|
|
||||||
|
@ -22,18 +22,21 @@ def get_master_pass(
|
|||||||
return (result.salt, result.password_hash)
|
return (result.salt, result.password_hash)
|
||||||
|
|
||||||
|
|
||||||
def get_accounts(engine: Engine, user_id: int) -> list[str]:
|
def get_accounts(
|
||||||
|
engine: Engine,
|
||||||
|
user_id: int,
|
||||||
|
*,
|
||||||
|
to_sort: bool = False,
|
||||||
|
) -> list[str]:
|
||||||
"""Gets list of account names"""
|
"""Gets list of account names"""
|
||||||
statement = (
|
statement = sqlmodel.select(models.Account.name).where(
|
||||||
sqlmodel.select(models.Account)
|
models.Account.user_id == user_id,
|
||||||
.where(
|
|
||||||
models.Account.user_id == user_id,
|
|
||||||
)
|
|
||||||
.order_by(models.Account.name)
|
|
||||||
)
|
)
|
||||||
|
if to_sort:
|
||||||
|
statement = statement.order_by(models.Account.name)
|
||||||
with sqlmodel.Session(engine) as session:
|
with sqlmodel.Session(engine) as session:
|
||||||
result = session.exec(statement)
|
result = list(session.exec(statement))
|
||||||
return [account.name for account in result]
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_all_accounts(
|
def get_all_accounts(
|
||||||
|
Reference in New Issue
Block a user