This commit is contained in:
parent
0c2af2bdf4
commit
269c0e449f
5
main.py
5
main.py
|
@ -44,7 +44,10 @@ class WebhookEndpoint(HTTPEndpoint):
|
||||||
try:
|
try:
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
if data:
|
if data:
|
||||||
await create_author(data)
|
# Extract user_id and slug
|
||||||
|
user_id = data["user"]["id"]
|
||||||
|
slug = data["user"]["preferred_username"] or data["user"]["email"].replace(".", "-").split("@").pop()
|
||||||
|
await create_author(user_id, slug)
|
||||||
return JSONResponse({"status": "success"})
|
return JSONResponse({"status": "success"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse({"status": "error", "message": str(e)}, status_code=500)
|
return JSONResponse({"status": "error", "message": str(e)}, status_code=500)
|
||||||
|
|
|
@ -241,9 +241,9 @@ async def rate_author(_, info, rated_slug, value):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
async def create_author(data):
|
async def create_author(user_id: str, slug: str):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
# TODO: check Authorization header
|
# TODO: check Authorization header
|
||||||
new_author = Author(**data)
|
new_author = Author(user=user_id, slug=slug)
|
||||||
session.add(new_author)
|
session.add(new_author)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user