Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…php_laravel_web into feat/fetchAllRolesInAnOrganisation-endpoint
  • Loading branch information
sparkybug committed Aug 8, 2024
2 parents 588e7e8 + 866e1a7 commit c13e9fa
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function store(Request $request)
'quantity' => $request->quantity,
'is_archived' => false,
'org_id' => $request->org_id,
'category' => $request->category,
]);

return response()->json([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers\Api\V1\Admin;
namespace App\Http\Controllers\Api\V1\User;

use App\Http\Controllers\Controller;
use App\Models\Order;
Expand Down Expand Up @@ -84,18 +84,43 @@ public function index()
'message' => 'Dashboard retrieved successfully',
'status_code' => Response::HTTP_OK,
'data' => [
'current_month_revenue' => $currentMonthRevenue,
'difference_in_revenue_percent' => $percentageDifference . '%',
'subscriptions' => 0,
'monthly_subscriptions_diff' => 0,
'current_month_orders' => $currentMonthOrders,
'difference_in_orders_percent' => $percentageDifferenceOrders . '%',
'active_users_count' => $activeUser,
'difference_an_hour_ago' => max(($activeUser - $activeUserAnHourAgo), 0),
'revenue' => [
'current_month' => $currentMonthRevenue,
'previous_month' => $lastMonthRevenue,
'percentage_difference' => $percentageDifference . '%',
],
'subscriptions' => [
'current_month' => 0,
'previous_month' => 0,
'percentage_difference' => 0 . '%',
],
'orders' => [
'current_month' => $currentMonthOrders,
'previous_month' => $lastMonthOrders,
'percentage_difference' => $percentageDifferenceOrders . '%',
],
'active_users' => [
'current' => $activeUser,
'difference_an_hour_ago' => max(($activeUser - $activeUserAnHourAgo), 0),
],
]
]);
}

public function recent_sales()
{
$user = auth()->user();
$orders = Order::whereHas('product', function ($query) use ($user) {
$query->where('user_id', $user->id);
})->with('user')->get();

return response()->json([
'message' => 'Recent sales retrieved successfully',
'status_code' => Response::HTTP_OK,
'data' => $orders,
]);
}

