first commit
Some checks failed
Build And Push / publish (push) Failing after 3m15s

This commit is contained in:
2025-09-24 04:11:55 +03:00
commit 967bb8d936
45 changed files with 2651 additions and 0 deletions

0
src/shared/__init__.py Normal file
View File

66
src/shared/exceptions.py Normal file
View File

@ -0,0 +1,66 @@
from fastapi import HTTPException, status
class BasicException(HTTPException):
base_status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR
base_detail: str = 'Something went wrong'
def __init__(
self, *, status_code: int | None = None, detail: str | None = None
):
status_code = status_code or self.base_status_code
detail = detail or self.base_detail
super().__init__(status_code=status_code, detail=detail)
@classmethod
def description(cls, detail: str | None = None):
return {
'description': detail or cls.base_detail,
'content': {
'application/json': {
'example': {
'detail': detail or cls.base_detail,
}
}
},
}
class BadRequestException(BasicException):
base_status_code: int = status.HTTP_400_BAD_REQUEST
base_detail: str = 'Bad Request'
class UnauthorizedException(BasicException):
base_status_code: int = status.HTTP_401_UNAUTHORIZED
base_detail: str = 'Unauthorized'
class ForbiddenException(BasicException):
base_status_code: int = status.HTTP_403_FORBIDDEN
base_detail: str = 'Forbidden'
class NotFoundException(BasicException):
base_status_code: int = status.HTTP_404_NOT_FOUND
base_detail: str = 'Not Found'
class ConflictException(BasicException):
base_status_code: int = status.HTTP_409_CONFLICT
base_detail: str = 'Conflict'
class TooManyRequestsException(BasicException):
base_status_code: int = status.HTTP_429_TOO_MANY_REQUESTS
base_detail: str = 'Too Many Requests'
class InternalServerErrorException(BasicException):
base_status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR
base_detail: str = 'Internal Server Error'
class UnknownException(BasicException):
base_status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR
base_detail: str = 'Unknown error'

5
src/shared/redis.py Normal file
View File

@ -0,0 +1,5 @@
from redis import Redis
from core.config import settings
client = Redis.from_url(settings.REDIS_URL)