Исправлены критические ошибки

Этот коммит содержится в:
Глеб Иваницкий 2024-08-13 20:22:38 +03:00
родитель e6a39b98bd
Коммит 65d48f2826
2 изменённых файлов: 18 добавлений и 17 удалений

Просмотреть файл

@ -29,7 +29,7 @@ class Users:
async with connection.cursor() as cursor: async with connection.cursor() as cursor:
sql = ''' sql = '''
insert into users ( insert into users (
telegram_id, telegram_user_id,
first_name, first_name,
last_name, last_name,
username username
@ -38,7 +38,7 @@ class Users:
%(first_name)s, %(first_name)s,
%(last_name)s, %(last_name)s,
%(username)s %(username)s
) on conflict (telegram_id) do update set ) on conflict (telegram_user_id) do update set
first_name = excluded.first_name, first_name = excluded.first_name,
last_name = excluded.last_name, last_name = excluded.last_name,
username = excluded.username username = excluded.username
@ -116,7 +116,7 @@ class PollOptions:
where where
poll_options.poll_schema_id = %(poll_schema_id)s poll_options.poll_schema_id = %(poll_schema_id)s
and poll_options.ordinal is not null; and poll_options.ordinal is not null;
''' if ordinals is not None else ''' ''' if ordinals is None else '''
select select
poll_options.id, poll_options.id,
poll_options.name, poll_options.name,
@ -138,6 +138,7 @@ class PollOptions:
return [ return [
models.PollOption( models.PollOption(
id=poll_option_id, id=poll_option_id,
poll_schema=poll_schema,
name=name, name=name,
ordinal=ordinal, ordinal=ordinal,
) )
@ -159,13 +160,12 @@ class Polls:
poll_schemas.id, poll_schemas.id,
poll_schemas.name, poll_schemas.name,
poll_schemas.question, poll_schemas.question,
poll_schemas.options,
polls.created_at, polls.created_at,
polls.is_active polls.is_complete
from from
polls polls
inner join poll_schemas on inner join poll_schemas on
polls.schema_id = poll_schemas.id; polls.poll_schema_id = poll_schemas.id;
''' '''
await cursor.execute(sql) await cursor.execute(sql)
records = await cursor.fetchall() records = await cursor.fetchall()
@ -178,12 +178,11 @@ class Polls:
id=poll_schema_id, id=poll_schema_id,
name=name, name=name,
question=question, question=question,
options=options,
), ),
created_at=created_at, created_at=created_at,
is_active=is_active, is_complete=is_complete,
) )
for poll_id, telegram_message_id, telegram_poll_id, poll_schema_id, name, question, options, created_at, is_active for poll_id, telegram_message_id, telegram_poll_id, poll_schema_id, name, question, created_at, is_complete
in records in records
] ]
@ -199,7 +198,7 @@ class Polls:
insert into polls ( insert into polls (
telegram_message_id, telegram_message_id,
telegram_poll_id, telegram_poll_id,
poll_schema poll_schema_id
) values ( ) values (
%(telegram_message_id)s, %(telegram_message_id)s,
%(telegram_poll_id)s, %(telegram_poll_id)s,
@ -207,18 +206,18 @@ class Polls:
) returning ) returning
polls.id, polls.id,
polls.created_at, polls.created_at,
polls.is_active; polls.is_complete;
''' '''
await cursor.execute( await cursor.execute(
sql, sql,
{ {
'telegram_message_id': telegram_message_id, 'telegram_message_id': telegram_message_id,
'telegram_poll_id': telegram_poll_id, 'telegram_poll_id': telegram_poll_id,
'poll_schema': poll_schema.id, 'poll_schema_id': poll_schema.id,
}, },
) )
try: try:
poll_id, created_at, is_active = await cursor.fetchone() poll_id, created_at, is_complete = await cursor.fetchone()
except TypeError: except TypeError:
raise NotFoundError() raise NotFoundError()
return models.Poll( return models.Poll(
@ -227,7 +226,7 @@ class Polls:
telegram_poll_id=telegram_poll_id, telegram_poll_id=telegram_poll_id,
poll_schema=poll_schema, poll_schema=poll_schema,
created_at=created_at, created_at=created_at,
is_active=is_active, is_complete=is_complete,
) )
@ -264,6 +263,7 @@ class PollAnswers:
for poll_option for poll_option
in poll_options in poll_options
], ],
returning=True,
) )
records = await cursor.fetchall() records = await cursor.fetchall()
return [ return [

Просмотреть файл

@ -1,4 +1,5 @@
from datetime import datetime from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -9,8 +10,8 @@ class User(BaseModel):
exclude=True, exclude=True,
) )
first_name: str first_name: str
last_name: str last_name: Optional[str]
username: str username: Optional[str]
class PollSchema(BaseModel): class PollSchema(BaseModel):
@ -23,7 +24,7 @@ class PollOption(BaseModel):
id: int id: int
poll_schema: PollSchema poll_schema: PollSchema
name: str name: str
ordinal: int ordinal: Optional[int]
class Poll(BaseModel): class Poll(BaseModel):