Required role: | Moderator |
<?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};
class StatBase implements JsonSerializable
{
public function __construct(
/** @var string */
public string $refId='',
/** @var int|null */
public ?int $appUserId=null,
/** @var string */
public string $rawUrl='',
/** @var string */
public string $remoteIp='',
/** @var DateTime */
public DateTime $createdDate=new DateTime()
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['refId'])) $this->refId = $o['refId'];
if (isset($o['appUserId'])) $this->appUserId = $o['appUserId'];
if (isset($o['rawUrl'])) $this->rawUrl = $o['rawUrl'];
if (isset($o['remoteIp'])) $this->remoteIp = $o['remoteIp'];
if (isset($o['createdDate'])) $this->createdDate = JsonConverters::from('DateTime', $o['createdDate']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->refId)) $o['refId'] = $this->refId;
if (isset($this->appUserId)) $o['appUserId'] = $this->appUserId;
if (isset($this->rawUrl)) $o['rawUrl'] = $this->rawUrl;
if (isset($this->remoteIp)) $o['remoteIp'] = $this->remoteIp;
if (isset($this->createdDate)) $o['createdDate'] = JsonConverters::to('DateTime', $this->createdDate);
return empty($o) ? new class(){} : $o;
}
}
enum SignupType : string
{
case Updates = 'Updates';
case Beta = 'Beta';
}
class Signup extends StatBase implements JsonSerializable
{
/**
* @param string $refId
* @param int|null $appUserId
* @param string $rawUrl
* @param string $remoteIp
* @param DateTime $createdDate
*/
public function __construct(
string $refId='',
?int $appUserId=null,
string $rawUrl='',
string $remoteIp='',
DateTime $createdDate=new DateTime(),
/** @var int */
public int $id=0,
/** @var SignupType|null */
public ?SignupType $type=null,
/** @var string */
public string $email='',
/** @var string|null */
public ?string $name=null,
/** @var DateTime|null */
public ?DateTime $cancelledDate=null
) {
parent::__construct($refId,$appUserId,$rawUrl,$remoteIp,$createdDate);
}
/** @throws Exception */
public function fromMap($o): void {
parent::fromMap($o);
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['type'])) $this->type = JsonConverters::from('SignupType', $o['type']);
if (isset($o['email'])) $this->email = $o['email'];
if (isset($o['name'])) $this->name = $o['name'];
if (isset($o['cancelledDate'])) $this->cancelledDate = JsonConverters::from('DateTime', $o['cancelledDate']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = parent::jsonSerialize();
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->type)) $o['type'] = JsonConverters::to('SignupType', $this->type);
if (isset($this->email)) $o['email'] = $this->email;
if (isset($this->name)) $o['name'] = $this->name;
if (isset($this->cancelledDate)) $o['cancelledDate'] = JsonConverters::to('DateTime', $this->cancelledDate);
return empty($o) ? new class(){} : $o;
}
}
// @ValidateRequest(Validator="HasRole(`Moderator`)")
/**
* @template IPatchDb of Signup
*/
class UpdateSignup implements IPatchDb, JsonSerializable
{
public function __construct(
/** @var int */
public int $id=0,
/** @var SignupType|null */
public ?SignupType $type=null,
// @Validate(Validator="Email")
/** @var string|null */
public ?string $email=null,
/** @var string|null */
public ?string $name=null,
/** @var DateTime|null */
public ?DateTime $cancelledDate=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['type'])) $this->type = JsonConverters::from('SignupType', $o['type']);
if (isset($o['email'])) $this->email = $o['email'];
if (isset($o['name'])) $this->name = $o['name'];
if (isset($o['cancelledDate'])) $this->cancelledDate = JsonConverters::from('DateTime', $o['cancelledDate']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->type)) $o['type'] = JsonConverters::to('SignupType', $this->type);
if (isset($this->email)) $o['email'] = $this->email;
if (isset($this->name)) $o['name'] = $this->name;
if (isset($this->cancelledDate)) $o['cancelledDate'] = JsonConverters::to('DateTime', $this->cancelledDate);
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 /jsonl/reply/UpdateSignup HTTP/1.1
Host: blazordiffusion.com
Accept: text/jsonl
Content-Type: text/jsonl
Content-Length: length
{"id":0,"type":"Updates","email":"String","name":"String","cancelledDate":"0001-01-01T00:00:00"}
HTTP/1.1 200 OK Content-Type: text/jsonl Content-Length: length {"id":0,"type":"Updates","email":"String","name":"String","cancelledDate":"0001-01-01T00:00:00","refId":"String","appUserId":0,"rawUrl":"String","remoteIp":"String","createdDate":"0001-01-01T00:00:00"}