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.
This commit is contained in:
jerryfletcher21
2024-06-15 14:40:40 +02:00
parent 6647e164c3
commit 96ea0ac2ab
4 changed files with 35 additions and 19 deletions

View File

@ -628,10 +628,11 @@ class UpdateOrderSerializer(serializers.Serializer):
mining_fee_rate = serializers.DecimalField( mining_fee_rate = serializers.DecimalField(
max_digits=6, decimal_places=3, allow_null=True, required=False, default=None max_digits=6, decimal_places=3, allow_null=True, required=False, default=None
) )
current_status = serializers.IntegerField( current_status = serializers.ChoiceField(
min_value=Decimal(0), choices=Order.Status.choices,
max_value=18, default=None,
allow_null=True, allow_null=True,
allow_blank=True,
required=False, required=False,
help_text="Current order status for the client", help_text="Current order status for the client",
) )

View File

@ -511,7 +511,7 @@ class OrderView(viewsets.ViewSet):
mining_fee_rate = serializer.data.get("mining_fee_rate") mining_fee_rate = serializer.data.get("mining_fee_rate")
statement = serializer.data.get("statement") statement = serializer.data.get("statement")
rating = serializer.data.get("rating") 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! # 1) If action is take, it is a taker request!
if action == "take": if action == "take":
@ -587,16 +587,6 @@ class OrderView(viewsets.ViewSet):
# 3) If action is cancel # 3) If action is cancel
elif action == "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( valid, context = Logics.cancel_order(
order, request.user, current_status=current_status order, request.user, current_status=current_status
) )

View File

@ -1,7 +1,7 @@
openapi: 3.0.3 openapi: 3.0.3
info: info:
title: RoboSats REST API title: RoboSats REST API
version: 0.6.0 version: 0.6.2
x-logo: x-logo:
url: https://raw.githubusercontent.com/Reckless-Satoshi/robosats/main/frontend/static/assets/images/robosats-0.1.1-banner.png url: https://raw.githubusercontent.com/Reckless-Satoshi/robosats/main/frontend/static/assets/images/robosats-0.1.1-banner.png
backgroundColor: '#FFFFFF' backgroundColor: '#FFFFFF'
@ -1956,11 +1956,33 @@ components:
pattern: ^-?\d{0,3}(?:\.\d{0,3})?$ pattern: ^-?\d{0,3}(?:\.\d{0,3})?$
nullable: true nullable: true
current_status: current_status:
type: integer
maximum: 18
minimum: 0
nullable: true 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: required:
- action - action
Version: Version:

View File

@ -146,6 +146,9 @@ SPECTACULAR_SETTINGS = {
} }
}, },
"REDOC_DIST": "SIDECAR", "REDOC_DIST": "SIDECAR",
"ENUM_NAME_OVERRIDES": {
"StatusEnum": "api.models.order.Order.Status",
}
} }