Blazor Diffusion

<back to all web services

CreateAlbum

Albums
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};


// @DataContract
class AuditBase implements JsonSerializable
{
    public function __construct(
        // @DataMember(Order=1)
        /** @var DateTime */
        public DateTime $createdDate=new DateTime(),

        // @DataMember(Order=2)
        // @Required()
        /** @var string */
        public string $createdBy='',

        // @DataMember(Order=3)
        /** @var DateTime */
        public DateTime $modifiedDate=new DateTime(),

        // @DataMember(Order=4)
        // @Required()
        /** @var string */
        public string $modifiedBy='',

        // @DataMember(Order=5)
        /** @var DateTime|null */
        public ?DateTime $deletedDate=null,

        // @DataMember(Order=6)
        /** @var string|null */
        public ?string $deletedBy=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['createdDate'])) $this->createdDate = JsonConverters::from('DateTime', $o['createdDate']);
        if (isset($o['createdBy'])) $this->createdBy = $o['createdBy'];
        if (isset($o['modifiedDate'])) $this->modifiedDate = JsonConverters::from('DateTime', $o['modifiedDate']);
        if (isset($o['modifiedBy'])) $this->modifiedBy = $o['modifiedBy'];
        if (isset($o['deletedDate'])) $this->deletedDate = JsonConverters::from('DateTime', $o['deletedDate']);
        if (isset($o['deletedBy'])) $this->deletedBy = $o['deletedBy'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->createdDate)) $o['createdDate'] = JsonConverters::to('DateTime', $this->createdDate);
        if (isset($this->createdBy)) $o['createdBy'] = $this->createdBy;
        if (isset($this->modifiedDate)) $o['modifiedDate'] = JsonConverters::to('DateTime', $this->modifiedDate);
        if (isset($this->modifiedBy)) $o['modifiedBy'] = $this->modifiedBy;
        if (isset($this->deletedDate)) $o['deletedDate'] = JsonConverters::to('DateTime', $this->deletedDate);
        if (isset($this->deletedBy)) $o['deletedBy'] = $this->deletedBy;
        return empty($o) ? new class(){} : $o;
    }
}

class Artifact extends AuditBase implements JsonSerializable
{
    /**
     * @param DateTime $createdDate
     * @param string $createdBy
     * @param DateTime $modifiedDate
     * @param string $modifiedBy
     * @param DateTime|null $deletedDate
     * @param string|null $deletedBy
     */
    public function __construct(
        DateTime $createdDate=new DateTime(),
        string $createdBy='',
        DateTime $modifiedDate=new DateTime(),
        string $modifiedBy='',
        ?DateTime $deletedDate=null,
        ?string $deletedBy=null,
        /** @var int */
        public int $id=0,
        // @References("typeof(BlazorDiffusion.ServiceModel.Creative)")
        /** @var int */
        public int $creativeId=0,

        /** @var string */
        public string $fileName='',
        /** @var string */
        public string $filePath='',
        /** @var string */
        public string $contentType='',
        /** @var int */
        public int $contentLength=0,
        /** @var int */
        public int $width=0,
        /** @var int */
        public int $height=0,
        /** @var int */
        public int $seed=0,
        /** @var string */
        public string $prompt='',
        /** @var bool|null */
        public ?bool $nsfw=null,
        /** @var int|null */
        public ?int $averageHash=null,
        /** @var int|null */
        public ?int $perceptualHash=null,
        /** @var int|null */
        public ?int $differenceHash=null,
        /** @var string|null */
        public ?string $background=null,
        /** @var string|null */
        public ?string $lqip=null,
        /** @var int */
        public int $quality=0,
        /** @var int */
        public int $likesCount=0,
        /** @var int */
        public int $albumsCount=0,
        /** @var int */
        public int $downloadsCount=0,
        /** @var int */
        public int $searchCount=0,
        /** @var int */
        public int $temporalScore=0,
        /** @var int */
        public int $score=0,
        /** @var int */
        public int $rank=0,
        /** @var string */
        public string $refId='',
        /** @var array<string,string>|null */
        public ?array $versions=null
    ) {
        parent::__construct($createdDate,$createdBy,$modifiedDate,$modifiedBy,$deletedDate,$deletedBy);
    }

