This commit is contained in:
parent
8050a7e828
commit
8f690af6ef
|
@ -1,5 +1,6 @@
|
|||
import time
|
||||
from typing import List
|
||||
import logging
|
||||
|
||||
from sqlalchemy import and_, case, distinct, func, literal, select, cast, Integer
|
||||
from sqlalchemy.orm import aliased
|
||||
|
@ -17,6 +18,10 @@ from services.db import local_session
|
|||
from services.schema import mutation, query
|
||||
from services.unread import get_total_unread_counter
|
||||
|
||||
logging.basicConfig()
|
||||
logger = logging.getLogger("\t[resolvers.author]\t")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
def add_author_stat_columns(q):
|
||||
shout_author_aliased = aliased(ShoutAuthor)
|
||||
|
@ -48,7 +53,6 @@ def get_authors_from_query(q):
|
|||
"followings": followings_stat,
|
||||
}
|
||||
authors.append(author)
|
||||
# print(f"[resolvers.author] get_authors_from_query {authors}")
|
||||
return authors
|
||||
|
||||
|
||||
|
@ -201,7 +205,7 @@ async def get_author(_, _info, slug="", author_id=None):
|
|||
@query.field("get_author_id")
|
||||
async def get_author_id(_, _info, user: str):
|
||||
with local_session() as session:
|
||||
print(f"[resolvers.author] getting author id for {user}")
|
||||
logger.info(f"[resolvers.author] getting author id for {user}")
|
||||
q = select(Author).filter(Author.user == user)
|
||||
return load_author_with_stats(q)
|
||||
|
||||
|
@ -302,4 +306,4 @@ async def create_author(user_id: str, slug: str, name: str = ""):
|
|||
new_author = Author(user=user_id, slug=slug, name=name)
|
||||
session.add(new_author)
|
||||
session.commit()
|
||||
print(f"[resolvers.author] created by webhook {new_author.dict()}")
|
||||
logger.info(f"author created by webhook {new_author.dict()}")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import time
|
||||
from typing import List
|
||||
import logging
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
|
@ -19,6 +20,10 @@ from services.notify import notify_follower
|
|||
from services.schema import mutation, query
|
||||
|
||||
|
||||
logging.basicConfig()
|
||||
logger = logging.getLogger("\t[resolvers.reaction]\t")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
@login_required
|
||||
@mutation.field("follow")
|
||||
async def follow(_, info, what, slug):
|
||||
|
@ -48,7 +53,7 @@ async def follow(_, info, what, slug):
|
|||
result = FollowingResult("NEW", "shout", slug)
|
||||
await FollowingManager.push("shout", result)
|
||||
except Exception as e:
|
||||
print(Exception(e))
|
||||
logger.error(e)
|
||||
return {"error": str(e)}
|
||||
|
||||
return {}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import time
|
||||
from typing import List
|
||||
import logging
|
||||
|
||||
from sqlalchemy import and_, asc, case, desc, func, select, text
|
||||
from sqlalchemy.orm import aliased, joinedload
|
||||
|
@ -13,6 +14,10 @@ from services.notify import notify_reaction
|
|||
from services.schema import mutation, query
|
||||
|
||||
|
||||
logging.basicConfig()
|
||||
logger = logging.getLogger("\t[resolvers.reaction]\t")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
def add_reaction_stat_columns(q):
|
||||
aliased_reaction = aliased(Reaction)
|
||||
|
||||
|
@ -242,7 +247,7 @@ async def create_reaction(_, info, reaction):
|
|||
try:
|
||||
reactions_follow(author.id, reaction["shout"], True)
|
||||
except Exception as e:
|
||||
print(f"[resolvers.reactions] error on reactions auto following: {e}")
|
||||
logger.error(f"[resolvers.reactions] error on reactions auto following: {e}")
|
||||
|
||||
rdict["stat"] = {"commented": 0, "reacted": 0, "rating": 0}
|
||||
|
||||
|
@ -438,8 +443,10 @@ async def load_shouts_followed(_, info, limit=50, offset=0) -> List[Shout]:
|
|||
with local_session() as session:
|
||||
author = session.query(Author).filter(Author.user == user_id).first()
|
||||
if author:
|
||||
author_id: int = author.dict()["id"]
|
||||
shouts = reacted_shouts_updates(author_id, limit, offset)
|
||||
return shouts
|
||||
else:
|
||||
return []
|
||||
try:
|
||||
author_id: int = author.dict()["id"]
|
||||
shouts = reacted_shouts_updates(author_id, limit, offset)
|
||||
return shouts
|
||||
except Exception as error:
|
||||
logger.debug(error)
|
||||
return []
|
||||
|
|
|
@ -58,7 +58,7 @@ async def get_topics_all(_, _info):
|
|||
|
||||
|
||||
def topics_followed_by(author_id):
|
||||
q = select(Topic)
|
||||
q = select(Topic, TopicFollower)
|
||||
q = add_topic_stat_columns(q)
|
||||
q = q.join(TopicFollower).where(TopicFollower.follower == author_id)
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from functools import wraps
|
||||
import logging
|
||||
|
||||
from aiohttp import ClientSession
|
||||
from starlette.exceptions import HTTPException
|
||||
|
@ -6,6 +7,11 @@ from starlette.exceptions import HTTPException
|
|||
from settings import AUTH_URL, AUTH_SECRET
|
||||
|
||||
|
||||
logging.basicConfig()
|
||||
logger = logging.getLogger("\t[services.auth]\t")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
async def request_data(gql, headers = { "Content-Type": "application/json" }):
|
||||
try:
|
||||
# Asynchronous HTTP request to the authentication server
|
||||
|
@ -15,12 +21,12 @@ async def request_data(gql, headers = { "Content-Type": "application/json" }):
|
|||
data = await response.json()
|
||||
errors = data.get("errors")
|
||||
if errors:
|
||||
print(f"[services.auth] errors: {errors}")
|
||||
logger.error(f"[services.auth] errors: {errors}")
|
||||
else:
|
||||
return data
|
||||
except Exception as e:
|
||||
# Handling and logging exceptions during authentication check
|
||||
print(f"[services.auth] request_data error: {e}")
|
||||
logger.error(f"[services.auth] request_data error: {e}")
|
||||
return None
|
||||
|
||||
|
||||
|
@ -30,7 +36,7 @@ async def check_auth(req) -> str | None:
|
|||
user_id = ""
|
||||
if token:
|
||||
# Logging the authentication token
|
||||
print(f"[services.auth] checking auth token: {token}")
|
||||
logger.error(f"[services.auth] checking auth token: {token}")
|
||||
query_name = "validate_jwt_token"
|
||||
operation = "ValidateToken"
|
||||
variables = {
|
||||
|
@ -55,7 +61,7 @@ async def check_auth(req) -> str | None:
|
|||
|
||||
|
||||
async def add_user_role(user_id):
|
||||
print(f"[services.auth] add author role for user_id: {user_id}")
|
||||
logger.info(f"[services.auth] add author role for user_id: {user_id}")
|
||||
query_name = "_update_user"
|
||||
operation = "UpdateUserRoles"
|
||||
headers = {"Content-Type": "application/json", "x-authorizer-admin-secret": AUTH_SECRET}
|
||||
|
|
Loading…
Reference in New Issue
Block a user