mirror of
https://codeberg.org/catask-org/catask.git
synced 2025-04-18 12:53:42 -05:00
abort if question is not found
This commit is contained in:
parent
1f8979cf58
commit
dd27fc8e09
1 changed files with 16 additions and 8 deletions
24
functions.py
24
functions.py
|
@ -137,14 +137,22 @@ def connectToDb():
|
|||
return psycopg.connect(f"postgresql://{dbUser}:{dbPass}@{dbHost}/{dbName}", row_factory=dict_row)
|
||||
|
||||
def getQuestion(question_id: int) -> dict:
|
||||
conn = connectToDb()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM questions WHERE id=%s", (question_id,))
|
||||
question = cursor.fetchone()
|
||||
question['creation_date'] = question['creation_date'].replace(microsecond=0).replace(tzinfo=None)
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return question
|
||||
try:
|
||||
conn = connectToDb()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM questions WHERE id=%s", (question_id,))
|
||||
question = cursor.fetchone()
|
||||
|
||||
if not question:
|
||||
return abort(404)
|
||||
|
||||
question['creation_date'] = question['creation_date'].replace(microsecond=0).replace(tzinfo=None)
|
||||
|
||||
return question
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
def getAllQuestions(limit: int = None, offset: int = None) -> dict:
|
||||
conn = connectToDb()
|
||||
|
|
Loading…
Add table
Reference in a new issue