style: format backend with black
Also drops the session-sliding comment in login_required.
This commit is contained in:
+11
-2
@@ -1,4 +1,5 @@
|
||||
"""Notes slice: a per-book reading journal. Ownership is always derived through books.user_id."""
|
||||
|
||||
from flask import Blueprint, g, jsonify
|
||||
|
||||
from auth import login_required
|
||||
@@ -22,7 +23,12 @@ def to_json(row: dict) -> dict:
|
||||
|
||||
|
||||
def _require_book(book_id: int) -> None:
|
||||
if query_one("SELECT 1 FROM books WHERE id = %s AND user_id = %s", (book_id, g.user_id)) is None:
|
||||
if (
|
||||
query_one(
|
||||
"SELECT 1 FROM books WHERE id = %s AND user_id = %s", (book_id, g.user_id)
|
||||
)
|
||||
is None
|
||||
):
|
||||
raise ApiError(404, "Book not found")
|
||||
|
||||
|
||||
@@ -42,7 +48,10 @@ def list_notes(book_id: int):
|
||||
def add_note(book_id: int):
|
||||
_require_book(book_id)
|
||||
body = text(json_body({"body"}), "body", MAX_BODY)
|
||||
row = query_one(f"INSERT INTO notes AS n (book_id, body) VALUES (%s, %s) RETURNING {NOTE_COLUMNS}", (book_id, body))
|
||||
row = query_one(
|
||||
f"INSERT INTO notes AS n (book_id, body) VALUES (%s, %s) RETURNING {NOTE_COLUMNS}",
|
||||
(book_id, body),
|
||||
)
|
||||
return jsonify(to_json(row)), 201
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user