MyApp

<back to all web services

UpdateProfile

Game
<?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 IPatchDb of Profile
 */
class UpdateProfile implements IPatchDb, JsonSerializable
{
    public function __construct(
        /** @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|null */
        public ?int $highScore=null,
        /** @var int|null */
        public ?int $gamesPlayed=null,
        // @Validate(Validator="InclusiveBetween(0,100)")
        /** @var int|null */
        public ?int $energy=null,

        /** @var string|null */
        public ?string $profileUrl=null,
        /** @var string|null */
        public ?string $coverUrl=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        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'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        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;
        return empty($o) ? new class(){} : $o;
    }
}

PHP UpdateProfile 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/UpdateProfile HTTP/1.1 
Host: blazor-gallery.servicestack.net 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	id: 0,
	role: Leader,
	region: 0,
	username: String,
	highScore: 0,
	gamesPlayed: 0,
	energy: 0,
	profileUrl: String,
	coverUrl: String
}
HTTP/1.1 200 OK
Content-Type: text/jsv
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
		}
	}
}