    /** @throws Exception */
    public function fromMap($o): void {
        parent::fromMap($o);
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['creativeId'])) $this->creativeId = $o['creativeId'];
        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['width'])) $this->width = $o['width'];
        if (isset($o['height'])) $this->height = $o['height'];
        if (isset($o['seed'])) $this->seed = $o['seed'];
        if (isset($o['prompt'])) $this->prompt = $o['prompt'];
        if (isset($o['nsfw'])) $this->nsfw = $o['nsfw'];
        if (isset($o['averageHash'])) $this->averageHash = $o['averageHash'];
        if (isset($o['perceptualHash'])) $this->perceptualHash = $o['perceptualHash'];
        if (isset($o['differenceHash'])) $this->differenceHash = $o['differenceHash'];
        if (isset($o['background'])) $this->background = $o['background'];
        if (isset($o['lqip'])) $this->lqip = $o['lqip'];
        if (isset($o['quality'])) $this->quality = $o['quality'];
        if (isset($o['likesCount'])) $this->likesCount = $o['likesCount'];
        if (isset($o['albumsCount'])) $this->albumsCount = $o['albumsCount'];
        if (isset($o['downloadsCount'])) $this->downloadsCount = $o['downloadsCount'];
        if (isset($o['searchCount'])) $this->searchCount = $o['searchCount'];
        if (isset($o['temporalScore'])) $this->temporalScore = $o['temporalScore'];
        if (isset($o['score'])) $this->score = $o['score'];
        if (isset($o['rank'])) $this->rank = $o['rank'];
        if (isset($o['refId'])) $this->refId = $o['refId'];
        if (isset($o['versions'])) $this->versions = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','string']), $o['versions']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = parent::jsonSerialize();
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->creativeId)) $o['creativeId'] = $this->creativeId;
        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->width)) $o['width'] = $this->width;
        if (isset($this->height)) $o['height'] = $this->height;
        if (isset($this->seed)) $o['seed'] = $this->seed;
        if (isset($this->prompt)) $o['prompt'] = $this->prompt;
        if (isset($this->nsfw)) $o['nsfw'] = $this->nsfw;
        if (isset($this->averageHash)) $o['averageHash'] = $this->averageHash;
        if (isset($this->perceptualHash)) $o['perceptualHash'] = $this->perceptualHash;
        if (isset($this->differenceHash)) $o['differenceHash'] = $this->differenceHash;
        if (isset($this->background)) $o['background'] = $this->background;
        if (isset($this->lqip)) $o['lqip'] = $this->lqip;
        if (isset($this->quality)) $o['quality'] = $this->quality;
        if (isset($this->likesCount)) $o['likesCount'] = $this->likesCount;
        if (isset($this->albumsCount)) $o['albumsCount'] = $this->albumsCount;
        if (isset($this->downloadsCount)) $o['downloadsCount'] = $this->downloadsCount;
        if (isset($this->searchCount)) $o['searchCount'] = $this->searchCount;
        if (isset($this->temporalScore)) $o['temporalScore'] = $this->temporalScore;
        if (isset($this->score)) $o['score'] = $this->score;
        if (isset($this->rank)) $o['rank'] = $this->rank;
        if (isset($this->refId)) $o['refId'] = $this->refId;
        if (isset($this->versions)) $o['versions'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','string']), $this->versions);
        return empty($o) ? new class(){} : $o;
    }
}

