Skip to content

Commit

Permalink
#100 Add supported-ext header
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Aug 13, 2018
1 parent 0652fcf commit 3c746b9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/extension/ApiController.php
Expand Up @@ -13,7 +13,7 @@
use rjapi\helpers\Json;
use rjapi\types\PhpInterface;

class ApiController extends Controller
class ApiController extends Controller implements JSONApiInterface
{
use BaseRelationsTrait,
OptionsTrait,
Expand All @@ -28,20 +28,20 @@ class ApiController extends Controller
protected $jsonApi = true;

private $props = [];
private $entity = null;
private $entity;
/** @var BaseModel $model */
private $model = null;
private $model;
/** @var EntitiesTrait $modelEntity */
private $modelEntity = null;
private $middleWare = null;
private $modelEntity;
private $middleWare;
private $relsRemoved = false;
private $defaultOrderBy = [];
/** @var ConfigOptions $configOptions */
protected $configOptions = null;
protected $configOptions;
/** @var CustomSql $customSql */
protected $customSql = null;
protected $customSql;
/** @var BitMask $bitMask */
private $bitMask = null;
private $bitMask;

private $jsonApiMethods = [
JSONApiInterface::URI_METHOD_INDEX,
Expand Down Expand Up @@ -249,9 +249,10 @@ private function processUpdate($model, array $jsonApiAttributes)
/**
* DELETE Deletes one entry determined by unique id as uri param
*
* @param Request $request
* @param int|string $id
*/
public function delete($id)
public function delete(Request $request, $id)
{
$model = $this->getEntity($id);
if ($model !== null) {
Expand Down
31 changes: 31 additions & 0 deletions src/extension/BaseController.php
@@ -1,6 +1,37 @@
<?php

namespace rjapi\extension;

use Illuminate\Http\Request;

class BaseController extends ApiController
{

/**
* @param Request $request
* @throws \rjapi\exceptions\AttributesException
*/
public function create(Request $request)
{
parent::create($request);
}

/**
* @param Request $request
* @param int|string $id
* @throws \rjapi\exceptions\AttributesException
*/
public function update(Request $request, $id)
{
parent::update($request, $id);
}

/**
* @param Request $request
* @param int|string $id
*/
public function delete(Request $request, $id)
{
parent::delete($request, $id);
}
}
17 changes: 16 additions & 1 deletion src/extension/JSONApiInterface.php
@@ -1,10 +1,14 @@
<?php
namespace rjapi\extension;

use Illuminate\Http\Request;

interface JSONApiInterface
{
public const CONTENT_TYPE_KEY = 'Content-Type';

public const HEADER_CONTENT_TYPE = 'Content-Type: ';
public const HEADER_CONTENT_TYPE_VALUE = 'application/vnd.api+json';
public const HEADER_CONTENT_TYPE_VALUE = 'application/vnd.api+json; supported-ext="bulk"';

public const PARAM_ACCESS_TOKEN = 'access_token';
public const CLASS_API_ACCESS_TOKEN = 'ApiAccessToken';
Expand Down Expand Up @@ -44,4 +48,15 @@ interface JSONApiInterface
public const ERROR_DETAIL = 'detail';

public const ENCODE_DEPTH_1024 = 1024;

// methods JSON-API must implement
public function index(Request $request);

public function view(Request $request, $id);

public function create(Request $request);

public function update(Request $request, $id);

public function delete(Request $request, $id);
}

0 comments on commit 3c746b9

Please sign in to comment.