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']);