Remove repositories from the API and switch cipher to rijndael-256

This commit is contained in:
James Brooks
2015-05-23 19:09:24 +01:00
committed by James Brooks
parent d788691006
commit 106c1a034a
24 changed files with 222 additions and 939 deletions

View File

@@ -11,39 +11,26 @@
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Tag;
use CachetHQ\Cachet\Repositories\Component\ComponentRepository;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class ComponentController extends AbstractApiController
{
/**
* The component repository instance.
*
* @var \CachetHQ\Cachet\Repositories\Component\ComponentRepository
*/
protected $component;
/**
* Create a new component controller instance.
*
* @param \CachetHQ\Cachet\Repositories\Component\ComponentRepository $component
*/
public function __construct(ComponentRepository $component)
{
$this->component = $component;
}
/**
* Get all components.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getComponents(Request $request)
{
$components = $this->component->paginate(Binput::get('per_page', 20));
$components = Component::paginate(Binput::get('per_page', 20));
return $this->paginator($components, $request);
}
@@ -51,13 +38,13 @@ class ComponentController extends AbstractApiController
/**
* Get a single component.
*
* @param int $id
* @param \CachetHQ\Cachet\Models\Component $component
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function getComponent($id)
public function getComponent(Component $component)
{
return $this->item($this->component->findOrFail($id));
return $this->item($component);
}
/**
@@ -69,10 +56,18 @@ class ComponentController extends AbstractApiController
*/
public function postComponents(Guard $auth)
{
$component = $this->component->create(
$auth->user()->id,
Binput::except('tags')
);
$componentData = Binput::except('tags');
$componentData['user_id'] = $auth->user()->id;
try {
$component = Component::create($componentData);
} catch (Exception $e) {
throw new BadRequestHttpException();
}
if (!$component->isValid()) {
throw new BadRequestHttpException();
}
if (Binput::has('tags')) {
// The component was added successfully, so now let's deal with the tags.
@@ -94,13 +89,17 @@ class ComponentController extends AbstractApiController
/**
* Update an existing component.
*
* @param int $id
* @param \CachetHQ\Cachet\Models\Componet $component
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function putComponent($id)
public function putComponent(Component $component)
{
$component = $this->component->update($id, Binput::except('tags'));
$component->update(Binput::except('tags'));
if (!$component->isValid('updating')) {
throw new BadRequestHttpException();
}
if (Binput::has('tags')) {
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
@@ -121,13 +120,13 @@ class ComponentController extends AbstractApiController
/**
* Delete an existing component.
*
* @param int $id
* @param \CachetHQ\Cachet\Models\Component $component
*
* @return \Dingo\Api\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function deleteComponent($id)
public function deleteComponent(Component $component)
{
$this->component->destroy($id);
$component->delete();
return $this->noContent();
}