All Verbs | /cached/customers/{Id} |
---|
<?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 Customer implements JsonSerializable
{
public function __construct(
// @DataMember
/** @var string */
public string $id='',
// @DataMember
/** @var string */
public string $companyName='',
// @DataMember
/** @var string */
public string $contactName='',
// @DataMember
/** @var string */
public string $contactTitle='',
// @DataMember
/** @var string */
public string $address='',
// @DataMember
/** @var string */
public string $city='',
// @DataMember
/** @var string */
public string $region='',
// @DataMember
/** @var string */
public string $postalCode='',
// @DataMember
/** @var string */
public string $country='',
// @DataMember
/** @var string */
public string $phone='',
// @DataMember
/** @var string */
public string $fax=''
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['companyName'])) $this->companyName = $o['companyName'];
if (isset($o['contactName'])) $this->contactName = $o['contactName'];
if (isset($o['contactTitle'])) $this->contactTitle = $o['contactTitle'];
if (isset($o['address'])) $this->address = $o['address'];
if (isset($o['city'])) $this->city = $o['city'];
if (isset($o['region'])) $this->region = $o['region'];
if (isset($o['postalCode'])) $this->postalCode = $o['postalCode'];
if (isset($o['country'])) $this->country = $o['country'];
if (isset($o['phone'])) $this->phone = $o['phone'];
if (isset($o['fax'])) $this->fax = $o['fax'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->companyName)) $o['companyName'] = $this->companyName;
if (isset($this->contactName)) $o['contactName'] = $this->contactName;
if (isset($this->contactTitle)) $o['contactTitle'] = $this->contactTitle;
if (isset($this->address)) $o['address'] = $this->address;
if (isset($this->city)) $o['city'] = $this->city;
if (isset($this->region)) $o['region'] = $this->region;
if (isset($this->postalCode)) $o['postalCode'] = $this->postalCode;
if (isset($this->country)) $o['country'] = $this->country;
if (isset($this->phone)) $o['phone'] = $this->phone;
if (isset($this->fax)) $o['fax'] = $this->fax;
return empty($o) ? new class(){} : $o;
}
}
// @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 CustomerDetailsResponse implements JsonSerializable
{
public function __construct(
// @DataMember
/** @var Customer|null */
public ?Customer $customer=null,
// @DataMember
/** @var array<CustomerOrder>|null */
public ?array $orders=null,
// @DataMember
/** @var ResponseStatus|null */
public ?ResponseStatus $responseStatus=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['customer'])) $this->customer = JsonConverters::from('Customer', $o['customer']);
if (isset($o['orders'])) $this->orders = JsonConverters::fromArray('CustomerOrder', $o['orders']);
if (isset($o['responseStatus'])) $this->responseStatus = JsonConverters::from('ResponseStatus', $o['responseStatus']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->customer)) $o['customer'] = JsonConverters::to('Customer', $this->customer);
if (isset($this->orders)) $o['orders'] = JsonConverters::toArray('CustomerOrder', $this->orders);
if (isset($this->responseStatus)) $o['responseStatus'] = JsonConverters::to('ResponseStatus', $this->responseStatus);
return empty($o) ? new class(){} : $o;
}
}
class CachedGetCustomerDetails implements IGet, JsonSerializable
{
public function __construct(
/** @var string */
public string $id=''
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
return empty($o) ? new class(){} : $o;
}
}
PHP CachedGetCustomerDetails DTOs
To override the Content-type in your clients, use the HTTP Accept Header, append the .csv suffix or ?format=csv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /cached/customers/{Id} HTTP/1.1
Host: northwind.netcore.io
Accept: text/csv
Content-Type: text/csv
Content-Length: length
{"id":"String"}
HTTP/1.1 200 OK Content-Type: text/csv Content-Length: length {"customer":{"id":"String","companyName":"String","contactName":"String","contactTitle":"String","address":"String","city":"String","region":"String","postalCode":"String","country":"String","phone":"String","fax":"String"},"orders":[{"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"}}}