feat: added business models, implemented business signup and signin

This commit is contained in:
ITQ
2025-01-20 16:09:37 +03:00
parent 2eef92b617
commit 9ae9b46780
19 changed files with 272 additions and 2 deletions
+22 -2
View File
@@ -6,9 +6,28 @@ import django.http
from django.http import HttpRequest, HttpResponse
from ninja import NinjaAPI, errors
from config.errors import UniqueConstraintError
logger = logging.getLogger("django")
def handle_unique_constraint_error(
request: HttpRequest,
exc: UniqueConstraintError,
router: NinjaAPI,
) -> HttpResponse:
detail = list(exc.validation_error)
if hasattr(exc, "error_dict"):
detail = dict(exc.validation_error)
return router.create_response(
request,
{"detail": detail},
status=status.CONFLICT,
)
def handle_django_validation_error(
request: HttpRequest,
exc: django.core.exceptions.ValidationError,
@@ -22,7 +41,7 @@ def handle_django_validation_error(
return router.create_response(
request,
{"detail": detail},
status=status.UNPROCESSABLE_ENTITY,
status=status.BAD_REQUEST,
)
@@ -42,7 +61,7 @@ def handle_validation_error(
return router.create_response(
request,
{"detail": exc.errors},
status=status.UNPROCESSABLE_ENTITY,
status=status.BAD_REQUEST,
)
@@ -69,6 +88,7 @@ def handle_unknown_exception(
exception_handlers = [
(UniqueConstraintError, handle_unique_constraint_error),
(django.core.exceptions.ValidationError, handle_django_validation_error),
(errors.AuthenticationError, handle_authentication_error),
(errors.ValidationError, handle_validation_error),