<?php
// DeviceSupplies.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use Docuform\Api\HttpRequestHandler;use Docuform\Api\Exception\ApiHttpBadRequestException;use Docuform\Api\UserType;use Psr\Http\Message\ServerRequestInterface;use Psr\Http\Message\ResponseInterface;use Docuform\Api\ApiScopes;class DeviceSupplies extends HttpRequestHandler{public function getAllowedUserTypes($request):array{return[UserType::USERTYPE_CUSTOMER,UserType::USERTYPE_DEALER,UserType::USERTYPE_ADMIN];}public function getRequiredScopes($request):array{if($request->getMethod()!=='GET')return['allOf'=>[ApiScopes::server_read,ApiScopes::server_write],'anyOf'=>[]];else return['allOf'=>[ApiScopes::server_read],'anyOf'=>[]];}public function handleRequest($request,& $response,$arguments):int{$result=404;if($request->getMethod()==='GET'){$serverApi=$this->getContainer()->get('RestApi');$device=$serverApi->getDevice();if(empty($device)){throw new ApiHttpBadRequestException($request);}$supplies=new DeviceSupply($this->getContainer());$supplies->read();if($supplies->deviceId===$device->id){DeviceSupply::buildJsonResponse($response,$supplies,'deviceSupplies');$result=200;}else{$result=204;}}return $result;}}