<?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 QueryBase implements JsonSerializable
{
public function __construct(
// @DataMember(Order=1)
/** @var int|null */
public ?int $skip=null,
// @DataMember(Order=2)
/** @var int|null */
public ?int $take=null,
// @DataMember(Order=3)
/** @var string|null */
public ?string $orderBy=null,
// @DataMember(Order=4)
/** @var string|null */
public ?string $orderByDesc=null,
// @DataMember(Order=5)
/** @var string|null */
public ?string $include=null,
// @DataMember(Order=6)
/** @var string|null */
public ?string $fields=null,
// @DataMember(Order=7)
/** @var array<string,string>|null */
public ?array $meta=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['skip'])) $this->skip = $o['skip'];
if (isset($o['take'])) $this->take = $o['take'];
if (isset($o['orderBy'])) $this->orderBy = $o['orderBy'];
if (isset($o['orderByDesc'])) $this->orderByDesc = $o['orderByDesc'];
if (isset($o['include'])) $this->include = $o['include'];
if (isset($o['fields'])) $this->fields = $o['fields'];
if (isset($o['meta'])) $this->meta = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','string']), $o['meta']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->skip)) $o['skip'] = $this->skip;
if (isset($this->take)) $o['take'] = $this->take;
if (isset($this->orderBy)) $o['orderBy'] = $this->orderBy;
if (isset($this->orderByDesc)) $o['orderByDesc'] = $this->orderByDesc;
if (isset($this->include)) $o['include'] = $this->include;
if (isset($this->fields)) $o['fields'] = $this->fields;
if (isset($this->meta)) $o['meta'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','string']), $this->meta);
return empty($o) ? new class(){} : $o;
}
}
/**
* @template T
*/
class QueryDb extends QueryBase implements JsonSerializable
{
public array $genericArgs = [];
public static function create(array $genericArgs=[]): QueryDb {
$to = new QueryDb();
$to->genericArgs = $genericArgs;
return $to;
}
/**
* @param int|null $skip
* @param int|null $take
* @param string|null $orderBy
* @param string|null $orderByDesc
* @param string|null $include
* @param string|null $fields
* @param array<string,string>|null $meta
*/
public function __construct(
mixed $skip=null,
mixed $take=null,
mixed $orderBy=null,
mixed $orderByDesc=null,
mixed $include=null,
mixed $fields=null,
mixed $meta=null
) {
parent::__construct($skip,$take,$orderBy,$orderByDesc,$include,$fields,$meta);
}
/** @throws Exception */
public function fromMap($o): void {
parent::fromMap($o);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = parent::jsonSerialize();
return empty($o) ? new class(){} : $o;
}
}
// @DataContract
class AuditBase implements JsonSerializable
{
public function __construct(
// @DataMember(Order=1)
/** @var DateTime */
public DateTime $createdDate=new DateTime(),
// @DataMember(Order=2)
// @Required()
/** @var string */
public string $createdBy='',
// @DataMember(Order=3)
/** @var DateTime */
public DateTime $modifiedDate=new DateTime(),
// @DataMember(Order=4)
// @Required()
/** @var string */
public string $modifiedBy='',
// @DataMember(Order=5)
/** @var DateTime|null */
public ?DateTime $deletedDate=null,
// @DataMember(Order=6)
/** @var string|null */
public ?string $deletedBy=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['createdDate'])) $this->createdDate = JsonConverters::from('DateTime', $o['createdDate']);
if (isset($o['createdBy'])) $this->createdBy = $o['createdBy'];
if (isset($o['modifiedDate'])) $this->modifiedDate = JsonConverters::from('DateTime', $o['modifiedDate']);
if (isset($o['modifiedBy'])) $this->modifiedBy = $o['modifiedBy'];
if (isset($o['deletedDate'])) $this->deletedDate = JsonConverters::from('DateTime', $o['deletedDate']);
if (isset($o['deletedBy'])) $this->deletedBy = $o['deletedBy'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->createdDate)) $o['createdDate'] = JsonConverters::to('DateTime', $this->createdDate);
if (isset($this->createdBy)) $o['createdBy'] = $this->createdBy;
if (isset($this->modifiedDate)) $o['modifiedDate'] = JsonConverters::to('DateTime', $this->modifiedDate);
if (isset($this->modifiedBy)) $o['modifiedBy'] = $this->modifiedBy;
if (isset($this->deletedDate)) $o['deletedDate'] = JsonConverters::to('DateTime', $this->deletedDate);
if (isset($this->deletedBy)) $o['deletedBy'] = $this->deletedBy;
return empty($o) ? new class(){} : $o;
}
}
enum PhoneKind : string
{
case Home = 'Home';
case Mobile = 'Mobile';
case Work = 'Work';
}
class Phone implements JsonSerializable
{
public function __construct(
/** @var PhoneKind|null */
public ?PhoneKind $kind=null,
/** @var string */
public string $number='',
/** @var string */
public string $ext=''
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['kind'])) $this->kind = JsonConverters::from('PhoneKind', $o['kind']);
if (isset($o['number'])) $this->number = $o['number'];
if (isset($o['ext'])) $this->ext = $o['ext'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->kind)) $o['kind'] = JsonConverters::to('PhoneKind', $this->kind);
if (isset($this->number)) $o['number'] = $this->number;
if (isset($this->ext)) $o['ext'] = $this->ext;
return empty($o) ? new class(){} : $o;
}
}
class PlayerGameItem implements JsonSerializable
{
public function __construct(
/** @var int */
public int $id=0,
// @References("typeof(MyApp.ServiceModel.Player)")
/** @var int */
public int $playerId=0,
// @References("typeof(MyApp.ServiceModel.GameItem)")
/** @var string */
public string $gameItemName=''
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['playerId'])) $this->playerId = $o['playerId'];
if (isset($o['gameItemName'])) $this->gameItemName = $o['gameItemName'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->playerId)) $o['playerId'] = $this->playerId;
if (isset($this->gameItemName)) $o['gameItemName'] = $this->gameItemName;
return empty($o) ? new class(){} : $o;
}
}
enum PlayerRole : string
{
case Leader = 'Leader';
case Player = 'Player';
case NonPlayer = 'NonPlayer';
}
enum PlayerRegion : int
{
case Africa = 1;
case Americas = 2;
case Asia = 3;
case Australasia = 4;
case Europe = 5;
}
class Profile extends AuditBase implements JsonSerializable
{
/**
* @param DateTime $createdDate
* @param string $createdBy
* @param DateTime $modifiedDate
* @param string $modifiedBy
* @param DateTime|null $deletedDate
* @param string|null $deletedBy
*/
public function __construct(
DateTime $createdDate=new DateTime(),
string $createdBy='',
DateTime $modifiedDate=new DateTime(),
string $modifiedBy='',
?DateTime $deletedDate=null,
?string $deletedBy=null,
/** @var int */
public int $id=0,
/** @var PlayerRole|null */
public ?PlayerRole $role=null,
/** @var PlayerRegion|null */
public ?PlayerRegion $region=null,
/** @var string|null */
public ?string $username=null,
/** @var int */
public int $highScore=0,
/** @var int */
public int $gamesPlayed=0,
/** @var int */
public int $energy=0,
/** @var string|null */
public ?string $profileUrl=null,
/** @var string|null */
public ?string $coverUrl=null,
/** @var array<string,string>|null */
public ?array $meta=null
) {
parent::__construct($createdDate,$createdBy,$modifiedDate,$modifiedBy,$deletedDate,$deletedBy);
}
/** @throws Exception */
public function fromMap($o): void {
parent::fromMap($o);
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['role'])) $this->role = JsonConverters::from('PlayerRole', $o['role']);
if (isset($o['region'])) $this->region = JsonConverters::from('PlayerRegion', $o['region']);
if (isset($o['username'])) $this->username = $o['username'];
if (isset($o['highScore'])) $this->highScore = $o['highScore'];
if (isset($o['gamesPlayed'])) $this->gamesPlayed = $o['gamesPlayed'];
if (isset($o['energy'])) $this->energy = $o['energy'];
if (isset($o['profileUrl'])) $this->profileUrl = $o['profileUrl'];
if (isset($o['coverUrl'])) $this->coverUrl = $o['coverUrl'];
if (isset($o['meta'])) $this->meta = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','string']), $o['meta']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = parent::jsonSerialize();
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->role)) $o['role'] = JsonConverters::to('PlayerRole', $this->role);
if (isset($this->region)) $o['region'] = JsonConverters::to('PlayerRegion', $this->region);
if (isset($this->username)) $o['username'] = $this->username;
if (isset($this->highScore)) $o['highScore'] = $this->highScore;
if (isset($this->gamesPlayed)) $o['gamesPlayed'] = $this->gamesPlayed;
if (isset($this->energy)) $o['energy'] = $this->energy;
if (isset($this->profileUrl)) $o['profileUrl'] = $this->profileUrl;
if (isset($this->coverUrl)) $o['coverUrl'] = $this->coverUrl;
if (isset($this->meta)) $o['meta'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','string']), $this->meta);
return empty($o) ? new class(){} : $o;
}
}
class Player extends AuditBase implements JsonSerializable
{
/**
* @param DateTime $createdDate
* @param string $createdBy
* @param DateTime $modifiedDate
* @param string $modifiedBy
* @param DateTime|null $deletedDate
* @param string|null $deletedBy
*/
public function __construct(
DateTime $createdDate=new DateTime(),
string $createdBy='',
DateTime $modifiedDate=new DateTime(),
string $modifiedBy='',
?DateTime $deletedDate=null,
?string $deletedBy=null,
/** @var int */
public int $id=0,
// @Required()
/** @var string */
public string $firstName='',
/** @var string */
public string $lastName='',
/** @var string */
public string $email='',
/** @var array<Phone>|null */
public ?array $phoneNumbers=null,
/** @var array<PlayerGameItem>|null */
public ?array $gameItems=null,
/** @var Profile|null */
public ?Profile $profile=null,
/** @var int */
public int $profileId=0,
/** @var string */
public string $savedLevelId='',
/** @var int */
public int $rowVersion=0
) {
parent::__construct($createdDate,$createdBy,$modifiedDate,$modifiedBy,$deletedDate,$deletedBy);
}
/** @throws Exception */
public function fromMap($o): void {
parent::fromMap($o);
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['firstName'])) $this->firstName = $o['firstName'];
if (isset($o['lastName'])) $this->lastName = $o['lastName'];
if (isset($o['email'])) $this->email = $o['email'];
if (isset($o['phoneNumbers'])) $this->phoneNumbers = JsonConverters::fromArray('Phone', $o['phoneNumbers']);
if (isset($o['gameItems'])) $this->gameItems = JsonConverters::fromArray('PlayerGameItem', $o['gameItems']);
if (isset($o['profile'])) $this->profile = JsonConverters::from('Profile', $o['profile']);
if (isset($o['profileId'])) $this->profileId = $o['profileId'];
if (isset($o['savedLevelId'])) $this->savedLevelId = $o['savedLevelId'];
if (isset($o['rowVersion'])) $this->rowVersion = $o['rowVersion'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = parent::jsonSerialize();
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->firstName)) $o['firstName'] = $this->firstName;
if (isset($this->lastName)) $o['lastName'] = $this->lastName;
if (isset($this->email)) $o['email'] = $this->email;
if (isset($this->phoneNumbers)) $o['phoneNumbers'] = JsonConverters::toArray('Phone', $this->phoneNumbers);
if (isset($this->gameItems)) $o['gameItems'] = JsonConverters::toArray('PlayerGameItem', $this->gameItems);
if (isset($this->profile)) $o['profile'] = JsonConverters::to('Profile', $this->profile);
if (isset($this->profileId)) $o['profileId'] = $this->profileId;
if (isset($this->savedLevelId)) $o['savedLevelId'] = $this->savedLevelId;
if (isset($this->rowVersion)) $o['rowVersion'] = $this->rowVersion;
return empty($o) ? new class(){} : $o;
}
}
/**
* @template QueryDb of Player
*/
class QueryPlayer extends QueryDb implements JsonSerializable
{
/**
* @param int|null $skip
* @param int|null $take
* @param string|null $orderBy
* @param string|null $orderByDesc
* @param string|null $include
* @param string|null $fields
* @param array<string,string>|null $meta
*/
public function __construct(
?int $skip=null,
?int $take=null,
?string $orderBy=null,
?string $orderByDesc=null,
?string $include=null,
?string $fields=null,
?array $meta=null
) {
parent::__construct($skip,$take,$orderBy,$orderByDesc,$include,$fields,$meta);
}
/** @throws Exception */
public function fromMap($o): void {
parent::fromMap($o);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = parent::jsonSerialize();
return empty($o) ? new class(){} : $o;
}
}
class Todo implements JsonSerializable
{
public function __construct(
/** @var int */
public int $id=0,
/** @var string */
public string $text='',
/** @var bool|null */
public ?bool $isFinished=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['text'])) $this->text = $o['text'];
if (isset($o['isFinished'])) $this->isFinished = $o['isFinished'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->text)) $o['text'] = $this->text;
if (isset($this->isFinished)) $o['isFinished'] = $this->isFinished;
return empty($o) ? new class(){} : $o;
}
}
// @DataContract
/**
* @template T
*/
class QueryResponse implements JsonSerializable
{
public array $genericArgs = [];
public static function create(array $genericArgs=[]): QueryResponse {
$to = new QueryResponse();
$to->genericArgs = $genericArgs;
return $to;
}
public function __construct(
// @DataMember(Order=1)
/** @var int */
public mixed $offset=0,
// @DataMember(Order=2)
/** @var int */
public mixed $total=0,
// @DataMember(Order=3)
/** @var array<Todo>|null */
public mixed $results=null,
// @DataMember(Order=4)
/** @var array<string,string>|null */
public mixed $meta=null,
// @DataMember(Order=5)
/** @var ResponseStatus|null */
public mixed $responseStatus=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['offset'])) $this->offset = $o['offset'];
if (isset($o['total'])) $this->total = $o['total'];
if (isset($o['results'])) $this->results = JsonConverters::fromArray('Todo', $o['results']);
if (isset($o['meta'])) $this->meta = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','string']), $o['meta']);
if (isset($o['responseStatus'])) $this->responseStatus = JsonConverters::from('ResponseStatus', $o['responseStatus']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->offset)) $o['offset'] = $this->offset;
if (isset($this->total)) $o['total'] = $this->total;
if (isset($this->results)) $o['results'] = JsonConverters::toArray('Todo', $this->results);
if (isset($this->meta)) $o['meta'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','string']), $this->meta);
if (isset($this->responseStatus)) $o['responseStatus'] = JsonConverters::to('ResponseStatus', $this->responseStatus);
return empty($o) ? new class(){} : $o;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json
To embed the response in a jsonp callback, append ?callback=myCallback
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /json/reply/QueryPlayer HTTP/1.1
Host: blazor-gallery.servicestack.net
Accept: application/json
Content-Type: application/json
Content-Length: length
{"skip":0,"take":0,"orderBy":"String","orderByDesc":"String","include":"String","fields":"String","meta":{"String":"String"}}
HTTP/1.1 200 OK Content-Type: application/json Content-Length: length {"offset":0,"total":0,"results":[{"id":0,"firstName":"String","lastName":"String","email":"String","phoneNumbers":[{"kind":"Home","number":"String","ext":"String"}],"gameItems":[{"id":0,"playerId":0,"gameItemName":"String"}],"profile":{"id":0,"role":"Leader","region":"Africa","username":"String","highScore":0,"gamesPlayed":0,"energy":0,"profileUrl":"String","coverUrl":"String","meta":{"String":"String"},"createdDate":"0001-01-01T00:00:00","createdBy":"String","modifiedDate":"0001-01-01T00:00:00","modifiedBy":"String","deletedDate":"0001-01-01T00:00:00","deletedBy":"String"},"profileId":0,"savedLevelId":"00000000-0000-0000-0000-000000000000","rowVersion":0,"createdDate":"0001-01-01T00:00:00","createdBy":"String","modifiedDate":"0001-01-01T00:00:00","modifiedBy":"String","deletedDate":"0001-01-01T00:00:00","deletedBy":"String"}],"meta":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}