schema-fix-author-fix
All checks were successful
deploy / deploy (push) Successful in 1m42s

This commit is contained in:
Untone 2023-12-07 21:29:25 +03:00
parent bb55cfaefe
commit c1adaf3ed6
3 changed files with 15 additions and 6 deletions

View File

@ -68,6 +68,7 @@ class Shout(Base):
body = Column(String, nullable=False, comment="Body") body = Column(String, nullable=False, comment="Body")
slug = Column(String, unique=True) slug = Column(String, unique=True)
cover = Column(String, nullable=True, comment="Cover image url") cover = Column(String, nullable=True, comment="Cover image url")
cover_caption = Column(String, nullable=True, comment="Cover image alt caption")
lead = Column(String, nullable=True) lead = Column(String, nullable=True)
description = Column(String, nullable=True) description = Column(String, nullable=True)
title = Column(String, nullable=True) title = Column(String, nullable=True)

View File

@ -173,7 +173,10 @@ async def get_author(_, _info, slug="", user=None, author_id=None):
q = add_author_stat_columns(q) q = add_author_stat_columns(q)
authors = get_authors_from_query(q) authors = get_authors_from_query(q)
return authors[0] if authors:
return authors.pop()
else:
return {"error": "cant find author"}
@query.field("load_authors_by") @query.field("load_authors_by")
@ -201,15 +204,19 @@ async def load_authors_by(_, _info, by, limit, offset):
@query.field("get_author_followed") @query.field("get_author_followed")
async def get_author_followed(_, _info, slug="", user=None, author_id=None) -> List[Author]: async def get_author_followed(_, _info, slug="", user=None, author_id=None) -> List[Author]:
# First, we need to get the author_id for the given slug author_id_query = None
with local_session() as session: if slug:
author_id_query = select(Author.id).where(Author.slug == slug) author_id_query = select(Author.id).where(Author.slug == slug)
elif user:
author_id_query = select(Author.id).where(Author.user == user)
if not author_id:
with local_session() as session:
author_id = session.execute(author_id_query).scalar() author_id = session.execute(author_id_query).scalar()
if author_id is None: if author_id is None:
raise ValueError("Author not found") raise ValueError("Author not found")
else:
return await followed_authors(author_id) return await followed_authors(author_id) # Author[]
@query.field("get_author_followers") @query.field("get_author_followers")

View File

@ -126,6 +126,7 @@ type Shout {
lang: String lang: String
community: String community: String
cover: String cover: String
cover_caption: String
layout: String layout: String
version_of: String version_of: String
visibility: ShoutVisibility visibility: ShoutVisibility