All Verbs | /orders | ||
---|---|---|---|
All Verbs | /orders/page/{Page} | ||
All Verbs | /customers/{CustomerId}/orders |
<?php namespace dtos;
use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};
// @DataContract
class Order implements JsonSerializable
{
public function __construct(
// @DataMember
/** @var int */
public int $id=0,
// @DataMember
/** @var string */
public string $customerId='',
// @DataMember
/** @var int */
public int $employeeId=0,
// @DataMember
/** @var DateTime|null */
public ?DateTime $orderDate=null,
// @DataMember
/** @var DateTime|null */
public ?DateTime $requiredDate=null,
// @DataMember
/** @var DateTime|null */
public ?DateTime $shippedDate=null,
// @DataMember
/** @var int|null */
public ?int $shipVia=null,
// @DataMember
/** @var float */
public float $freight=0.0,
// @DataMember
/** @var string */
public string $shipName='',
// @DataMember
/** @var string */
public string $shipAddress='',
// @DataMember
/** @var string */
public string $shipCity='',
// @DataMember
/** @var string */
public string $shipRegion='',
// @DataMember
/** @var string */
public string $shipPostalCode='',
// @DataMember
/** @var string */
public string $shipCountry=''
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['customerId'])) $this->customerId = $o['customerId'];
if (isset($o['employeeId'])) $this->employeeId = $o['employeeId'];
if (isset($o['orderDate'])) $this->orderDate = JsonConverters::from('DateTime', $o['orderDate']);
if (isset($o['requiredDate'])) $this->requiredDate = JsonConverters::from('DateTime', $o['requiredDate']);
if (isset($o['shippedDate'])) $this->shippedDate = JsonConverters::from('DateTime', $o['shippedDate']);
if (isset($o['shipVia'])) $this->shipVia = $o['shipVia'];
if (isset($o['freight'])) $this->freight = $o['freight'];
if (isset($o['shipName'])) $this->shipName = $o['shipName'];
if (isset($o['shipAddress'])) $this->shipAddress = $o['shipAddress'];
if (isset($o['shipCity'])) $this->shipCity = $o['shipCity'];
if (isset($o['shipRegion'])) $this->shipRegion = $o['shipRegion'];
if (isset($o['shipPostalCode'])) $this->shipPostalCode = $o['shipPostalCode'];
if (isset($o['shipCountry'])) $this->shipCountry = $o['shipCountry'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->customerId)) $o['customerId'] = $this->customerId;
if (isset($this->employeeId)) $o['employeeId'] = $this->employeeId;
if (isset($this->orderDate)) $o['orderDate'] = JsonConverters::to('DateTime', $this->orderDate);
if (isset($this->requiredDate)) $o['requiredDate'] = JsonConverters::to('DateTime', $this->requiredDate);
if (isset($this->shippedDate)) $o['shippedDate'] = JsonConverters::to('DateTime', $this->shippedDate);
if (isset($this->shipVia)) $o['shipVia'] = $this->shipVia;
if (isset($this->freight)) $o['freight'] = $this->freight;
if (isset($this->shipName)) $o['shipName'] = $this->shipName;
if (isset($this->shipAddress)) $o['shipAddress'] = $this->shipAddress;
if (isset($this->shipCity)) $o['shipCity'] = $this->shipCity;
if (isset($this->shipRegion)) $o['shipRegion'] = $this->shipRegion;
if (isset($this->shipPostalCode)) $o['shipPostalCode'] = $this->shipPostalCode;
if (isset($this->shipCountry)) $o['shipCountry'] = $this->shipCountry;
return empty($o) ? new class(){} : $o;
}
}
// @DataContract
class OrderDetail implements JsonSerializable
{
public function __construct(
// @DataMember
/** @var int */
public int $orderId=0,
// @DataMember
/** @var int */
public int $productId=0,
// @DataMember
/** @var float */
public float $unitPrice=0.0,
// @DataMember
/** @var int */
public int $quantity=0,
// @DataMember
/** @var float */
public float $discount=0.0
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['orderId'])) $this->orderId = $o['orderId'];
if (isset($o['productId'])) $this->productId = $o['productId'];
if (isset($o['unitPrice'])) $this->unitPrice = $o['unitPrice'];
if (isset($o['quantity'])) $this->quantity = $o['quantity'];
if (isset($o['discount'])) $this->discount = $o['discount'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->orderId)) $o['orderId'] = $this->orderId;
if (isset($this->productId)) $o['productId'] = $this->productId;
if (isset($this->unitPrice)) $o['unitPrice'] = $this->unitPrice;
if (isset($this->quantity)) $o['quantity'] = $this->quantity;
if (isset($this->discount)) $o['discount'] = $this->discount;
return empty($o) ? new class(){} : $o;
}
}
// @DataContract
class CustomerOrder implements JsonSerializable
{
public function __construct(
// @DataMember
/** @var Order|null */
public ?Order $order=null,
// @DataMember
/** @var array<OrderDetail>|null */
public ?array $orderDetails=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['order'])) $this->order = JsonConverters::from('Order', $o['order']);
if (isset($o['orderDetails'])) $this->orderDetails = JsonConverters::fromArray('OrderDetail', $o['orderDetails']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->order)) $o['order'] = JsonConverters::to('Order', $this->order);
if (isset($this->orderDetails)) $o['orderDetails'] = JsonConverters::toArray('OrderDetail', $this->orderDetails);
return empty($o) ? new class(){} : $o;
}
}
// @DataContract
class OrdersResponse implements JsonSerializable
{
public function __construct(
// @DataMember
/** @var array<CustomerOrder>|null */
public ?array $results=null,
// @DataMember
/** @var ResponseStatus|null */
public ?ResponseStatus $responseStatus=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['results'])) $this->results = JsonConverters::fromArray('CustomerOrder', $o['results']);
if (isset($o['responseStatus'])) $this->responseStatus = JsonConverters::from('ResponseStatus', $o['responseStatus']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->results)) $o['results'] = JsonConverters::toArray('CustomerOrder', $this->results);
if (isset($this->responseStatus)) $o['responseStatus'] = JsonConverters::to('ResponseStatus', $this->responseStatus);
return empty($o) ? new class(){} : $o;
}
}
class GetOrders implements IGet, JsonSerializable
{
public function __construct(
/** @var int|null */
public ?int $page=null,
/** @var string */
public string $customerId=''
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['page'])) $this->page = $o['page'];
if (isset($o['customerId'])) $this->customerId = $o['customerId'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->page)) $o['page'] = $this->page;
if (isset($this->customerId)) $o['customerId'] = $this->customerId;
return empty($o) ? new class(){} : $o;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .other suffix or ?format=other
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /orders HTTP/1.1
Host: northwind.netcore.io
Accept: text/x-vcard
Content-Type: text/x-vcard
Content-Length: length
{"page":0,"customerId":"String"}
HTTP/1.1 200 OK Content-Type: text/x-vcard Content-Length: length {"results":[{"order":{"id":0,"customerId":"String","employeeId":0,"orderDate":"\/Date(-62135596800000-0000)\/","requiredDate":"\/Date(-62135596800000-0000)\/","shippedDate":"\/Date(-62135596800000-0000)\/","shipVia":0,"freight":0,"shipName":"String","shipAddress":"String","shipCity":"String","shipRegion":"String","shipPostalCode":"String","shipCountry":"String"},"orderDetails":[{"orderId":0,"productId":0,"unitPrice":0,"quantity":0,"discount":0}]}],"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}