Skip to content

Commit c996647

Browse files
committed
added swagger for project api
1 parent 9bc2cde commit c996647

File tree

11 files changed

+2117
-723
lines changed

11 files changed

+2117
-723
lines changed

app/Http/Controllers/Api/CategoryController.php

+48-4
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,65 @@
1010
use App\Models\Prop;
1111
use Illuminate\Http\Request;
1212

13+
/**
14+
* @OA\Info(title="xShop API", version="1.0.0")
15+
*/
16+
/**
17+
* @OA\PathItem(path="/api/v1")
18+
*/
1319
class CategoryController extends Controller
1420
{
1521
/**
16-
* Display a listing of the resource.
22+
* @OA\Get(
23+
* path="/api/v1/categories",
24+
* summary="Get list of categories",
25+
* @OA\Response(
26+
* response=200,
27+
* description="A list of categories"
28+
* )
29+
* )
1730
*/
1831
public function index()
1932
{
20-
return CategoriesCollection::collection(Category::orderBy('sort', 'asc')->get());
33+
return success(CategoriesCollection::collection(Category::orderBy('sort', 'asc')->get()));
2134
}
2235

23-
public function show(Category $category){
24-
return new CategoryResource($category);
36+
37+
/**
38+
* @OA\Get(
39+
* path="/api/v1/category/{category}",
40+
* summary="Get category",
41+
* @OA\Parameter(
42+
* description="Slug of one category",
43+
* name="category",
44+
* in="path",
45+
* required=true,
46+
* @OA\Schema(
47+
* type="string"
48+
* ),
49+
* ),
50+
* @OA\Parameter(
51+
* description="sub products per page",
52+
* name="per_page",
53+
* in="query",
54+
* required=false,
55+
* @OA\Schema(
56+
* type="integer"
57+
* )
58+
* ),
59+
* @OA\Response(
60+
* response=200,
61+
* description="A category with datas"
62+
* )
63+
* )
64+
*/
65+
public function show(Category $category)
66+
{
67+
return success(new CategoryResource($category));
2568
}
2669

2770

71+
2872
public function props( $id){
2973
$category = Category::whereId($id)->firstOrFail();
3074
return PropCollection::collection($category->props()->orderBy('sort')->get());

app/Http/Controllers/Api/GroupController.php

+45-4
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,65 @@
88
use App\Models\Group;
99
use Illuminate\Http\Request;
1010

11+
12+
/**
13+
* @OA\Info(title="xShop API", version="1.0.0")
14+
*/
15+
/**
16+
* @OA\PathItem(path="/api/v1")
17+
*/
1118
class GroupController extends Controller
1219
{
20+
21+
1322
/**
14-
* Display a listing of the resource.
23+
* @OA\Get(
24+
* path="/api/v1/groups",
25+
* summary="Get list of groups",
26+
* @OA\Response(
27+
* response=200,
28+
* description="A list of categories"
29+
* )
30+
* )
1531
*/
1632
public function index()
1733
{
1834
//
19-
return GroupsCollection::collection(Group::orderBy('sort', 'asc')->get());
35+
return success(GroupsCollection::collection(Group::orderBy('sort', 'asc')->get()));
2036
}
2137

2238

2339
/**
24-
* Display the specified resource.
40+
* @OA\Get(
41+
* path="/api/v1/group/{group}",
42+
* summary="Get category",
43+
* @OA\Parameter(
44+
* description="Slug of one group",
45+
* name="group",
46+
* in="path",
47+
* required=true,
48+
* @OA\Schema(
49+
* type="string"
50+
* ),
51+
* ),
52+
* @OA\Parameter(
53+
* description="sub posts per page",
54+
* name="per_page",
55+
* in="query",
56+
* required=false,
57+
* @OA\Schema(
58+
* type="integer"
59+
* )
60+
* ),
61+
* @OA\Response(
62+
* response=200,
63+
* description="A group with datas"
64+
* )
65+
* )
2566
*/
2667
public function show(Group $group)
2768
{
2869
//
29-
return GroupCollection::make($group);
70+
return success(GroupCollection::make($group));
3071
}
3172
}

app/Http/Controllers/Api/ProductController.php

+66
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,74 @@
99
use Illuminate\Http\Request;
1010
use Illuminate\Support\Facades\Cache;
1111

12+
/**
13+
* @OA\Info(title="xShop API", version="1.0.0")
14+
*/
15+
/**
16+
* @OA\PathItem(path="/api/v1")
17+
*/
1218
class ProductController extends Controller
1319
{
20+
21+
/**
22+
* @OA\Get(
23+
* path="/api/v1/products",
24+
* summary="Get list of products",
25+
* @OA\Parameter(
26+
* name="sort",
27+
* in="query",
28+
* required=false,
29+
* @OA\Schema(
30+
* type="string",
31+
* enum={"new", "old", "most_view", "less_view", "most_buy", "less_buy"}
32+
* )
33+
* ),
34+
* @OA\Parameter(
35+
* name="category",
36+
* in="query",
37+
* required=false,
38+
* @OA\Schema(
39+
* type="string"
40+
* )
41+
* ),
42+
* @OA\Parameter(
43+
* name="search",
44+
* in="query",
45+
* required=false,
46+
* @OA\Schema(
47+
* type="string"
48+
* )
49+
* ),
50+
* @OA\Parameter(
51+
* name="min_price",
52+
* in="query",
53+
* required=false,
54+
* @OA\Schema(
55+
* type="integer"
56+
* )
57+
* ),
58+
* @OA\Parameter(
59+
* name="max_price",
60+
* in="query",
61+
* required=false,
62+
* @OA\Schema(
63+
* type="integer"
64+
* )
65+
* ),
66+
* @OA\Parameter(
67+
* name="per_page",
68+
* in="query",
69+
* required=false,
70+
* @OA\Schema(
71+
* type="integer"
72+
* )
73+
* ),
74+
* @OA\Response(
75+
* response=200,
76+
* description="A list of products"
77+
* )
78+
* )
79+
*/
1480
public function index(Request $request)
1581
{
1682

app/OpenApi/Swagger.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\OpenApi;
4+
5+
/**
6+
* @OA\Info(title="xShop API", version="1.0.0")
7+
*/
8+
class Swagger
9+
{
10+
11+
}

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"ext-zip": "*",
1212
"carlos-meneses/laravel-mpdf": "^2.1",
1313
"chillerlan/php-qrcode": "^5.0",
14+
"darkaonline/l5-swagger": "^8.6",
1415
"dpsoft/mellat": "^1.1",
1516
"dpsoft/parsian-payment": "^1.0",
1617
"dpsoft/pay.ir": "dev-master",

0 commit comments

Comments
 (0)