Blazor Diffusion

<back to all web services

CreateCreativeModifier

Creatives
Requires Authentication
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};


// @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 Modifier 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 */
        public string $name='',
        /** @var string */
        public string $category='',
        /** @var string|null */
        public ?string $description=null,
        /** @var int */
        public int $score=0,
        /** @var int */
        public int $rank=0
    ) {
        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['category'])) $this->category = $o['category'];
        if (isset($o['description'])) $this->description = $o['description'];
        if (isset($o['score'])) $this->score = $o['score'];
        if (isset($o['rank'])) $this->rank = $o['rank'];
    }
    
    /** @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->category)) $o['category'] = $this->category;
        if (isset($this->description)) $o['description'] = $this->description;
        if (isset($this->score)) $o['score'] = $this->score;
        if (isset($this->rank)) $o['rank'] = $this->rank;
        return empty($o) ? new class(){} : $o;
    }
}

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

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

        /** @var Modifier|null */
        public ?Modifier $modifier=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['creativeId'])) $this->creativeId = $o['creativeId'];
        if (isset($o['modifierId'])) $this->modifierId = $o['modifierId'];
        if (isset($o['modifier'])) $this->modifier = JsonConverters::from('Modifier', $o['modifier']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->creativeId)) $o['creativeId'] = $this->creativeId;
        if (isset($this->modifierId)) $o['modifierId'] = $this->modifierId;
        if (isset($this->modifier)) $o['modifier'] = JsonConverters::to('Modifier', $this->modifier);
        return empty($o) ? new class(){} : $o;
    }
}

// @ValidateRequest(Validator="HasRole(`Moderator`)")
/**
 * @template ICreateDb of CreativeModifier
 */
class CreateCreativeModifier implements ICreateDb, JsonSerializable
{
    public function __construct(
        // @Validate(Validator="GreaterThan(0)")
        /** @var int|null */
        public ?int $creativeId=null,

        // @Validate(Validator="GreaterThan(0)")
        /** @var int|null */
        public ?int $modifierId=null
    ) {
    }

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

PHP CreateCreativeModifier 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/CreateCreativeModifier HTTP/1.1 
Host: blazordiffusion.com 
Accept: text/csv
Content-Type: text/csv
Content-Length: length

{"creativeId":0,"modifierId":0}
HTTP/1.1 200 OK
Content-Type: text/csv
Content-Length: length

{"id":0,"creativeId":0,"modifierId":0,"modifier":{"id":0,"name":"String","category":"String","description":"String","score":0,"rank":0,"createdDate":"0001-01-01T00:00:00","createdBy":"String","modifiedDate":"0001-01-01T00:00:00","modifiedBy":"String","deletedDate":"0001-01-01T00:00:00","deletedBy":"String"}}