BokaMera.API.Host

<back to all web services

AddCompanyTrial

Requires Authentication
Requires any of the roles:bookingsupplier-administrator-write, superadmin
The following routes are available for this service:
POST/trials/company/Add new trial to a companyStart a new trial to the company for the logged in user.
<?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 TrialQueryResponse implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $Id=0,
        /** @var string|null */
        public ?string $Name=null,
        /** @var int */
        public int $TrialDays=0
    ) {
    }

    /** @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['TrialDays'])) $this->TrialDays = $o['TrialDays'];
    }
    
    /** @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->TrialDays)) $o['TrialDays'] = $this->TrialDays;
        return empty($o) ? new class(){} : $o;
    }
}

class CompanyTrialQueryResponse implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $TrialTypeId=0,
        /** @var TrialQueryResponse|null */
        public ?TrialQueryResponse $TrialType=null,
        /** @var DateTime|null */
        public ?DateTime $Started=null,
        /** @var DateTime */
        public DateTime $Created=new DateTime(),
        /** @var DateTime|null */
        public ?DateTime $ValidTo=null,
        /** @var bool|null */
        public ?bool $Active=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['TrialTypeId'])) $this->TrialTypeId = $o['TrialTypeId'];
        if (isset($o['TrialType'])) $this->TrialType = JsonConverters::from('TrialQueryResponse', $o['TrialType']);
        if (isset($o['Started'])) $this->Started = JsonConverters::from('DateTime', $o['Started']);
        if (isset($o['Created'])) $this->Created = JsonConverters::from('DateTime', $o['Created']);
        if (isset($o['ValidTo'])) $this->ValidTo = JsonConverters::from('DateTime', $o['ValidTo']);
        if (isset($o['Active'])) $this->Active = $o['Active'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->TrialTypeId)) $o['TrialTypeId'] = $this->TrialTypeId;
        if (isset($this->TrialType)) $o['TrialType'] = JsonConverters::to('TrialQueryResponse', $this->TrialType);
        if (isset($this->Started)) $o['Started'] = JsonConverters::to('DateTime', $this->Started);
        if (isset($this->Created)) $o['Created'] = JsonConverters::to('DateTime', $this->Created);
        if (isset($this->ValidTo)) $o['ValidTo'] = JsonConverters::to('DateTime', $this->ValidTo);
        if (isset($this->Active)) $o['Active'] = $this->Active;
        return empty($o) ? new class(){} : $o;
    }
}

// @ApiResponse(Description="You were unauthorized to call this service", StatusCode=401)
// @ValidateRequest(Validator="IsAuthenticated")
class AddCompanyTrial implements ICompany, JsonSerializable
{
    public function __construct(
        /** @description The company id, if empty will use the company id for the user you are logged in with. */
        // @ApiMember(Description="The company id, if empty will use the company id for the user you are logged in with.")
        /** @var string|null */
        public ?string $CompanyId=null,

        /** @description Id of the trial type */
        // @ApiMember(Description="Id of the trial type", IsRequired=true)
        /** @var int */
        public int $TrialTypeId=0
    ) {
    }

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

PHP AddCompanyTrial 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 /trials/company/ HTTP/1.1 
Host: testapi.bokamera.se 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	CompanyId: 00000000-0000-0000-0000-000000000000,
	TrialTypeId: 0
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	TrialTypeId: 0,
	TrialType: 
	{
		Id: 0,
		Name: String,
		TrialDays: 0
	},
	Started: "0001-01-01T00:00:00",
	ValidTo: "0001-01-01T00:00:00",
	Active: False
}