From 96ea0ac2abe7ff64ac7d7b68e6dab9dec244fa43 Mon Sep 17 00:00:00 2001 From: jerryfletcher21 Date: Sat, 15 Jun 2024 14:40:40 +0200 Subject: [PATCH] change current status to ChoiceField also added ENUM_NAME_OVERRIDES in SPECTACULAR_SETTINGS, because without it when generating api-latest.yaml this warning is returned: Warning: encountered multiple names for the same choice set (CurrentStatusEnum). This may be unwanted even though the generated schema is technically correct. Add an entry to ENUM_NAME_OVERRIDES to fix the naming. --- api/serializers.py | 7 ++++--- api/views.py | 12 +---------- docs/assets/schemas/api-latest.yaml | 32 ++++++++++++++++++++++++----- robosats/settings.py | 3 +++ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index 9ed0d782..61dd360e 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -628,10 +628,11 @@ class UpdateOrderSerializer(serializers.Serializer): mining_fee_rate = serializers.DecimalField( max_digits=6, decimal_places=3, allow_null=True, required=False, default=None ) - current_status = serializers.IntegerField( - min_value=Decimal(0), - max_value=18, + current_status = serializers.ChoiceField( + choices=Order.Status.choices, + default=None, allow_null=True, + allow_blank=True, required=False, help_text="Current order status for the client", ) diff --git a/api/views.py b/api/views.py index b5045259..0d43206a 100644 --- a/api/views.py +++ b/api/views.py @@ -511,7 +511,7 @@ class OrderView(viewsets.ViewSet): mining_fee_rate = serializer.data.get("mining_fee_rate") statement = serializer.data.get("statement") rating = serializer.data.get("rating") - current_status_int = serializer.data.get("current_status", None) + current_status = serializer.data.get("current_status", None) # 1) If action is take, it is a taker request! if action == "take": @@ -587,16 +587,6 @@ class OrderView(viewsets.ViewSet): # 3) If action is cancel elif action == "cancel": - if current_status_int is None: - current_status = None - else: - if current_status_int < 0 or current_status_int >= len(Order.Status): - return Response( - {"bad_request": "current_status is not in the correct range"}, - status.HTTP_400_BAD_REQUEST - ) - current_status = Order.Status(current_status_int) - valid, context = Logics.cancel_order( order, request.user, current_status=current_status ) diff --git a/docs/assets/schemas/api-latest.yaml b/docs/assets/schemas/api-latest.yaml index 1ab048b4..84115f45 100644 --- a/docs/assets/schemas/api-latest.yaml +++ b/docs/assets/schemas/api-latest.yaml @@ -1,7 +1,7 @@ openapi: 3.0.3 info: title: RoboSats REST API - version: 0.6.0 + version: 0.6.2 x-logo: url: https://raw.githubusercontent.com/Reckless-Satoshi/robosats/main/frontend/static/assets/images/robosats-0.1.1-banner.png backgroundColor: '#FFFFFF' @@ -1956,11 +1956,33 @@ components: pattern: ^-?\d{0,3}(?:\.\d{0,3})?$ nullable: true current_status: - type: integer - maximum: 18 - minimum: 0 nullable: true - description: Current order status for the client + description: |- + Current order status for the client + + * `0` - Waiting for maker bond + * `1` - Public + * `2` - Paused + * `3` - Waiting for taker bond + * `4` - Cancelled + * `5` - Expired + * `6` - Waiting for trade collateral and buyer invoice + * `7` - Waiting only for seller trade collateral + * `8` - Waiting only for buyer invoice + * `9` - Sending fiat - In chatroom + * `10` - Fiat sent - In chatroom + * `11` - In dispute + * `12` - Collaboratively cancelled + * `13` - Sending satoshis to buyer + * `14` - Sucessful trade + * `15` - Failed lightning network routing + * `16` - Wait for dispute resolution + * `17` - Maker lost dispute + * `18` - Taker lost dispute + oneOf: + - $ref: '#/components/schemas/StatusEnum' + - $ref: '#/components/schemas/BlankEnum' + - $ref: '#/components/schemas/NullEnum' required: - action Version: diff --git a/robosats/settings.py b/robosats/settings.py index b25a6bf2..fafb4f55 100644 --- a/robosats/settings.py +++ b/robosats/settings.py @@ -146,6 +146,9 @@ SPECTACULAR_SETTINGS = { } }, "REDOC_DIST": "SIDECAR", + "ENUM_NAME_OVERRIDES": { + "StatusEnum": "api.models.order.Order.Status", + } }