refractor structure project and add user endpoint

This commit is contained in:
2026-01-08 15:05:23 +03:00
parent 423ce8bc62
commit 8e0131451d
25 changed files with 329 additions and 218 deletions
+7 -2
View File
@@ -1,10 +1,13 @@
import json
import logging
from functools import wraps
from fastapi import Request
from fastapi.encoders import jsonable_encoder
from app.utils.redis import get_redis
from app.core.redis import get_redis
log = logging.getLogger(__name__)
def cache(ttl: int = 10):
if ttl <= 0:
@@ -17,10 +20,12 @@ def cache(ttl: int = 10):
request: Request = kwargs.get("request")
response_cache = await redis.get(str(request.url))
if response_cache is not None:
log.debug("Getting from cache")
return json.loads(response_cache)
response_cache = await func(*args, **kwargs)
await redis.setex(str(request.url), ttl, json.dumps(response_cache))
serializable_data = jsonable_encoder(response_cache)
await redis.setex(str(request.url), ttl, json.dumps(serializable_data))
return response_cache
return wrapper