diff --git a/app/controllers/ApiController.php b/app/controllers/ApiController.php index 98960ad2c..3ad2cbf06 100644 --- a/app/controllers/ApiController.php +++ b/app/controllers/ApiController.php @@ -1,11 +1,28 @@ auth = $auth; + } + + /** + * Get all components + * + * @return \Illuminate\Database\Eloquent\Collection + */ public function getComponents() { return Component::all(); } + /** + * Get a single component + * + * @param int $id + * + * @return Component + */ public function getComponent($id) { if ($component = Component::find($id)) { return $component; @@ -19,10 +36,37 @@ return $component->incidents; } + /** + * Create a new component + * + * @return Component + */ + public function postComponents() { + $component = new Component(Input::all()); + if ($component->isValid()) { + $component->saveOrFail(); + return $component; + } else { + App::abort(404, $component->getErrors()->first()); + } + } + + /** + * Get all incidents + * + * @return \Illuminate\Database\Eloquent\Collection + */ public function getIncidents() { return Incident::all(); } + /** + * Get a single incident + * + * @param int $id + * + * @return Incident + */ public function getIncident($id) { if ($incident = Incident::find($id)) { return $incident; @@ -31,4 +75,18 @@ } } + /** + * Create a new incident + * + * @return Incident + */ + public function postIncidents() { + $incident = new Incident(Input::all()); + if ($incident->isValid()) { + $incident->saveOrFail(); + return $incident; + } else { + App::abort(404, $incident->getErrors()->first()); + } + } } diff --git a/app/models/Component.php b/app/models/Component.php index 337cf3711..4f246b4a4 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -1,6 +1,17 @@ 'required', + 'status' => 'required|integer' + ]; + + protected $fillable = ['name', 'description', 'status']; + /** * Lookup all of the incidents reported on the component. * @return Illuminate\Database\Eloquent\Relations diff --git a/app/models/Incident.php b/app/models/Incident.php index c0aa4b1c6..2807312fd 100644 --- a/app/models/Incident.php +++ b/app/models/Incident.php @@ -1,6 +1,20 @@ 'required|integer', + 'name' => 'required', + 'status' => 'required|integer', + 'message' => 'required', + ]; + + protected $fillable = ['component', 'name', 'status', 'message']; + /** * An incident belongs to a component. * @return Illuminate\Database\Eloquent\Relations\BelongsTo diff --git a/app/routes/api.php b/app/routes/api.php index 3f55953ff..3522a5f07 100644 --- a/app/routes/api.php +++ b/app/routes/api.php @@ -8,4 +8,9 @@ Route::get('incidents', 'ApiController@getIncidents'); Route::get('incidents/{id}', 'ApiController@getIncident'); + Route::group(['protected' => true], function() { + Route::post('components', 'ApiController@postComponents'); + Route::post('incidents', 'ApiController@postIncidents'); + }); + }); diff --git a/composer.json b/composer.json index 3345983ba..e6933ee4a 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,8 @@ "require": { "laravel/framework": "4.2.*", "guzzlehttp/guzzle": "4.*", - "dingo/api": "~0.6" + "dingo/api": "~0.6", + "watson/validating": "0.10.*" }, "autoload": { "classmap": [ diff --git a/composer.lock b/composer.lock index 3bc2e6cb9..90fe5eacc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "f1b0b35a64f38b74527150925a720e8d", + "hash": "582a0ffe83dfc08436525ef3419162a7", "packages": [ { "name": "classpreloader/classpreloader", @@ -1874,6 +1874,55 @@ "description": "Symfony Translation Component", "homepage": "http://symfony.com", "time": "2014-10-26 07:41:27" + }, + { + "name": "watson/validating", + "version": "0.10.6", + "source": { + "type": "git", + "url": "https://github.com/dwightwatson/validating.git", + "reference": "673b165b4391942a7fae1e85a84f21b5f367f33f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dwightwatson/validating/zipball/673b165b4391942a7fae1e85a84f21b5f367f33f", + "reference": "673b165b4391942a7fae1e85a84f21b5f367f33f", + "shasum": "" + }, + "require": { + "illuminate/database": "~4.2.6", + "illuminate/events": "~4.2.6", + "illuminate/support": "~4.2.6", + "illuminate/validation": "~4.2.6", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "0.9.*", + "phpunit/phpunit": "4.1.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Watson\\Validating\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dwight Watson", + "email": "dwight@studiousapp.com" + } + ], + "description": "Eloquent model validating trait.", + "keywords": [ + "eloquent", + "laravel", + "validation" + ], + "time": "2014-11-20 02:09:08" } ], "packages-dev": [],