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