From d815f64dc879a75a583f64f95f7001a075fa1f28 Mon Sep 17 00:00:00 2001 From: jedi Date: Tue, 24 Dec 2019 13:52:10 +0100 Subject: [PATCH] add File api endpoints --- app/File.php | 2 ++ app/Http/Controllers/ExampleController.php | 18 ---------- app/Http/Controllers/FileController.php | 41 ++++++++++++++++++++++ routes/web.php | 7 ++++ 4 files changed, 50 insertions(+), 18 deletions(-) delete mode 100644 app/Http/Controllers/ExampleController.php create mode 100644 app/Http/Controllers/FileController.php diff --git a/app/File.php b/app/File.php index 42e190a..4e029a2 100644 --- a/app/File.php +++ b/app/File.php @@ -16,6 +16,8 @@ class File extends Model 'hash', 'iid' ]; + protected $primaryKey = 'hash'; + /** * The attributes excluded from the model's JSON form. * diff --git a/app/Http/Controllers/ExampleController.php b/app/Http/Controllers/ExampleController.php deleted file mode 100644 index aab066e..0000000 --- a/app/Http/Controllers/ExampleController.php +++ /dev/null @@ -1,18 +0,0 @@ -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); + } +} diff --git a/routes/web.php b/routes/web.php index 7c990bd..f07dc3e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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']);