fix return values in add_user and add_feed methods

This commit is contained in:
mitsuha_s 2022-07-13 20:15:11 +00:00
parent f11b0b91af
commit 5d0a6843b6

View file

@ -22,9 +22,9 @@ class Database:
def add_user(self, telegram_id: int) -> int:
"""Add a user's telegram id to the database and return its database id."""
self.log.debug('add_user(telegram_id=\'%s\')', telegram_id)
id = self.cur.execute('INSERT INTO users (telegram_id) VALUES (%s) RETURNING id', [telegram_id])
self.cur.execute('INSERT INTO users (telegram_id) VALUES (%s) RETURNING id', [telegram_id])
self.conn.commit()
return id
return self.cur.fetchone()[0]
def find_user(self, telegram_id: int) -> int | None:
"""Get a user's telegram id and return its database id."""
@ -38,9 +38,9 @@ class Database:
def add_feed(self, url: str) -> int:
"""Add a feed to the database and return its id."""
self.log.debug('add_feed(url=\'%s\')', url)
id = self.cur.execute('INSERT INTO feeds (url) VALUES (%s) RETURNING id', [url])
self.cur.execute('INSERT INTO feeds (url) VALUES (%s) RETURNING id', [url])
self.conn.commit()
return id
return self.cur.fetchone()[0]
def find_feed_by_url(self, url: str) -> int | None:
"""Find feed ID by url."""
@ -121,7 +121,7 @@ class Database:
subscribers = self.cur.fetchall()
return list(map(lambda x: x['telegram_id'], subscribers))
def find_feeds(self) -> list[psycopg2.extras.DictRow]:
def find_feeds(self) -> list[DictRow]:
"""Get a list of feeds."""
self.log.debug('find_feeds()')
self.cur.execute('SELECT * FROM feeds')