class AlbumArtifact implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $id=0,
        // @References("typeof(BlazorDiffusion.ServiceModel.Album)")
        /** @var int */
        public int $albumId=0,

        // @References("typeof(BlazorDiffusion.ServiceModel.Artifact)")
        /** @var int */
        public int $artifactId=0,

        /** @var string|null */
        public ?string $description=null,
        /** @var DateTime */
        public DateTime $createdDate=new DateTime(),
        /** @var DateTime */
        public DateTime $modifiedDate=new DateTime(),
        /** @var Artifact|null */
        public ?Artifact $artifact=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['albumId'])) $this->albumId = $o['albumId'];
        if (isset($o['artifactId'])) $this->artifactId = $o['artifactId'];
        if (isset($o['description'])) $this->description = $o['description'];
        if (isset($o['createdDate'])) $this->createdDate = JsonConverters::from('DateTime', $o['createdDate']);
        if (isset($o['modifiedDate'])) $this->modifiedDate = JsonConverters::from('DateTime', $o['modifiedDate']);
        if (isset($o['artifact'])) $this->artifact = JsonConverters::from('Artifact', $o['artifact']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->albumId)) $o['albumId'] = $this->albumId;
        if (isset($this->artifactId)) $o['artifactId'] = $this->artifactId;
        if (isset($this->description)) $o['description'] = $this->description;
        if (isset($this->createdDate)) $o['createdDate'] = JsonConverters::to('DateTime', $this->createdDate);
        if (isset($this->modifiedDate)) $o['modifiedDate'] = JsonConverters::to('DateTime', $this->modifiedDate);
        if (isset($this->artifact)) $o['artifact'] = JsonConverters::to('Artifact', $this->artifact);
        return empty($o) ? new class(){} : $o;
    }
}

class Album extends AuditBase implements JsonSerializable
{
    /**
     * @param DateTime $createdDate
     * @param string $createdBy
     * @param DateTime $modifiedDate
     * @param string $modifiedBy
     * @param DateTime|null $deletedDate
     * @param string|null $deletedBy
     */
    public function __construct(
        DateTime $createdDate=new DateTime(),
        string $createdBy='',
        DateTime $modifiedDate=new DateTime(),
        string $modifiedBy='',
        ?DateTime $deletedDate=null,
        ?string $deletedBy=null,
        /** @var int */
        public int $id=0,
        /** @var string|null */
        public ?string $name=null,
        /** @var string */
        public string $description='',
        /** @var string */
        public string $slug='',
        /** @var array<string>|null */
        public ?array $tags=null,
        /** @var string */
        public string $refId='',
        /** @var int */
        public int $ownerId=0,
        /** @var string */
        public string $ownerRef='',
        /** @var int|null */
        public ?int $primaryArtifactId=null,
        /** @var bool|null */
        public ?bool $private=null,
        /** @var int|null */
        public ?int $rating=null,
        /** @var int */
        public int $likesCount=0,
        /** @var int */
        public int $downloadsCount=0,
        /** @var int */
        public int $searchCount=0,
        /** @var int */
        public int $score=0,
        /** @var int */
        public int $rank=0,
        /** @var int|null */
        public ?int $prefColumns=null,
        /** @var array<AlbumArtifact>|null */
        public ?array $artifacts=null
    ) {
        parent::__construct($createdDate,$createdBy,$modifiedDate,$modifiedBy,$deletedDate,$deletedBy);
    }

