Skip to content

Commit

Permalink
feat: added update of subscription plan
Browse files Browse the repository at this point in the history
  • Loading branch information
tulbadex committed Aug 24, 2024
2 parents eef9949 + ab622f2 commit ee8d754
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
18 changes: 13 additions & 5 deletions app/Http/Controllers/Api/V1/Admin/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,12 @@ public function store(Request $request)
public function show(Request $request, string $id)
{
try {
$blog = Blog::find($id);
$blog = Blog::with('comments')->find($id);

if(!$blog){
return response()->json([
'error' => 'Blog not found.',
'message' => 'Blog not found.',
'status_code' => Response::HTTP_NOT_FOUND,
], 404);
}
Expand All @@ -178,14 +179,21 @@ public function show(Request $request, string $id)
'category' => $blog->category,
'content' => $blog->content,
'image_url' => $blog->image_url,
'created_at' => $blog->created_at,
'published_date' => $blog->created_at->toIso8601String(),
'updated_date' => $blog->updated_at->toIso8601String(),
'author_id' => $blog->author_id,
'comments' => $blog->comments->map(function ($comment) {
return [
'id' => $comment->id,
'content' => $comment->content,
'created_at' => $comment->created_at?->toIso8601String(),
];
}),
],
'message' => 'Blog post fetched sucessfully.',
'message' => 'Blog post details fetched sucessfully.',
'status_code' => Response::HTTP_OK,
], Response::HTTP_OK);
} catch (Exception $exception) {
// Log::error('Error creating blog post: ' . $exception->getMessage());
DB::rollBack();
return response()->json(['error' => 'Internal server error.'], 500);
}
}
Expand Down
25 changes: 25 additions & 0 deletions app/Http/Controllers/Api/V1/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,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);
}
}
26 changes: 25 additions & 1 deletion app/Http/Controllers/BillingPlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,30 @@ public function update(Request $request, string $id)
*/
public function destroy(string $id)
{
//
$plans = SubscriptionPlan::find($id);

if (!$plans) {
return response()->json([
'status_code' => 404,
'error' => 'Not Found',
'message' => 'Plan not found'
], 404);
}

try {
$plans->delete();

// Return success response
return response()->json([
'data' => true,
'status_code' => 200,
'message' => 'Plan deleted successfully'
], 200);
} catch (\Exception $e) {
return response()->json([
'status' => 500,
'message' => 'Internal server error'
], 500);
}
}
}
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
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
Route::get('/products/search', [ProductController::class, 'search']);
Route::get('/products', [ProductController::class, 'index']);
Route::get('/products/{product_id}', [ProductController::class, 'show']);
Route::delete('/products/{product_id}', [ProductController::class, 'delete']);

Route::get('/billing-plans', [BillingPlanController::class, 'index']);
Route::get('/billing-plans/{id}', [BillingPlanController::class, 'getBillingPlan']);
Route::put('/billing-plans/{id}', [BillingPlanController::class, 'update']);
Expand Down

0 comments on commit ee8d754

Please sign in to comment.