Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit ad78e15

Browse files
committed
- Update docs
- Register ModelNotFoundException error handler for Dingo - Allow the user to update password
1 parent 8b518d1 commit ad78e15

File tree

7 files changed

+282
-161
lines changed

7 files changed

+282
-161
lines changed

app/Providers/AppServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Services\Users\UsersService;
66
use Illuminate\Support\ServiceProvider;
77
use App\Contracts\Users\UsersServiceContract;
8+
use Illuminate\Database\Eloquent\ModelNotFoundException;
89

910
class AppServiceProvider extends ServiceProvider
1011
{
@@ -26,5 +27,8 @@ public function boot()
2627
public function register()
2728
{
2829
$this->app->bind(UsersServiceContract::class, UsersService::class);
30+
app('Dingo\Api\Exception\Handler')->register(function (ModelNotFoundException $exception) {
31+
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
32+
});
2933
}
3034
}

app/Services/Users/UsersService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public function update($id, array $attributes = [])
125125
if (isset($attributes['email']) && $attributes['email'] != $model->email) {
126126
$this->validationUpdateRules['email'] = 'sometimes|required|unique:users,email,'.$model->id;
127127
}
128-
if (isset($attributes['password'])) {
129-
unset($attributes['password']);
128+
if(isset($attributes['password'])) {
129+
$attributes['password'] = bcrypt($attributes['password']);
130130
}
131131
$this->runValidator($attributes, $this->validationUpdateRules, $this->validationMessages);
132132
$model->fill($attributes);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"laravel/passport": "^2.0",
2323
"webpatser/laravel-uuid": "^2.0",
2424
"spatie/laravel-permission": "^1.7",
25-
"joselfonseca/laravel-api-tools" : "3.0.*"
25+
"joselfonseca/laravel-api-tools" : "dev-master"
2626
},
2727
"require-dev": {
2828
"fzaninotto/faker": "~1.4",

composer.lock

Lines changed: 49 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/blueprint/apidocs.apib

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FORMAT: 1A
2-
HOST: https://example.com/api
2+
HOST: https://example.com
33

44
# Laravel API
55
Welcome to the Starter Kit API, here you will find all the information related to the endpoints available.
@@ -41,6 +41,10 @@ This endpoint will allow you to get the users registered in the system
4141
+ (User Object)
4242
+ meta
4343
+ pagination (User Pagination)
44+
+ links
45+
+ self: `http://laravelapi.dev/api/users?page=1` (string)
46+
+ first: `http://laravelapi.dev/api/users?page=1` (string)
47+
+ last: `http://laravelapi.dev/api/users?page=1` (string)
4448

4549
+ Response 401 (application/json)
4650

@@ -188,36 +192,38 @@ This endpoint will allow you to delete a user from the system
188192
# Data Structures
189193

190194
## Error 404 (object)
191-
- code: 404 (number)
192-
- title: `Not found` (string)
195+
- status_code: 404 (number)
196+
- message: `Not found` (string)
193197

194198
## Error 400 (object)
195-
- code: 400 (number)
196-
- title: `Bad Request` (string)
199+
- status_code: 400 (number)
200+
- message: `Bad Request` (string)
197201

198202
## Error 403 (object)
199-
- code: 403 (number)
200-
- title: `Forbidden` (string)
203+
- status_code: 403 (number)
204+
- message: `Forbidden` (string)
201205

202206
## Error 401 (object)
203-
- code: 401 (number)
204-
- title: `Unauthorized` (string)
207+
- status_code: 401 (number)
208+
- message: `Unauthorized` (string)
205209

206210
## Error 405 (object)
207-
- code: 405 (number)
208-
- title: `Method Not Allowed` (string)
211+
- status_code: 405 (number)
212+
- message: `Method Not Allowed` (string)
209213

210214
## Error 422 (object)
211-
- code: 422 (number)
212-
- title: `Validation error` (string)
215+
- status_code: 422 (number)
216+
- message: `Validation error` (string)
213217
- errors (array) `Array of errors present in the validation`
214218

215219
## User Object (object)
220+
- type: `user` (string)
216221
- id: `d4d42ea0-ee77-11e6-b823-6d63c6504afc` (string)
217-
- name: `Jhon Doe` (string)
218-
- email: `[email protected]` (string)
219-
- created_at: `2017-02-09T03:28:32+00:00` (string)
220-
- updated_at: `2017-02-09T03:28:32+00:00` (string)
222+
- attributes
223+
- name: `Jhon Doe` (string)
224+
- email: `[email protected]` (string)
225+
- created_at: `2017-02-09T03:28:32+00:00` (string)
226+
- updated_at: `2017-02-09T03:28:32+00:00` (string)
221227

222228
## User Create (object)
223229
- name: `Jhon Doe` (string, required)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
66
"watch-poll": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
77
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
8-
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
8+
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
9+
"docs": "aglio -i docs/api/blueprint/apidocs.apib --theme-variables Flatly --theme-template triple -o resources/views/apidocs.blade.php"
910
},
1011
"devDependencies": {
1112
"axios": "^0.15.3",

0 commit comments

Comments
 (0)