    /** @throws Exception */
    public function fromMap($o): void {
        parent::fromMap($o);
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['name'])) $this->name = $o['name'];
        if (isset($o['description'])) $this->description = $o['description'];
        if (isset($o['slug'])) $this->slug = $o['slug'];
        if (isset($o['tags'])) $this->tags = JsonConverters::fromArray('string', $o['tags']);
        if (isset($o['refId'])) $this->refId = $o['refId'];
        if (isset($o['ownerId'])) $this->ownerId = $o['ownerId'];
        if (isset($o['ownerRef'])) $this->ownerRef = $o['ownerRef'];
        if (isset($o['primaryArtifactId'])) $this->primaryArtifactId = $o['primaryArtifactId'];
        if (isset($o['private'])) $this->private = $o['private'];
        if (isset($o['rating'])) $this->rating = $o['rating'];
        if (isset($o['likesCount'])) $this->likesCount = $o['likesCount'];
        if (isset($o['downloadsCount'])) $this->downloadsCount = $o['downloadsCount'];
        if (isset($o['searchCount'])) $this->searchCount = $o['searchCount'];
        if (isset($o['score'])) $this->score = $o['score'];
        if (isset($o['rank'])) $this->rank = $o['rank'];
        if (isset($o['prefColumns'])) $this->prefColumns = $o['prefColumns'];
        if (isset($o['artifacts'])) $this->artifacts = JsonConverters::fromArray('AlbumArtifact', $o['artifacts']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = parent::jsonSerialize();
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->name)) $o['name'] = $this->name;
        if (isset($this->description)) $o['description'] = $this->description;
        if (isset($this->slug)) $o['slug'] = $this->slug;
        if (isset($this->tags)) $o['tags'] = JsonConverters::toArray('string', $this->tags);
        if (isset($this->refId)) $o['refId'] = $this->refId;
        if (isset($this->ownerId)) $o['ownerId'] = $this->ownerId;
        if (isset($this->ownerRef)) $o['ownerRef'] = $this->ownerRef;
        if (isset($this->primaryArtifactId)) $o['primaryArtifactId'] = $this->primaryArtifactId;
        if (isset($this->private)) $o['private'] = $this->private;
        if (isset($this->rating)) $o['rating'] = $this->rating;
        if (isset($this->likesCount)) $o['likesCount'] = $this->likesCount;
        if (isset($this->downloadsCount)) $o['downloadsCount'] = $this->downloadsCount;
        if (isset($this->searchCount)) $o['searchCount'] = $this->searchCount;
        if (isset($this->score)) $o['score'] = $this->score;
        if (isset($this->rank)) $o['rank'] = $this->rank;
        if (isset($this->prefColumns)) $o['prefColumns'] = $this->prefColumns;
        if (isset($this->artifacts)) $o['artifacts'] = JsonConverters::toArray('AlbumArtifact', $this->artifacts);
        return empty($o) ? new class(){} : $o;
    }
}

// @ValidateRequest(Validator="IsAuthenticated")
/**
 * @template ICreateDb of Album
 */
class CreateAlbum implements ICreateDb, JsonSerializable
{
    public function __construct(
        // @Validate(Validator="NotEmpty")
        /** @var string */
        public string $name='',

        /** @var string */
        public string $description='',
        /** @var array<string>|null */
        public ?array $tags=null,
        /** @var int|null */
        public ?int $primaryArtifactId=null,
        /** @var array<int>|null */
        public ?array $artifactIds=null
    ) {
    }

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

PHP CreateAlbum DTOs

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

HTTP + CSV

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

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

{"name":"String","description":"String","tags":["String"],"primaryArtifactId":0,"artifactIds":[0]}
HTTP/1.1 200 OK
Content-Type: text/csv
Content-Length: length

{"id":0,"name":"String","description":"String","slug":"String","tags":["String"],"refId":"String","ownerId":0,"ownerRef":"String","primaryArtifactId":0,"private":false,"rating":0,"likesCount":0,"downloadsCount":0,"searchCount":0,"score":0,"rank":0,"prefColumns":0,"artifacts":[{"id":0,"albumId":0,"artifactId":0,"description":"String","createdDate":"0001-01-01T00:00:00","modifiedDate":"0001-01-01T00:00:00","artifact":{"id":0,"creativeId":0,"fileName":"String","filePath":"String","contentType":"String","contentLength":0,"width":0,"height":0,"seed":0,"prompt":"String","nsfw":false,"averageHash":0,"perceptualHash":0,"differenceHash":0,"background":"String","lqip":"String","quality":0,"likesCount":0,"albumsCount":0,"downloadsCount":0,"searchCount":0,"temporalScore":0,"score":0,"rank":0,"refId":"String","versions":{"String":"String"},"createdDate":"0001-01-01T00:00:00","createdBy":"String","modifiedDate":"0001-01-01T00:00:00","modifiedBy":"String","deletedDate":"0001-01-01T00:00:00","deletedBy":"String"}}],"createdDate":"0001-01-01T00:00:00","createdBy":"String","modifiedDate":"0001-01-01T00:00:00","modifiedBy":"String","deletedDate":"0001-01-01T00:00:00","deletedBy":"String"}