<?php
// Jobs.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use Docuform\Api\HttpRequestHandler;use Docuform\Api\UserType;use Docuform\Api\Exception\ApiHttpForbiddenException;use Docuform\Api\Exception\ApiHttpMissingLicense;use Psr\Http\Message\ResponseInterface;use Psr\Http\Message\ServerRequestInterface;use Docuform\Api\ApiScopes;use Docuform\Database\DbDatabase;class Jobs extends HttpRequestHandler{public function getAllowedUserTypes($request):array{return[UserType::USERTYPE_SERVICEACCOUNT,UserType::USERTYPE_CUSTOMER,UserType::USERTYPE_DEALER,UserType::USERTYPE_ADMIN];}public function getRequiredScopes($request):array{if($request->getMethod()!=='GET')return['allOf'=>[ApiScopes::accounting,ApiScopes::server_write],'anyOf'=>[]];else return['allOf'=>[ApiScopes::accounting,ApiScopes::server_read],'anyOf'=>[]];}public function handleRequest($request,& $response,$arguments):int{$result=404;if($request->getMethod()==='GET'){$job=new Job($this->getContainer());$credit=$job->read($this->getContainer());$json=json_encode($credit);$response->getBody()->write($json);$result=200;}elseif($request->getMethod()==='POST'){$job=new Job($this->getContainer());$job->create($request->getParsedBody());Job::buildJsonResponse($response,$job);$result=201;}return $result;}}