Blazor Diffusion

<back to all web services

UserData

User
Requires Authentication
<?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 Likes implements JsonSerializable
{
    public function __construct(
        /** @var array<int>|null */
        public ?array $artifactIds=null,
        /** @var array<int>|null */
        public ?array $albumIds=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['artifactIds'])) $this->artifactIds = JsonConverters::fromArray('int', $o['artifactIds']);
        if (isset($o['albumIds'])) $this->albumIds = JsonConverters::fromArray('int', $o['albumIds']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->artifactIds)) $o['artifactIds'] = JsonConverters::toArray('int', $this->artifactIds);
        if (isset($this->albumIds)) $o['albumIds'] = JsonConverters::toArray('int', $this->albumIds);
        return empty($o) ? new class(){} : $o;
    }
}

class AlbumResult implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $id=0,
        /** @var string */
        public string $name='',
        /** @var string */
        public string $slug='',
        /** @var string */
        public string $albumRef='',
        /** @var string */
        public string $ownerRef='',
        /** @var int|null */
        public ?int $primaryArtifactId=null,
        /** @var int */
        public int $score=0,
        /** @var array<int>|null */
        public ?array $artifactIds=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['name'])) $this->name = $o['name'];
        if (isset($o['slug'])) $this->slug = $o['slug'];
        if (isset($o['albumRef'])) $this->albumRef = $o['albumRef'];
        if (isset($o['ownerRef'])) $this->ownerRef = $o['ownerRef'];
        if (isset($o['primaryArtifactId'])) $this->primaryArtifactId = $o['primaryArtifactId'];
        if (isset($o['score'])) $this->score = $o['score'];
        if (isset($o['artifactIds'])) $this->artifactIds = JsonConverters::fromArray('int', $o['artifactIds']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->name)) $o['name'] = $this->name;
        if (isset($this->slug)) $o['slug'] = $this->slug;
        if (isset($this->albumRef)) $o['albumRef'] = $this->albumRef;
        if (isset($this->ownerRef)) $o['ownerRef'] = $this->ownerRef;
        if (isset($this->primaryArtifactId)) $o['primaryArtifactId'] = $this->primaryArtifactId;
        if (isset($this->score)) $o['score'] = $this->score;
        if (isset($this->artifactIds)) $o['artifactIds'] = JsonConverters::toArray('int', $this->artifactIds);
        return empty($o) ? new class(){} : $o;
    }
}

class UserResult implements JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $refId='',
        /** @var string|null */
        public ?string $handle=null,
        /** @var string|null */
        public ?string $avatar=null,
        /** @var string|null */
        public ?string $profileUrl=null,
        /** @var Likes|null */
        public ?Likes $likes=null,
        /** @var array<AlbumResult>|null */
        public ?array $albums=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['refId'])) $this->refId = $o['refId'];
        if (isset($o['handle'])) $this->handle = $o['handle'];
        if (isset($o['avatar'])) $this->avatar = $o['avatar'];
        if (isset($o['profileUrl'])) $this->profileUrl = $o['profileUrl'];
        if (isset($o['likes'])) $this->likes = JsonConverters::from('Likes', $o['likes']);
        if (isset($o['albums'])) $this->albums = JsonConverters::fromArray('AlbumResult', $o['albums']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->refId)) $o['refId'] = $this->refId;
        if (isset($this->handle)) $o['handle'] = $this->handle;
        if (isset($this->avatar)) $o['avatar'] = $this->avatar;
        if (isset($this->profileUrl)) $o['profileUrl'] = $this->profileUrl;
        if (isset($this->likes)) $o['likes'] = JsonConverters::to('Likes', $this->likes);
        if (isset($this->albums)) $o['albums'] = JsonConverters::toArray('AlbumResult', $this->albums);
        return empty($o) ? new class(){} : $o;
    }
}

class UserProfile implements JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $displayName='',
        /** @var string|null */
        public ?string $avatar=null,
        /** @var string|null */
        public ?string $handle=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['displayName'])) $this->displayName = $o['displayName'];
        if (isset($o['avatar'])) $this->avatar = $o['avatar'];
        if (isset($o['handle'])) $this->handle = $o['handle'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->displayName)) $o['displayName'] = $this->displayName;
        if (isset($this->avatar)) $o['avatar'] = $this->avatar;
        if (isset($this->handle)) $o['handle'] = $this->handle;
        return empty($o) ? new class(){} : $o;
    }
}

enum SignupType : string
{
    case Updates = 'Updates';
    case Beta = 'Beta';
}

class UserDataResponse implements JsonSerializable
{
    public function __construct(
        /** @var UserResult|null */
        public ?UserResult $user=null,
        /** @var UserProfile|null */
        public ?UserProfile $profile=null,
        /** @var array<SignupType>|null */
        public ?array $signups=null,
        /** @var string[] */
        public array $roles=[],
        /** @var ResponseStatus|null */
        public ?ResponseStatus $responseStatus=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['user'])) $this->user = JsonConverters::from('UserResult', $o['user']);
        if (isset($o['profile'])) $this->profile = JsonConverters::from('UserProfile', $o['profile']);
        if (isset($o['signups'])) $this->signups = JsonConverters::fromArray('SignupType', $o['signups']);
        if (isset($o['roles'])) $this->roles = JsonConverters::fromArray('string', $o['roles']);
        if (isset($o['responseStatus'])) $this->responseStatus = JsonConverters::from('ResponseStatus', $o['responseStatus']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->user)) $o['user'] = JsonConverters::to('UserResult', $this->user);
        if (isset($this->profile)) $o['profile'] = JsonConverters::to('UserProfile', $this->profile);
        if (isset($this->signups)) $o['signups'] = JsonConverters::toArray('SignupType', $this->signups);
        if (isset($this->roles)) $o['roles'] = JsonConverters::toArray('string', $this->roles);
        if (isset($this->responseStatus)) $o['responseStatus'] = JsonConverters::to('ResponseStatus', $this->responseStatus);
        return empty($o) ? new class(){} : $o;
    }
}

// @ValidateRequest(Validator="IsAuthenticated")
class UserData implements IPost, JsonSerializable
{
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        return empty($o) ? new class(){} : $o;
    }
}

PHP UserData DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv

HTTP + JSV

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /jsv/reply/UserData HTTP/1.1 
Host: blazordiffusion.com 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	user: 
	{
		refId: String,
		handle: String,
		avatar: String,
		profileUrl: String,
		likes: 
		{
			artifactIds: 
			[
				0
			],
			albumIds: 
			[
				0
			]
		},
		albums: 
		[
			{
				id: 0,
				name: String,
				slug: String,
				albumRef: String,
				ownerRef: String,
				primaryArtifactId: 0,
				score: 0,
				artifactIds: 
				[
					0
				]
			}
		]
	},
	profile: 
	{
		displayName: String,
		avatar: String,
		handle: String
	},
	signups: 
	[
		Updates
	],
	roles: 
	[
		String
	],
	responseStatus: 
	{
		errorCode: String,
		message: String,
		stackTrace: String,
		errors: 
		[
			{
				errorCode: String,
				fieldName: String,
				message: String,
				meta: 
				{
					String: String
				}
			}
		],
		meta: 
		{
			String: String
		}
	}
}