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(
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",
)

View File

@ -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
)

View File

@ -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:

View File

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