<?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};
enum FileAccessType : string
{
case Public = 'Public';
case Team = 'Team';
case Private = 'Private';
}
class FileSystemFile implements IFile, JsonSerializable
{
public function __construct(
/** @var int */
public int $id=0,
/** @var string */
public string $fileName='',
/** @var string */
public string $filePath='',
/** @var string */
public string $contentType='',
/** @var int */
public int $contentLength=0,
// @References("typeof(MyApp.ServiceModel.FileSystemItem)")
/** @var int */
public int $fileSystemItemId=0
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['fileName'])) $this->fileName = $o['fileName'];
if (isset($o['filePath'])) $this->filePath = $o['filePath'];
if (isset($o['contentType'])) $this->contentType = $o['contentType'];
if (isset($o['contentLength'])) $this->contentLength = $o['contentLength'];
if (isset($o['fileSystemItemId'])) $this->fileSystemItemId = $o['fileSystemItemId'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->fileName)) $o['fileName'] = $this->fileName;
if (isset($this->filePath)) $o['filePath'] = $this->filePath;
if (isset($this->contentType)) $o['contentType'] = $this->contentType;
if (isset($this->contentLength)) $o['contentLength'] = $this->contentLength;
if (isset($this->fileSystemItemId)) $o['fileSystemItemId'] = $this->fileSystemItemId;
return empty($o) ? new class(){} : $o;
}
}
class FileSystemItem implements IFileItem, JsonSerializable
{
public function __construct(
/** @var int */
public int $id=0,
/** @var FileAccessType|null */
public ?FileAccessType $fileAccessType=null,
/** @var FileSystemFile|null */
public ?FileSystemFile $file=null,
/** @var string */
public string $appUserId=''
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['fileAccessType'])) $this->fileAccessType = JsonConverters::from('FileAccessType', $o['fileAccessType']);
if (isset($o['file'])) $this->file = JsonConverters::from('FileSystemFile', $o['file']);
if (isset($o['appUserId'])) $this->appUserId = $o['appUserId'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->fileAccessType)) $o['fileAccessType'] = JsonConverters::to('FileAccessType', $this->fileAccessType);
if (isset($this->file)) $o['file'] = JsonConverters::to('FileSystemFile', $this->file);
if (isset($this->appUserId)) $o['appUserId'] = $this->appUserId;
return empty($o) ? new class(){} : $o;
}
}
/**
* @template ICreateDb of FileSystemItem
*/
class CreateFileSystemItem implements ICreateDb, IFileItem, JsonSerializable
{
public function __construct(
/** @var FileAccessType|null */
public ?FileAccessType $fileAccessType=null,
/** @var FileSystemFile|null */
public ?FileSystemFile $file=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['fileAccessType'])) $this->fileAccessType = JsonConverters::from('FileAccessType', $o['fileAccessType']);
if (isset($o['file'])) $this->file = JsonConverters::from('FileSystemFile', $o['file']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->fileAccessType)) $o['fileAccessType'] = JsonConverters::to('FileAccessType', $this->fileAccessType);
if (isset($this->file)) $o['file'] = JsonConverters::to('FileSystemFile', $this->file);
return empty($o) ? new class(){} : $o;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /jsv/reply/CreateFileSystemItem HTTP/1.1
Host: blazor-gallery.servicestack.net
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length
{
fileAccessType: Public,
file:
{
id: 0,
fileName: String,
filePath: String,
contentType: String,
contentLength: 0,
fileSystemItemId: 0
}
}
HTTP/1.1 200 OK Content-Type: text/jsv Content-Length: length { id: 0, fileAccessType: Public, file: { id: 0, fileName: String, filePath: String, contentType: String, contentLength: 0, fileSystemItemId: 0 }, appUserId: String }