<?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 IdResponse implements JsonSerializable
{
public function __construct(
// @DataMember(Order=1)
/** @var string|null */
public ?string $id=null,
// @DataMember(Order=2)
/** @var ResponseStatus|null */
public ?ResponseStatus $responseStatus=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['responseStatus'])) $this->responseStatus = JsonConverters::from('ResponseStatus', $o['responseStatus']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->responseStatus)) $o['responseStatus'] = JsonConverters::to('ResponseStatus', $this->responseStatus);
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;
}
/**
* @template ICreateDb of Profile
*/
class CreateProfile implements ICreateDb, JsonSerializable
{
public function __construct(
/** @var PlayerRole|null */
public ?PlayerRole $role=null,
/** @var PlayerRegion|null */
public ?PlayerRegion $region=null,
// @Validate(Validator="NotEmpty")
/** @var string */
public string $username='',
/** @var int */
public int $highScore=0,
/** @var int */
public int $gamesPlayed=0,
// @Validate(Validator="InclusiveBetween(0,100)")
/** @var int */
public int $energy=0,
/** @var string|null */
public ?string $profileUrl=null,
/** @var string|null */
public ?string $coverUrl=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
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'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
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;
return empty($o) ? new class(){} : $o;
}
}
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 /csv/reply/CreateProfile HTTP/1.1
Host: blazor-gallery.servicestack.net
Accept: text/csv
Content-Type: text/csv
Content-Length: length
{"role":"Leader","region":"Africa","username":"String","highScore":0,"gamesPlayed":0,"energy":0,"profileUrl":"String","coverUrl":"String"}
HTTP/1.1 200 OK Content-Type: text/csv Content-Length: length {"id":"String","responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}