mirror of
https://github.com/Blockstream/satellite-api.git
synced 2024-11-19 04:50:01 +01:00
Return more information on GET /admin/order
In addition to the info returned by the regular /order endpoint, return a few more admin-only fields.
This commit is contained in:
parent
895d9f785f
commit
b3454d7340
@ -21,6 +21,12 @@ class Order(db.Model):
|
|||||||
region_code = db.Column(db.Integer)
|
region_code = db.Column(db.Integer)
|
||||||
channel = db.Column(db.Integer, default=1)
|
channel = db.Column(db.Integer, default=1)
|
||||||
invoices = db.relationship('Invoice', backref='order', lazy=True)
|
invoices = db.relationship('Invoice', backref='order', lazy=True)
|
||||||
|
tx_confirmations = db.relationship('TxConfirmation',
|
||||||
|
backref='order',
|
||||||
|
lazy=True)
|
||||||
|
rx_confirmations = db.relationship('RxConfirmation',
|
||||||
|
backref='order',
|
||||||
|
lazy=True)
|
||||||
|
|
||||||
|
|
||||||
class Invoice(db.Model):
|
class Invoice(db.Model):
|
||||||
|
@ -16,7 +16,7 @@ from error import get_http_error_resp
|
|||||||
from invoice_helpers import new_invoice, pay_invoice
|
from invoice_helpers import new_invoice, pay_invoice
|
||||||
from models import Order, RxConfirmation, TxConfirmation
|
from models import Order, RxConfirmation, TxConfirmation
|
||||||
from regions import region_number_list_to_code
|
from regions import region_number_list_to_code
|
||||||
from schemas import order_schema, orders_schema,\
|
from schemas import admin_order_schema, order_schema, orders_schema,\
|
||||||
order_upload_req_schema, order_bump_schema,\
|
order_upload_req_schema, order_bump_schema,\
|
||||||
rx_confirmation_schema, tx_confirmation_schema
|
rx_confirmation_schema, tx_confirmation_schema
|
||||||
import bidding
|
import bidding
|
||||||
@ -50,8 +50,8 @@ class OrderResource(Resource):
|
|||||||
constants.CHANNEL_INFO[order.channel].user_permissions:
|
constants.CHANNEL_INFO[order.channel].user_permissions:
|
||||||
return get_http_error_resp('ORDER_CHANNEL_UNAUTHORIZED_OP',
|
return get_http_error_resp('ORDER_CHANNEL_UNAUTHORIZED_OP',
|
||||||
order.channel)
|
order.channel)
|
||||||
|
schema = admin_order_schema if admin_mode else order_schema
|
||||||
return order_schema.dump(order)
|
return schema.dump(order)
|
||||||
|
|
||||||
def delete(self, uuid):
|
def delete(self, uuid):
|
||||||
admin_mode = request.path.startswith("/admin/")
|
admin_mode = request.path.startswith("/admin/")
|
||||||
|
@ -3,7 +3,8 @@ from datetime import datetime, timedelta
|
|||||||
|
|
||||||
from marshmallow import fields, Schema, validate, ValidationError
|
from marshmallow import fields, Schema, validate, ValidationError
|
||||||
|
|
||||||
from regions import all_region_numbers, region_code_to_number_list
|
from regions import all_region_numbers, region_code_to_number_list, \
|
||||||
|
region_id_to_number
|
||||||
import constants
|
import constants
|
||||||
|
|
||||||
|
|
||||||
@ -25,6 +26,16 @@ class OrderSchema(Schema):
|
|||||||
lambda obj: region_code_to_number_list(obj.region_code))
|
lambda obj: region_code_to_number_list(obj.region_code))
|
||||||
|
|
||||||
|
|
||||||
|
class AdminOrderSchema(OrderSchema):
|
||||||
|
channel = fields.Integer()
|
||||||
|
tx_confirmations = fields.Function(
|
||||||
|
lambda obj:
|
||||||
|
[region_id_to_number(x.region_id) for x in obj.tx_confirmations])
|
||||||
|
rx_confirmations = fields.Function(
|
||||||
|
lambda obj:
|
||||||
|
[region_id_to_number(x.region_id) for x in obj.rx_confirmations])
|
||||||
|
|
||||||
|
|
||||||
def must_be_region_number(input):
|
def must_be_region_number(input):
|
||||||
if input not in all_region_numbers:
|
if input not in all_region_numbers:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
@ -81,6 +92,7 @@ class RxConfirmationSchema(Schema):
|
|||||||
|
|
||||||
|
|
||||||
order_schema = OrderSchema()
|
order_schema = OrderSchema()
|
||||||
|
admin_order_schema = AdminOrderSchema()
|
||||||
order_upload_req_schema = OrderUploadReqSchema()
|
order_upload_req_schema = OrderUploadReqSchema()
|
||||||
order_bump_schema = OrderBumpSchema()
|
order_bump_schema = OrderBumpSchema()
|
||||||
orders_schema = OrdersSchema()
|
orders_schema = OrdersSchema()
|
||||||
|
Loading…
Reference in New Issue
Block a user