Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get product id #589

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions app/Http/Controllers/Api/V1/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@ public function index(Request $request)
{
try {

$categories = Category::all();
$categories = Category::all();

return response()->json([
'status_code' => 200,
'message' => 'Categories returned successfully',
'data' => $categories,
]);

}catch (\Exception $e) {
return response()->json([
'status_code' => 500,
'error' => [
'message' => 'An unexpected error occurred while processing your request.',
'details' => [
'support_email' => '[email protected]',
return response()->json([
'status_code' => 200,
'message' => 'Categories returned successfully',
'data' => $categories,
]);
} catch (\Exception $e) {
return response()->json([
'status_code' => 500,
'error' => [
'message' => 'An unexpected error occurred while processing your request.',
'details' => [
'support_email' => '[email protected]',
],
],
],
], 500);
}
], 500);
}
}
}
78 changes: 78 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 Expand Up @@ -372,4 +425,29 @@ public function destroy($org_id, $product_id)
'data' => $product
], 200);
}

public function delete($product_id)
{



$product = Product::find($product_id);

if (!$product) {
return response()->json([
'error' => 'Product not found',
'message' => "The product with ID $product_id does not exist."
], 404);
}



$product->delete();

return response()->json([
'status_code' => 204,
'message' => 'Product successfully deleted.',
// 'data' => $product
], 204);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function up(): void
Schema::table('timezones', function (Blueprint $table) {
$table->renameColumn('name', 'timezone');
$table->renameColumn('offset', 'gmtoffset');
$table->string('description')->after('gmtoffset');
$table->string('description');
});
}

Expand Down
4 changes: 3 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
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']);
Route::get('/billing-plans/{id}', [BillingPlanController::class, 'getBillingPlan']);
Route::get('/payments/paystack/{organisation_id}/verify/{id}', [PaymentController::class, 'handlePaystackCallback']);
Expand Down
Loading