Requires any of the roles: | bookingsupplier-administrator-write, superadmin |
POST | /articles | Add new article | Add article to the company for the currently 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 BaseModel implements JsonSerializable
{
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
return empty($o) ? new class(){} : $o;
}
}
class ArticleServiceRelation extends BaseModel implements JsonSerializable
{
public function __construct(
// @Required()
/** @var string */
public string $CompanyId='',
/** @var int */
public int $Id=0,
// @Required()
/** @var int */
public int $ServiceId=0,
// @Required()
/** @var int */
public int $ArticleId=0
) {
}
/** @throws Exception */
public function fromMap($o): void {
parent::fromMap($o);
if (isset($o['CompanyId'])) $this->CompanyId = $o['CompanyId'];
if (isset($o['Id'])) $this->Id = $o['Id'];
if (isset($o['ServiceId'])) $this->ServiceId = $o['ServiceId'];
if (isset($o['ArticleId'])) $this->ArticleId = $o['ArticleId'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = parent::jsonSerialize();
if (isset($this->CompanyId)) $o['CompanyId'] = $this->CompanyId;
if (isset($this->Id)) $o['Id'] = $this->Id;
if (isset($this->ServiceId)) $o['ServiceId'] = $this->ServiceId;
if (isset($this->ArticleId)) $o['ArticleId'] = $this->ArticleId;
return empty($o) ? new class(){} : $o;
}
}
class ArticleResponse implements JsonSerializable
{
public function __construct(
/** @var string */
public string $CompanyId='',
/** @var int */
public int $Id=0,
/** @var string|null */
public ?string $Name=null,
/** @var int */
public int $ArticleTypeId=0,
/** @var string|null */
public ?string $Description=null,
/** @var string|null */
public ?string $ImageUrl=null,
/** @var bool|null */
public ?bool $Active=null,
/** @var int */
public int $Amount=0,
/** @var float */
public float $Price=0.0,
/** @var string|null */
public ?string $CurrencyId=null,
/** @var DateTime */
public DateTime $UpdatedDate=new DateTime(),
/** @var DateTime */
public DateTime $CreatedDate=new DateTime(),
/** @var array<ArticleServiceRelation>|null */
public ?array $Services=null,
/** @var array<int>|null */
public ?array $ServiceIds=null,
/** @var string|null */
public ?string $PriceSign=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['CompanyId'])) $this->CompanyId = $o['CompanyId'];
if (isset($o['Id'])) $this->Id = $o['Id'];
if (isset($o['Name'])) $this->Name = $o['Name'];
if (isset($o['ArticleTypeId'])) $this->ArticleTypeId = $o['ArticleTypeId'];
if (isset($o['Description'])) $this->Description = $o['Description'];
if (isset($o['ImageUrl'])) $this->ImageUrl = $o['ImageUrl'];
if (isset($o['Active'])) $this->Active = $o['Active'];
if (isset($o['Amount'])) $this->Amount = $o['Amount'];
if (isset($o['Price'])) $this->Price = $o['Price'];
if (isset($o['CurrencyId'])) $this->CurrencyId = $o['CurrencyId'];
if (isset($o['UpdatedDate'])) $this->UpdatedDate = JsonConverters::from('DateTime', $o['UpdatedDate']);
if (isset($o['CreatedDate'])) $this->CreatedDate = JsonConverters::from('DateTime', $o['CreatedDate']);
if (isset($o['Services'])) $this->Services = JsonConverters::fromArray('ArticleServiceRelation', $o['Services']);
if (isset($o['ServiceIds'])) $this->ServiceIds = JsonConverters::fromArray('int', $o['ServiceIds']);
if (isset($o['PriceSign'])) $this->PriceSign = $o['PriceSign'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->CompanyId)) $o['CompanyId'] = $this->CompanyId;
if (isset($this->Id)) $o['Id'] = $this->Id;
if (isset($this->Name)) $o['Name'] = $this->Name;
if (isset($this->ArticleTypeId)) $o['ArticleTypeId'] = $this->ArticleTypeId;
if (isset($this->Description)) $o['Description'] = $this->Description;
if (isset($this->ImageUrl)) $o['ImageUrl'] = $this->ImageUrl;
if (isset($this->Active)) $o['Active'] = $this->Active;
if (isset($this->Amount)) $o['Amount'] = $this->Amount;
if (isset($this->Price)) $o['Price'] = $this->Price;
if (isset($this->CurrencyId)) $o['CurrencyId'] = $this->CurrencyId;
if (isset($this->UpdatedDate)) $o['UpdatedDate'] = JsonConverters::to('DateTime', $this->UpdatedDate);
if (isset($this->CreatedDate)) $o['CreatedDate'] = JsonConverters::to('DateTime', $this->CreatedDate);
if (isset($this->Services)) $o['Services'] = JsonConverters::toArray('ArticleServiceRelation', $this->Services);
if (isset($this->ServiceIds)) $o['ServiceIds'] = JsonConverters::toArray('int', $this->ServiceIds);
if (isset($this->PriceSign)) $o['PriceSign'] = $this->PriceSign;
return empty($o) ? new class(){} : $o;
}
}
class CreateArticle implements JsonSerializable
{
public function __construct(
/** @description */
// @ApiMember(Description="")
/** @var string|null */
public ?string $CompanyId=null,
/** @description */
// @ApiMember(Description="", IsRequired=true)
/** @var string */
public string $Name='',
/** @description */
// @ApiMember(Description="", IsRequired=true)
/** @var int */
public int $ArticleTypeId=0,
/** @description */
// @ApiMember(Description="", IsRequired=true)
/** @var string */
public string $Description='',
/** @description */
// @ApiMember(Description="")
/** @var string|null */
public ?string $ImageUrl=null,
/** @description */
// @ApiMember(Description="", IsRequired=true)
/** @var bool|null */
public ?bool $Active=null,
/** @description */
// @ApiMember(Description="", IsRequired=true)
/** @var int */
public int $Amount=0,
/** @description . */
// @ApiMember(Description=".", IsRequired=true)
/** @var float */
public float $Price=0.0,
/** @description The payment currency id */
// @ApiMember(Description="The payment currency id", IsRequired=true)
/** @var string */
public string $CurrencyId='',
/** @description Query for specific services. */
// @ApiMember(Description="Query for specific services.", ParameterType="query")
/** @var int[]|null */
public ?array $ServiceIds=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['CompanyId'])) $this->CompanyId = $o['CompanyId'];
if (isset($o['Name'])) $this->Name = $o['Name'];
if (isset($o['ArticleTypeId'])) $this->ArticleTypeId = $o['ArticleTypeId'];
if (isset($o['Description'])) $this->Description = $o['Description'];
if (isset($o['ImageUrl'])) $this->ImageUrl = JsonConverters::from('string', $o['ImageUrl']);
if (isset($o['Active'])) $this->Active = $o['Active'];
if (isset($o['Amount'])) $this->Amount = $o['Amount'];
if (isset($o['Price'])) $this->Price = $o['Price'];
if (isset($o['CurrencyId'])) $this->CurrencyId = $o['CurrencyId'];
if (isset($o['ServiceIds'])) $this->ServiceIds = JsonConverters::fromArray('int', $o['ServiceIds']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->CompanyId)) $o['CompanyId'] = $this->CompanyId;
if (isset($this->Name)) $o['Name'] = $this->Name;
if (isset($this->ArticleTypeId)) $o['ArticleTypeId'] = $this->ArticleTypeId;
if (isset($this->Description)) $o['Description'] = $this->Description;
if (isset($this->ImageUrl)) $o['ImageUrl'] = JsonConverters::to('string', $this->ImageUrl);
if (isset($this->Active)) $o['Active'] = $this->Active;
if (isset($this->Amount)) $o['Amount'] = $this->Amount;
if (isset($this->Price)) $o['Price'] = $this->Price;
if (isset($this->CurrencyId)) $o['CurrencyId'] = $this->CurrencyId;
if (isset($this->ServiceIds)) $o['ServiceIds'] = JsonConverters::toArray('int', $this->ServiceIds);
return empty($o) ? new class(){} : $o;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .csv suffix or ?format=csv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /articles HTTP/1.1
Host: api.bokamera.se
Accept: text/csv
Content-Type: text/csv
Content-Length: length
{"CompanyId":"00000000-0000-0000-0000-000000000000","Name":"String","ArticleTypeId":0,"Description":"String","Active":false,"Amount":0,"Price":0,"CurrencyId":"String","ServiceIds":[0]}
HTTP/1.1 200 OK Content-Type: text/csv Content-Length: length {"Id":0,"Name":"String","ArticleTypeId":0,"Description":"String","ImageUrl":"String","Active":false,"Amount":0,"Price":0,"CurrencyId":"String","Services":[{"Id":0,"ServiceId":0,"ArticleId":0}],"ServiceIds":[0],"PriceSign":"String"}