diff --git a/app/Http/Controllers/Api/V1/SuperAdmin/SuperAdminProductController.php b/app/Http/Controllers/Api/V1/SuperAdmin/SuperAdminProductController.php index 811b22a0..4646510c 100644 --- a/app/Http/Controllers/Api/V1/SuperAdmin/SuperAdminProductController.php +++ b/app/Http/Controllers/Api/V1/SuperAdmin/SuperAdminProductController.php @@ -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([ diff --git a/app/Http/Controllers/Api/V1/User/DashboardController.php b/app/Http/Controllers/Api/V1/User/DashboardController.php index f8b2cd9b..ef5d233c 100644 --- a/app/Http/Controllers/Api/V1/User/DashboardController.php +++ b/app/Http/Controllers/Api/V1/User/DashboardController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api\V1\User; use App\Http\Controllers\Controller; +use App\Models\Order; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -106,6 +107,20 @@ public function index() ]); } + 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. */ diff --git a/app/Models/Order.php b/app/Models/Order.php index 747ba981..8ca3fa44 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -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'); + } } diff --git a/database/seeders/OrderSeeder.php b/database/seeders/OrderSeeder.php index 5fd30d41..8f144ab9 100644 --- a/database/seeders/OrderSeeder.php +++ b/database/seeders/OrderSeeder.php @@ -14,6 +14,6 @@ class OrderSeeder extends Seeder { public function run() { - // Order::factory()->count(10)->create(); + Order::factory()->count(10)->create(); } } diff --git a/public/uploads/1723041952.jpg b/public/uploads/1723041952.jpg new file mode 100644 index 00000000..b0079762 Binary files /dev/null and b/public/uploads/1723041952.jpg differ diff --git a/public/uploads/1723065375.jpg b/public/uploads/1723065375.jpg new file mode 100644 index 00000000..b0079762 Binary files /dev/null and b/public/uploads/1723065375.jpg differ diff --git a/public/uploads/1723065604.jpg b/public/uploads/1723065604.jpg new file mode 100644 index 00000000..b0079762 Binary files /dev/null and b/public/uploads/1723065604.jpg differ diff --git a/public/uploads/1723066655.jpg b/public/uploads/1723066655.jpg new file mode 100644 index 00000000..b0079762 Binary files /dev/null and b/public/uploads/1723066655.jpg differ diff --git a/public/uploads/1723066919.jpg b/public/uploads/1723066919.jpg new file mode 100644 index 00000000..b0079762 Binary files /dev/null and b/public/uploads/1723066919.jpg differ diff --git a/public/uploads/1723068692.jpg b/public/uploads/1723068692.jpg new file mode 100644 index 00000000..b0079762 Binary files /dev/null and b/public/uploads/1723068692.jpg differ diff --git a/routes/api.php b/routes/api.php index d2c352d5..e7510d04 100755 --- a/routes/api.php +++ b/routes/api.php @@ -253,6 +253,7 @@ 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']); });