-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.model.api.stub
More file actions
executable file
·165 lines (159 loc) · 4.95 KB
/
Copy pathcontroller.model.api.stub
File metadata and controls
executable file
·165 lines (159 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
namespace {{ namespace }};
use {{ namespacedModel }};
use {{ rootNamespace }}Http\Controllers\Controller;
use {{ namespacedRequests }}
use Illuminate\Http\Response;
/**
* Class {{ class }}Controller
* @package {{ namespace }}
*/
class {{ class }} extends Controller
{
/**
* @OA\Get(
* path="/{{ modelVariable }}s",
* operationId="index{{ model }}",
* tags={"{{ model }}s"},
* summary="Get list of {{ model }}",
* description="Returns list of {{ model }}",
* @OA\Response(response=200, description="Successful operation",
* @OA\JsonContent(ref="#/components/schemas/{{ model }}s"),
* ),
* )
*
* Display a listing of {{ model }}.
* @return JsonResponse
*/
public function index()
{
${{ modelVariable }}s = {{ model }}::all();
return response()->json(['data' => ${{ modelVariable }}s]);
}
/**
* @OA\Post(
* operationId="store{{ model }}",
* summary="Insert a new {{ model }}",
* description="Insert a new {{ model }}",
* tags={"{{ model }}s"},
* path="/{{ modelVariable }}s",
* @OA\RequestBody(
* description="{{ model }} to create",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* title="data",
* property="data",
* type="object",
* ref="#/components/schemas/{{ model }}")
* )
* )
* ),
* @OA\Response(response="201",description="{{ model }} created",
* @OA\JsonContent(
* @OA\Property(
* title="data",
* property="data",
* type="object",
* ref="#/components/schemas/{{ model }}"
* ),
* ),
* ),
* @OA\Response(response=422,description="Validation exception"),
* )
*
* @param {{ model }}Request $request
* @return JsonResponse
*/
public function store({{ storeRequest }} $request)
{
$data = {{ model }}::create($request->validated('data'));
return response()->json(['data' => $data], RESPONSE::HTTP_CREATED);
}
/**
* @OA\Get(
* path="/{{ modelVariable }}s/{{{ modelVariable }}_id}",
* summary="Show a {{ model }} from his Id",
* description="Show a {{ model }} from his Id",
* operationId="show{{ model }}",
* tags={"{{ model }}s"},
* @OA\Parameter(ref="#/components/parameters/{{ model }}--id"),
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(
* @OA\Property(
* title="data",
* property="data",
* type="object",
* ref="#/components/schemas/{{ model }}"
* ),
* ),
* ),
* @OA\Response(response="404",description="{{ model }} not found"),
* )
*
* @param {{ model }} ${{ model }}
* @return JsonResponse
*/
public function show({{ model }} ${{ modelVariable }})
{
return response()->json(['data' => ${{ modelVariable }}]);
}
/**
* @OA\Patch(
* operationId="update{{ model }}",
* summary="Update an existing {{ model }}",
* description="Update an existing {{ model }}",
* tags={"{{ model }}s"},
* path="/{{ modelVariable }}s/{{{ modelVariable }}_id}",
* @OA\Parameter(ref="#/components/parameters/{{ model }}--id"),
* @OA\Response(response="204",description="No content"),
* @OA\RequestBody(
* description="{{ model }} to update",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* title="data",
* property="data",
* type="object",
* ref="#/components/schemas/{{ model }}")
* )
* )
* )
* )
*
* @param Request $request
* @param {{ model }} ${{ model }}
* @return Response|JsonResponse
*/
public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }})
{
${{ modelVariable }}->update($request->validated('data'));
return response()->json(['data' => ${{ modelVariable }}->refresh()]);
}
/**
* @OA\Delete(
* path="/{{ modelVariable }}s/{{{ modelVariable }}_id}",
* summary="Delete a {{ model }}",
* description="Delete a {{ model }}",
* operationId="destroy{{ model }}",
* tags={"{{ model }}s"},
* @OA\Parameter(ref="#/components/parameters/{{ model }}--id"),
* @OA\Response(response=204,description="No content"),
* @OA\Response(response=404,description="{{ model }} not found"),
* )
*
* @param {{ model }} ${{ model }}
* @return Response|JsonResponse
*/
public function destroy({{ model }} ${{ modelVariable }})
{
${{ modelVariable }}->delete();
return response()->noContent();
}
}