Skip to content

Commit

Permalink
added price sort
Browse files Browse the repository at this point in the history
  • Loading branch information
A1Gard committed Jan 5, 2025
1 parent c996647 commit 76f3162
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/Api/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ProductController extends Controller
* required=false,
* @OA\Schema(
* type="string",
* enum={"new", "old", "most_view", "less_view", "most_buy", "less_buy"}
* enum={"new", "old", "most_view", "less_view", "most_buy", "less_buy","cheap","expensive"}
* )
* ),
* @OA\Parameter(
Expand Down Expand Up @@ -100,6 +100,10 @@ public function index(Request $request)
$product = $product->orderByDesc('sell');
if ($request['sort'] === 'less_buy')
$product = $product->orderBy('sell');
if ($request['sort'] === 'cheap')
$product = $product->orderBy('price');
if ($request['sort'] === 'expensive')
$product = $product->orderByDesc('price');
}
if (isset($request['category']) && !is_null($request['category']))
$product = $product->where('category_id', Category::firstWhere('slug', $request['category'])->id);
Expand Down
4 changes: 3 additions & 1 deletion storage/api-docs/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@
"most_view",
"less_view",
"most_buy",
"less_buy"
"less_buy",
"cheap",
"expensive"
]
}
},
Expand Down

0 comments on commit 76f3162

Please sign in to comment.