/**
* Show the form for creating a new resource.
*/
Expand Down
11 changes: 11 additions & 0 deletions app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Order extends Model
{
use HasUuids;
use HasFactory;

public function product(): BelongsTo
{
return $this->belongsTo(Product::class, 'product_id');
}

public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
}
10 changes: 9 additions & 1 deletion database/factories/OrderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ public function definition(): array
return [
'user_id' => User::factory(),
'product_id' => Product::factory(),
'status' => $this->faker->boolean,
'quantity' => $this->faker->randomDigit(),
'total_amount' => $this->faker->randomDigit(),
'order_number' => $orderNumber,
'tax' => $this->faker->randomFloat(2, 1, 100),
'shipping_cost' => $this->faker->randomFloat(2, 5, 50),
'discount' => $this->faker->randomFloat(2, 0, 50),
'status' => $this->faker->randomElement(['pending', 'processing', 'shipped', 'delivered']),
'payment_status' => $this->faker->randomElement(['unpaid', 'paid', 'refunded']),
'payment_method' => $this->faker->randomElement(['credit_card', 'paypal', 'bank_transfer']),
'shipping_address' => $this->faker->address,
'billing_address' => $this->faker->address,
'notes' => $this->faker->optional()->sentence,
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/seeders/OrderSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class OrderSeeder extends Seeder
{
public function run()
{
// Order::factory()->count(10)->create();
Order::factory()->count(10)->create();
}
}
Binary file added public/uploads/1723041952.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1723065375.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1723065604.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1723066655.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1723066919.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1723068692.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/docs/documentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4402,7 +4402,7 @@
}
}
},
"/api/v1/dashboard-cards": {
"/api/v1/user-statistics": {
"get": {
"summary": "Get a dashboard card content",
"tags": [
Expand Down
54 changes: 34 additions & 20 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\QuestController;
use App\Http\Controllers\Api\V1\JobController;
use App\Http\Controllers\Api\V1\RoleController;
use App\Http\Controllers\BillingPlanController;
use App\Http\Controllers\Api\V1\Admin\BlogController;
use App\Http\Controllers\Api\V1\Admin\CustomerController;
use App\Http\Controllers\Api\V1\Admin\EmailTemplateController;
use App\Http\Controllers\Api\V1\Admin\FaqController;
use App\Http\Controllers\Api\V1\Admin\Plan\FeatureController;
use App\Http\Controllers\Api\V1\Admin\Plan\SubscriptionController;
use App\Http\Controllers\Api\V1\ArticleController;
use App\Http\Controllers\Api\V1\Auth\AuthController;
use App\Http\Controllers\Api\V1\Auth\ForgetPasswordRequestController;
use App\Http\Controllers\Api\V1\Auth\ForgotResetPasswordController;
use App\Http\Controllers\Api\V1\Auth\LoginController;
use App\Http\Controllers\Api\V1\Auth\ResetUserPasswordController;
use App\Http\Controllers\Api\V1\Auth\SocialAuthController;
use App\Http\Controllers\Api\V1\BlogSearchController;
use App\Http\Controllers\Api\V1\CategoryController;
use App\Http\Controllers\Api\V1\CommentController;
use App\Http\Controllers\Api\V1\ContactController;
use App\Http\Controllers\Api\V1\CookiePreferencesController;
use App\Http\Controllers\Api\V1\HelpArticleController;
use App\Http\Controllers\Api\V1\JobController;
use App\Http\Controllers\Api\V1\JobSearchController;
use App\Http\Controllers\Api\V1\NotificationPreferenceController;
use App\Http\Controllers\Api\V1\Organisation\OrganisationController;
use App\Http\Controllers\Api\V1\Organisation\OrganizationMemberController;
use App\Http\Controllers\Api\V1\PaymentController;
use App\Http\Controllers\Api\V1\PreferenceController;
use App\Http\Controllers\Api\V1\ProductController;
use App\Http\Controllers\Api\V1\RoleController;
use App\Http\Controllers\Api\V1\SqueezeController;
use App\Http\Controllers\Api\V1\CategoryController;
use App\Http\Controllers\Api\V1\TimezoneController;
use App\Http\Controllers\Api\V1\WaitListController;
use App\Http\Controllers\Api\V1\Admin\FaqController;
use App\Http\Controllers\Api\V1\Auth\AuthController;
use App\Http\Controllers\Api\V1\JobSearchController;
use App\Http\Controllers\Api\V1\User\UserController;
use App\Http\Controllers\UserNotificationController;
use App\Http\Controllers\Api\V1\Admin\BlogController;
use App\Http\Controllers\Api\V1\Auth\LoginController;
use App\Http\Controllers\Api\V1\BlogSearchController;
use App\Http\Controllers\Api\V1\PreferenceController;
use App\Http\Controllers\Api\V1\HelpArticleController;
use App\Http\Controllers\Api\V1\SqueezePageCoontroller;
use App\Http\Controllers\Api\V1\SuperAdmin\SuperAdminProductController;
use App\Http\Controllers\Api\V1\Testimonial\TestimonialController;
use App\Http\Controllers\Api\V1\TimezoneController;
use App\Http\Controllers\Api\V1\User\AccountController;
use App\Http\Controllers\Api\V1\User\DashboardController;
use App\Http\Controllers\Api\V1\User\ExportUserController;
use App\Http\Controllers\Api\V1\User\ProfileController;
use App\Http\Controllers\NotificationSettingController;
use App\Http\Controllers\Api\V1\User\UserController;
use App\Http\Controllers\Api\V1\WaitListController;
use App\Http\Controllers\BillingPlanController;
use App\Http\Controllers\InvitationAcceptanceController;
use App\Http\Controllers\Api\V1\Admin\CustomerController;
use App\Http\Controllers\Api\V1\Admin\DashboardController;
Expand Down Expand Up @@ -238,7 +250,6 @@
Route::delete('/blogs/{id}', [BlogController::class, 'destroy']);
Route::get('/waitlists', [WaitListController::class, 'index']);
Route::apiResource('squeeze-pages', SqueezePageCoontroller::class);
Route::get('/dashboard-cards', [DashboardController::class, 'index']);
});

Route::post('/waitlists', [WaitListController::class, 'store']);
Expand All @@ -253,6 +264,9 @@
Route::put('/user/preferences/{id}', [PreferenceController::class, 'update']);
Route::get('/user/preferences', [PreferenceController::class, 'index']);
Route::delete('/user/preferences/{id}', [PreferenceController::class, 'delete']);
Route::get('/user-statistics', [DashboardController::class, 'index']);
Route::get('/user-sales', [DashboardController::class, 'recent_sales']);

});

// Notification settings
Expand Down

0 comments on commit c13e9fa

Please sign in to comment.