add File api endpoints

This commit is contained in:
j3d1 2019-12-24 13:52:10 +01:00
parent 17e859b9ba
commit d815f64dc8
4 changed files with 50 additions and 18 deletions

View file

@ -16,6 +16,8 @@ class File extends Model
'hash', 'iid'
];
protected $primaryKey = 'hash';
/**
* The attributes excluded from the model's JSON form.
*

View file

@ -1,18 +0,0 @@
<?php
namespace App\Http\Controllers;
class ExampleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
//
}

View file

@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers;
use App\File;
use Illuminate\Http\Request;
class FileController extends Controller
{
public function showAllFiles()
{
return response()->json(File::all());
}
public function showOneFile($id)
{
return response()->json(File::find($id));
}
public function create(Request $request)
{
$File = File::create($request->all());
return response()->json($File, 201);
}
public function update($id, Request $request)
{
$File = File::findOrFail($id);
$File->update($request->all());
return response()->json($File, 200);
}
public function delete($id)
{
File::findOrFail($id)->delete();
return response('Deleted Successfully', 200);
}
}

View file

@ -38,6 +38,13 @@ $router->group(['prefix' => '1'], function () use ($router) {
$router->delete('box/{id}', ['uses' => 'ContainerController@delete']);
$router->put('box/{id}', ['uses' => 'ContainerController@update']);
// files
$router->get('files', ['uses' => 'FileController@showAllFiles']);
$router->get('file/{id}', ['uses' => 'FileController@showOneFile']);
$router->post('file', ['uses' => 'FileController@create']);
$router->delete('file/{id}', ['uses' => 'FileController@delete']);
$router->put('file/{id}', ['uses' => 'FileController@update']);
// items
$router->get('{event}/items', ['uses' => 'ItemController@showByEvent']);
$router->get('{event}/items/{query}', ['uses' => 'ItemController@searchByEvent']);