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

Commit 889aa8e

Browse files
committed
API blueprint Document and some tweaks
1 parent 371ab68 commit 889aa8e

39 files changed

+1473
-76
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ Homestead.json
66
.env
77
yarn.lock
88
/public/css/
9-
/public/js/
9+
/public/js/
10+
/packages

app/Http/Controllers/Users/UsersController.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Http\Request;
66
use App\Http\Controllers\Controller;
77
use App\Contracts\Users\UsersServiceContract;
8+
use Joselfonseca\LaravelApiTools\Traits\ResponseBuilder;
89

910
/**
1011
* Class UsersController
@@ -13,6 +14,8 @@
1314
class UsersController extends Controller
1415
{
1516

17+
use ResponseBuilder;
18+
1619
/**
1720
* @var UsersServiceContract
1821
*/
@@ -26,6 +29,7 @@ public function __construct(UsersServiceContract $service)
2629
{
2730
$this->service = $service;
2831
$this->middleware('permission:List users')->only('index');
32+
$this->middleware('permission:List users')->only('show');
2933
$this->middleware('permission:Create users')->only('store');
3034
$this->middleware('permission:Update users')->only('update');
3135
$this->middleware('permission:Delete users')->only('destroy');
@@ -37,7 +41,17 @@ public function __construct(UsersServiceContract $service)
3741
public function index()
3842
{
3943
$users = $this->service->get();
40-
return $this->service->transform($users);
44+
return response()->json($this->service->transform($users));
45+
}
46+
47+
48+
/**
49+
* @param $id
50+
* @return \Illuminate\Http\JsonResponse
51+
*/
52+
public function show($id)
53+
{
54+
return response()->json($this->service->transform($this->service->find($id)));
4155
}
4256

4357
/**
@@ -47,8 +61,8 @@ public function index()
4761
public function store(Request $request)
4862
{
4963
$attributes = $request->all();
50-
$this->service->create($attributes);
51-
return response()->json()->setStatusCode(201);
64+
$user = $this->service->create($attributes);
65+
return $this->created(url('api/users/'.$user->uuid), $this->service->transform($user));
5266
}
5367

5468
/**
@@ -70,6 +84,6 @@ public function update(Request $request, $uuid)
7084
public function destroy(Request $request, $uuid)
7185
{
7286
$this->service->delete($uuid);
73-
return response()->json()->setStatusCode(204);
87+
return $this->noContent();
7488
}
7589
}

app/Services/Users/UsersService.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use League\Fractal\TransformerAbstract;
77
use App\Transformers\Users\UserTransformer;
88
use App\Contracts\Users\UsersServiceContract;
9-
use League\Fractal\Serializer\JsonApiSerializer;
109
use Joselfonseca\LaravelApiTools\Contracts\FractalAble;
1110
use Joselfonseca\LaravelApiTools\Contracts\ValidateAble;
1211
use Joselfonseca\LaravelApiTools\Traits\FractalAbleTrait;
@@ -79,14 +78,6 @@ public function setTransformer() : TransformerAbstract
7978
return app(UserTransformer::class);
8079
}
8180

82-
/**
83-
* @return JsonApiSerializer
84-
*/
85-
public function setSerializer()
86-
{
87-
return new JsonApiSerializer(url('api'));
88-
}
89-
9081
/**
9182
* @param int $limit
9283
* @return mixed

composer.lock

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

config/api.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Prefix
8+
|--------------------------------------------------------------------------
9+
|
10+
| This is the prefix you use for your routes
11+
|
12+
*/
13+
14+
'prefix' => 'api'
15+
16+
17+
];

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| any other location as required by the application or its packages.
1313
*/
1414

15-
'name' => 'Laravel',
15+
'name' => 'Laravel API',
1616

1717
/*
1818
|--------------------------------------------------------------------------

config/laravel-tactician.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
4+
return [
5+
// The locator to bind
6+
'locator' => 'Joselfonseca\LaravelTactician\Locator\LaravelLocator',
7+
// The inflector to bind
8+
'inflector' => 'League\Tactician\Handler\MethodNameInflector\HandleInflector',
9+
// The extractor to bind
10+
'extractor' => 'League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor',
11+
// The bus to bind
12+
'bus' => 'Joselfonseca\LaravelTactician\Bus'
13+
];

0 commit comments

Comments
 (0)