This commit is contained in:
parent
d3ed335fde
commit
1de3d163c1
|
@ -1,7 +1,5 @@
|
||||||
#### [0.4.10] - 2025-02-10
|
#### [0.4.11] - 2025-02-12
|
||||||
- `add_author_stat_columns` fixed
|
- `create_draft` resolver requires draft_id fixed
|
||||||
- `Draft` orm and schema tuning and fixes
|
|
||||||
- `create_draft` and `update_draft` mutations and resolvers fixed
|
|
||||||
|
|
||||||
|
|
||||||
#### [0.4.9] - 2025-02-09
|
#### [0.4.9] - 2025-02-09
|
||||||
|
|
|
@ -62,21 +62,50 @@ async def load_drafts(_, info):
|
||||||
@mutation.field("create_draft")
|
@mutation.field("create_draft")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_draft(_, info, draft_input):
|
async def create_draft(_, info, draft_input):
|
||||||
|
"""Create a new draft.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
info: GraphQL context
|
||||||
|
draft_input (dict): Draft data including optional fields:
|
||||||
|
- title (str)
|
||||||
|
- body (str)
|
||||||
|
- slug (str)
|
||||||
|
- etc.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Contains either:
|
||||||
|
- draft: The created draft object
|
||||||
|
- error: Error message if creation failed
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> async def test_create():
|
||||||
|
... context = {'user_id': '123', 'author': {'id': 1}}
|
||||||
|
... info = type('Info', (), {'context': context})()
|
||||||
|
... result = await create_draft(None, info, {'title': 'Test'})
|
||||||
|
... assert result.get('error') is None
|
||||||
|
... assert result['draft'].title == 'Test'
|
||||||
|
... return result
|
||||||
|
"""
|
||||||
user_id = info.context.get("user_id")
|
user_id = info.context.get("user_id")
|
||||||
author_dict = info.context.get("author", {})
|
author_dict = info.context.get("author", {})
|
||||||
author_id = author_dict.get("id")
|
author_id = author_dict.get("id")
|
||||||
draft_id = draft_input.get("id")
|
|
||||||
|
|
||||||
if not draft_id:
|
|
||||||
return {"error": "Draft ID is required"}
|
|
||||||
if not user_id or not author_id:
|
if not user_id or not author_id:
|
||||||
return {"error": "Author ID are required"}
|
return {"error": "Author ID is required"}
|
||||||
|
|
||||||
with local_session() as session:
|
try:
|
||||||
draft = Draft(created_by=author_id, **draft_input)
|
with local_session() as session:
|
||||||
session.add(draft)
|
# Remove id from input if present since it's auto-generated
|
||||||
session.commit()
|
if "id" in draft_input:
|
||||||
return {"draft": draft}
|
del draft_input["id"]
|
||||||
|
|
||||||
|
draft = Draft(created_by=author_id, **draft_input)
|
||||||
|
session.add(draft)
|
||||||
|
session.commit()
|
||||||
|
return {"draft": draft}
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to create draft: {e}", exc_info=True)
|
||||||
|
return {"error": f"Failed to create draft: {str(e)}"}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("update_draft")
|
@mutation.field("update_draft")
|
||||||
|
|
|
@ -636,27 +636,26 @@ async def delete_shout(_, info, shout_id: int):
|
||||||
def get_main_topic(topics):
|
def get_main_topic(topics):
|
||||||
"""Get the main topic from a list of ShoutTopic objects."""
|
"""Get the main topic from a list of ShoutTopic objects."""
|
||||||
logger.info(f"Starting get_main_topic with {len(topics) if topics else 0} topics")
|
logger.info(f"Starting get_main_topic with {len(topics) if topics else 0} topics")
|
||||||
logger.debug(f"Topics data: {[(t.topic.slug if t.topic else 'no-topic', t.main) for t in topics] if topics else []}")
|
logger.debug(
|
||||||
|
f"Topics data: {[(t.topic.slug if t.topic else 'no-topic', t.main) for t in topics] if topics else []}"
|
||||||
|
)
|
||||||
|
|
||||||
if not topics:
|
if not topics:
|
||||||
logger.warning("No topics provided to get_main_topic")
|
logger.warning("No topics provided to get_main_topic")
|
||||||
return {
|
return {"id": 0, "title": "no topic", "slug": "notopic", "is_main": True}
|
||||||
"id": 0,
|
|
||||||
"title": "no topic",
|
|
||||||
"slug": "notopic",
|
|
||||||
"is_main": True
|
|
||||||
}
|
|
||||||
|
|
||||||
# Find first main topic in original order
|
# Find first main topic in original order
|
||||||
main_topic_rel = next((st for st in topics if st.main), None)
|
main_topic_rel = next((st for st in topics if st.main), None)
|
||||||
logger.debug(f"Found main topic relation: {main_topic_rel.topic.slug if main_topic_rel and main_topic_rel.topic else None}")
|
logger.debug(
|
||||||
|
f"Found main topic relation: {main_topic_rel.topic.slug if main_topic_rel and main_topic_rel.topic else None}"
|
||||||
|
)
|
||||||
|
|
||||||
if main_topic_rel and main_topic_rel.topic:
|
if main_topic_rel and main_topic_rel.topic:
|
||||||
result = {
|
result = {
|
||||||
"slug": main_topic_rel.topic.slug,
|
"slug": main_topic_rel.topic.slug,
|
||||||
"title": main_topic_rel.topic.title,
|
"title": main_topic_rel.topic.title,
|
||||||
"id": main_topic_rel.topic.id,
|
"id": main_topic_rel.topic.id,
|
||||||
"is_main": True
|
"is_main": True,
|
||||||
}
|
}
|
||||||
logger.info(f"Returning main topic: {result}")
|
logger.info(f"Returning main topic: {result}")
|
||||||
return result
|
return result
|
||||||
|
@ -668,14 +667,9 @@ def get_main_topic(topics):
|
||||||
"slug": topics[0].topic.slug,
|
"slug": topics[0].topic.slug,
|
||||||
"title": topics[0].topic.title,
|
"title": topics[0].topic.title,
|
||||||
"id": topics[0].topic.id,
|
"id": topics[0].topic.id,
|
||||||
"is_main": True
|
"is_main": True,
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
logger.warning("No valid topics found, returning default")
|
logger.warning("No valid topics found, returning default")
|
||||||
return {
|
return {"slug": "notopic", "title": "no topic", "id": 0, "is_main": True}
|
||||||
"slug": "notopic",
|
|
||||||
"title": "no topic",
|
|
||||||
"id": 0,
|
|
||||||
"is_main": True
|
|
||||||
}
|
|
||||||
|
|
|
@ -239,7 +239,9 @@ def get_shouts_with_links(info, q, limit=20, offset=0):
|
||||||
main_topic = None
|
main_topic = None
|
||||||
if hasattr(row, "main_topic"):
|
if hasattr(row, "main_topic"):
|
||||||
logger.debug(f"Raw main_topic for shout#{shout_id}: {row.main_topic}")
|
logger.debug(f"Raw main_topic for shout#{shout_id}: {row.main_topic}")
|
||||||
main_topic = json.loads(row.main_topic) if isinstance(row.main_topic, str) else row.main_topic
|
main_topic = (
|
||||||
|
json.loads(row.main_topic) if isinstance(row.main_topic, str) else row.main_topic
|
||||||
|
)
|
||||||
logger.debug(f"Parsed main_topic for shout#{shout_id}: {main_topic}")
|
logger.debug(f"Parsed main_topic for shout#{shout_id}: {main_topic}")
|
||||||
|
|
||||||
if not main_topic and topics and len(topics) > 0:
|
if not main_topic and topics and len(topics) > 0:
|
||||||
|
@ -248,16 +250,11 @@ def get_shouts_with_links(info, q, limit=20, offset=0):
|
||||||
"id": topics[0]["id"],
|
"id": topics[0]["id"],
|
||||||
"title": topics[0]["title"],
|
"title": topics[0]["title"],
|
||||||
"slug": topics[0]["slug"],
|
"slug": topics[0]["slug"],
|
||||||
"is_main": True
|
"is_main": True,
|
||||||
}
|
}
|
||||||
elif not main_topic:
|
elif not main_topic:
|
||||||
logger.warning(f"No main_topic and no topics found for shout#{shout_id}")
|
logger.warning(f"No main_topic and no topics found for shout#{shout_id}")
|
||||||
main_topic = {
|
main_topic = {"id": 0, "title": "no topic", "slug": "notopic", "is_main": True}
|
||||||
"id": 0,
|
|
||||||
"title": "no topic",
|
|
||||||
"slug": "notopic",
|
|
||||||
"is_main": True
|
|
||||||
}
|
|
||||||
shout_dict["main_topic"] = main_topic
|
shout_dict["main_topic"] = main_topic
|
||||||
logger.debug(f"Final main_topic for shout#{shout_id}: {main_topic}")
|
logger.debug(f"Final main_topic for shout#{shout_id}: {main_topic}")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user