Skip to content

Commit

Permalink
product get
Browse files Browse the repository at this point in the history
  • Loading branch information
amowogbaje committed Aug 24, 2024
1 parent ed6dd18 commit 6614a1d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions app/Http/Controllers/Api/V1/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,59 @@ public function show(Request $request, $org_id, $product_id)



return response()->json([
'status_code' => 200,
"message" => "Product retrieved successfully",
'data' => $transformedProduct
]);
}

public function showProduct($product_id)
{
$product = Product::find($product_id);
if (!$product) {
return response()->json([
'status' => 'error',
"message" => "Product not found",
'status_code' => 404,
]);
}

$products = Product::select(
'product_id',
'name',
'price',
'imageUrl',
'description',
'created_at',
'updated_at',
'quantity',
'status',
'size',
'category'
)->get();

$transformedProduct = [
'id' => $product->product_id,
'name' => $product->name,
'price' => $product->price,
'cost_price' => $product->cost_price,
'image' => url($product->imageUrl),
'description' => $product->description,
'quantity' => $product->quantity,
'category' => $product->category,
'status' => $product->status,
'size' => $product->size,
'created_at' => $product->created_at,
'updated_at' => $product->updated_at,
'deletedAt' => $product->deletedAt,



];



return response()->json([
'status_code' => 200,
"message" => "Product retrieved successfully",
Expand Down
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
Route::get('/products/categories', [CategoryController::class, 'index']);
Route::get('/products/search', [ProductController::class, 'search']);
Route::get('/products', [ProductController::class, 'index']);
Route::get('/products/{product_id}', [ProductController::class, 'show']);
Route::get('/products/{product_id}', [ProductController::class, 'showProduct']);
Route::delete('/products/{product_id}', [ProductController::class, 'delete']);

Route::get('/billing-plans', [BillingPlanController::class, 'index']);
Expand Down

0 comments on commit 6614a1d

Please sign in to comment.