Skip to content

Commit

Permalink
added swagger for project api
Browse files Browse the repository at this point in the history
  • Loading branch information
A1Gard committed Jan 1, 2025
1 parent 9bc2cde commit c996647
Show file tree
Hide file tree
Showing 11 changed files with 2,117 additions and 723 deletions.
52 changes: 48 additions & 4 deletions app/Http/Controllers/Api/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,65 @@
use App\Models\Prop;
use Illuminate\Http\Request;

/**
* @OA\Info(title="xShop API", version="1.0.0")
*/
/**
* @OA\PathItem(path="/api/v1")
*/
class CategoryController extends Controller
{
/**
* Display a listing of the resource.
* @OA\Get(
* path="/api/v1/categories",
* summary="Get list of categories",
* @OA\Response(
* response=200,
* description="A list of categories"
* )
* )
*/
public function index()
{
return CategoriesCollection::collection(Category::orderBy('sort', 'asc')->get());
return success(CategoriesCollection::collection(Category::orderBy('sort', 'asc')->get()));
}

public function show(Category $category){
return new CategoryResource($category);

/**
* @OA\Get(
* path="/api/v1/category/{category}",
* summary="Get category",
* @OA\Parameter(
* description="Slug of one category",
* name="category",
* in="path",
* required=true,
* @OA\Schema(
* type="string"
* ),
* ),
* @OA\Parameter(
* description="sub products per page",
* name="per_page",
* in="query",
* required=false,
* @OA\Schema(
* type="integer"
* )
* ),
* @OA\Response(
* response=200,
* description="A category with datas"
* )
* )
*/
public function show(Category $category)
{
return success(new CategoryResource($category));
}



public function props( $id){
$category = Category::whereId($id)->firstOrFail();
return PropCollection::collection($category->props()->orderBy('sort')->get());
Expand Down
49 changes: 45 additions & 4 deletions app/Http/Controllers/Api/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,65 @@
use App\Models\Group;
use Illuminate\Http\Request;


/**
* @OA\Info(title="xShop API", version="1.0.0")
*/
/**
* @OA\PathItem(path="/api/v1")
*/
class GroupController extends Controller
{


/**
* Display a listing of the resource.
* @OA\Get(
* path="/api/v1/groups",
* summary="Get list of groups",
* @OA\Response(
* response=200,
* description="A list of categories"
* )
* )
*/
public function index()
{
//
return GroupsCollection::collection(Group::orderBy('sort', 'asc')->get());
return success(GroupsCollection::collection(Group::orderBy('sort', 'asc')->get()));
}


/**
* Display the specified resource.
* @OA\Get(
* path="/api/v1/group/{group}",
* summary="Get category",
* @OA\Parameter(
* description="Slug of one group",
* name="group",
* in="path",
* required=true,
* @OA\Schema(
* type="string"
* ),
* ),
* @OA\Parameter(
* description="sub posts per page",
* name="per_page",
* in="query",
* required=false,
* @OA\Schema(
* type="integer"
* )
* ),
* @OA\Response(
* response=200,
* description="A group with datas"
* )
* )
*/
public function show(Group $group)
{
//
return GroupCollection::make($group);
return success(GroupCollection::make($group));
}
}
66 changes: 66 additions & 0 deletions app/Http/Controllers/Api/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,74 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

/**
* @OA\Info(title="xShop API", version="1.0.0")
*/
/**
* @OA\PathItem(path="/api/v1")
*/
class ProductController extends Controller
{

/**
* @OA\Get(
* path="/api/v1/products",
* summary="Get list of products",
* @OA\Parameter(
* name="sort",
* in="query",
* required=false,
* @OA\Schema(
* type="string",
* enum={"new", "old", "most_view", "less_view", "most_buy", "less_buy"}
* )
* ),
* @OA\Parameter(
* name="category",
* in="query",
* required=false,
* @OA\Schema(
* type="string"
* )
* ),
* @OA\Parameter(
* name="search",
* in="query",
* required=false,
* @OA\Schema(
* type="string"
* )
* ),
* @OA\Parameter(
* name="min_price",
* in="query",
* required=false,
* @OA\Schema(
* type="integer"
* )
* ),
* @OA\Parameter(
* name="max_price",
* in="query",
* required=false,
* @OA\Schema(
* type="integer"
* )
* ),
* @OA\Parameter(
* name="per_page",
* in="query",
* required=false,
* @OA\Schema(
* type="integer"
* )
* ),
* @OA\Response(
* response=200,
* description="A list of products"
* )
* )
*/
public function index(Request $request)
{

Expand Down
11 changes: 11 additions & 0 deletions app/OpenApi/Swagger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\OpenApi;

/**
* @OA\Info(title="xShop API", version="1.0.0")
*/
class Swagger
{

}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"ext-zip": "*",
"carlos-meneses/laravel-mpdf": "^2.1",
"chillerlan/php-qrcode": "^5.0",
"darkaonline/l5-swagger": "^8.6",
"dpsoft/mellat": "^1.1",
"dpsoft/parsian-payment": "^1.0",
"dpsoft/pay.ir": "dev-master",
Expand Down
Loading

0 comments on commit c996647

Please sign in to comment.