You've already forked Promocode-API
mirror of
https://github.com/devitq/Promocode-API.git
synced 2026-05-22 19:47:11 +00:00
chore: small codebase improvements
This commit is contained in:
@@ -22,7 +22,7 @@ router = Router(tags=["business"])
|
||||
"/auth/sign-up",
|
||||
response={
|
||||
status.OK: schemas.BusinessSignUpOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.CONFLICT: global_schemas.UniqueConstraintError,
|
||||
},
|
||||
)
|
||||
@@ -43,7 +43,7 @@ def signup(
|
||||
"/auth/sign-in",
|
||||
response={
|
||||
status.OK: schemas.BusinessSignInOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
||||
},
|
||||
)
|
||||
@@ -79,7 +79,7 @@ def signin(
|
||||
auth=BusinessAuth(),
|
||||
response={
|
||||
status.CREATED: schemas.CreatePromocodeOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
||||
},
|
||||
)
|
||||
@@ -134,7 +134,7 @@ def create_promocode(
|
||||
auth=BusinessAuth(),
|
||||
response={
|
||||
status.OK: list[schemas.PromocodeViewOut],
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
|
||||
@@ -3,8 +3,9 @@ from http import HTTPStatus as status
|
||||
|
||||
import django.core.exceptions
|
||||
import django.http
|
||||
import ninja.errors
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from ninja import NinjaAPI, errors
|
||||
from ninja import NinjaAPI
|
||||
|
||||
from config.errors import UniqueConstraintError
|
||||
|
||||
@@ -47,7 +48,7 @@ def handle_django_validation_error(
|
||||
|
||||
def handle_authentication_error(
|
||||
request: HttpRequest,
|
||||
exc: errors.AuthenticationError,
|
||||
exc: ninja.errors.AuthenticationError,
|
||||
router: NinjaAPI,
|
||||
) -> HttpResponse:
|
||||
return router.create_response(
|
||||
@@ -59,7 +60,7 @@ def handle_authentication_error(
|
||||
|
||||
def handle_validation_error(
|
||||
request: HttpRequest,
|
||||
exc: errors.ValidationError,
|
||||
exc: ninja.errors.ValidationError,
|
||||
router: NinjaAPI,
|
||||
) -> HttpResponse:
|
||||
return router.create_response(
|
||||
@@ -98,8 +99,8 @@ 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),
|
||||
(ninja.errors.AuthenticationError, handle_authentication_error),
|
||||
(ninja.errors.ValidationError, handle_validation_error),
|
||||
(django.http.Http404, handle_not_found_error),
|
||||
(Exception, handle_unknown_exception),
|
||||
]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from http import HTTPStatus as status
|
||||
from typing import Any
|
||||
|
||||
from ninja import Schema
|
||||
|
||||
@@ -11,9 +12,9 @@ class NotFoundError(Schema):
|
||||
detail: str = status.NOT_FOUND.phrase
|
||||
|
||||
|
||||
class ValidationError(Schema):
|
||||
detail: str
|
||||
class BadRequestError(Schema):
|
||||
detail: Any
|
||||
|
||||
|
||||
class UniqueConstraintError(Schema):
|
||||
detail: str
|
||||
detail: Any
|
||||
|
||||
@@ -20,7 +20,7 @@ router = Router(tags=["user"])
|
||||
"/auth/sign-up",
|
||||
response={
|
||||
status.OK: schemas.UserSignUpOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.CONFLICT: global_schemas.UniqueConstraintError,
|
||||
},
|
||||
)
|
||||
@@ -44,7 +44,7 @@ def signup(
|
||||
"/auth/sign-in",
|
||||
response={
|
||||
status.OK: schemas.UserSignInOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
||||
},
|
||||
)
|
||||
@@ -94,7 +94,7 @@ def get_profile(request: HttpRequest) -> tuple[int, schemas.ViewUserOut]:
|
||||
auth=UserAuth(),
|
||||
response={
|
||||
status.OK: schemas.ViewUserOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -117,7 +117,7 @@ def patch_profile(
|
||||
auth=UserAuth(),
|
||||
response={
|
||||
status.OK: list[schemas.PromocodeViewOut],
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -180,7 +180,7 @@ def feed(
|
||||
auth=UserAuth(),
|
||||
response={
|
||||
status.OK: schemas.PromocodeViewOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -223,7 +223,7 @@ def get_promocode(
|
||||
auth=UserAuth(),
|
||||
response={
|
||||
status.OK: schemas.PromocodeLikeOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -248,7 +248,7 @@ def add_like(
|
||||
auth=UserAuth(),
|
||||
response={
|
||||
status.OK: schemas.PromocodeRemoveLikeOut,
|
||||
status.BAD_REQUEST: global_schemas.ValidationError,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user