Northwind Web Services

<back to all web services

CachedGetOrders

Cached
The following routes are available for this service:
All Verbs/cached/orders
All Verbs/cached/orders/page/{Page}
All Verbs/cached/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 CachedGetOrders 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;
    }
}

PHP CachedGetOrders DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .xml suffix or ?format=xml

HTTP + XML

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /cached/orders HTTP/1.1 
Host: northwind.netcore.io 
Accept: application/xml
Content-Type: application/xml
Content-Length: length

<CachedGetOrders xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Northwind.ServiceModel">
  <CustomerId>String</CustomerId>
  <Page>0</Page>
</CachedGetOrders>
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: length

<OrdersResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Northwind.ServiceModel">
  <ResponseStatus xmlns:d2p1="http://schemas.servicestack.net/types">
    <d2p1:ErrorCode>String</d2p1:ErrorCode>
    <d2p1:Message>String</d2p1:Message>
    <d2p1:StackTrace>String</d2p1:StackTrace>
    <d2p1:Errors>
      <d2p1:ResponseError>
        <d2p1:ErrorCode>String</d2p1:ErrorCode>
        <d2p1:FieldName>String</d2p1:FieldName>
        <d2p1:Message>String</d2p1:Message>
        <d2p1:Meta xmlns:d5p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
          <d5p1:KeyValueOfstringstring>
            <d5p1:Key>String</d5p1:Key>
            <d5p1:Value>String</d5p1:Value>
          </d5p1:KeyValueOfstringstring>
        </d2p1:Meta>
      </d2p1:ResponseError>
    </d2p1:Errors>
    <d2p1:Meta xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
      <d3p1:KeyValueOfstringstring>
        <d3p1:Key>String</d3p1:Key>
        <d3p1:Value>String</d3p1:Value>
      </d3p1:KeyValueOfstringstring>
    </d2p1:Meta>
  </ResponseStatus>
  <Results xmlns:d2p1="http://schemas.datacontract.org/2004/07/Northwind.ServiceModel.Types">
    <d2p1:CustomerOrder>
      <d2p1:Order>
        <d2p1:CustomerId>String</d2p1:CustomerId>
        <d2p1:EmployeeId>0</d2p1:EmployeeId>
        <d2p1:Freight>0</d2p1:Freight>
        <d2p1:Id>0</d2p1:Id>
        <d2p1:OrderDate>0001-01-01T00:00:00</d2p1:OrderDate>
        <d2p1:RequiredDate>0001-01-01T00:00:00</d2p1:RequiredDate>
        <d2p1:ShipAddress>String</d2p1:ShipAddress>
        <d2p1:ShipCity>String</d2p1:ShipCity>
        <d2p1:ShipCountry>String</d2p1:ShipCountry>
        <d2p1:ShipName>String</d2p1:ShipName>
        <d2p1:ShipPostalCode>String</d2p1:ShipPostalCode>
        <d2p1:ShipRegion>String</d2p1:ShipRegion>
        <d2p1:ShipVia>0</d2p1:ShipVia>
        <d2p1:ShippedDate>0001-01-01T00:00:00</d2p1:ShippedDate>
      </d2p1:Order>
      <d2p1:OrderDetails>
        <d2p1:OrderDetail>
          <d2p1:Discount>0</d2p1:Discount>
          <d2p1:OrderId>0</d2p1:OrderId>
          <d2p1:ProductId>0</d2p1:ProductId>
          <d2p1:Quantity>0</d2p1:Quantity>
          <d2p1:UnitPrice>0</d2p1:UnitPrice>
        </d2p1:OrderDetail>
      </d2p1:OrderDetails>
    </d2p1:CustomerOrder>
  </Results>
</OrdersResponse>