[rewrite] Major changes to code - switched to postgres, added initial backend docker files
This commit is contained in:
1 parent
c7e20fc935
commit
71e916586e
52 files changed
+783
-537
No files matched your search
@@ -1,13 +0,0 @@
|
||||
from functools import wraps
|
||||
from sqlalchemy.exc import DatabaseError as SqlAlchemyDatabaseError
|
||||
from app.database.exceptions import DatabaseError
|
||||
|
||||
|
||||
def handle_database_errors(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except SqlAlchemyDatabaseError as e:
|
||||
raise DatabaseError(str(e), -1) from e
|
||||
return wrapper
|
||||
@@ -0,0 +1,13 @@
|
||||
import sys
|
||||
import logging
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
def setup_logger():
|
||||
verbosity = settings.VERBOSITY
|
||||
if verbosity == "DEBUG":
|
||||
log_format = "[ %(name)s / %(levelname)s ] - %(filename)s:%(lineno)d - %(message)s"
|
||||
else:
|
||||
log_format = "[ %(levelname)s ] - %(message)s"
|
||||
|
||||
logging.basicConfig(level=verbosity, format=log_format, stream=sys.stdout)
|
||||
@@ -0,0 +1,6 @@
|
||||
from typing import Optional
|
||||
from uuid import uuid5, UUID, NAMESPACE_DNS
|
||||
|
||||
def generate_user_uuid5(email: str, shop_id: Optional[int]) -> UUID:
|
||||
unique_string = f"{email}-{shop_id}" if shop_id else email
|
||||
return uuid5(NAMESPACE_DNS, unique_string)
|
||||
@@ -0,0 +1,27 @@
|
||||
from functools import wraps
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from sqlalchemy.exc import DatabaseError as SqlAlchemyDatabaseError
|
||||
|
||||
from app.core.errors import RepositoryError, ServiceError
|
||||
|
||||
|
||||
def propagate_db_error_to_service(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except (SqlAlchemyDatabaseError, RepositoryError) as e:
|
||||
raise ServiceError(str(e)) from e
|
||||
return wrapper
|
||||
|
||||
|
||||
def propagate_service_errors_to_http_errors(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except ServiceError as e:
|
||||
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||
return wrapper
|
||||
Whitespace-only changes.
Reference in new issue
Block a user