Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:hngprojects/hng_boilerplate_php_lara…
Browse files Browse the repository at this point in the history
…vel_web into feat/add-languages
  • Loading branch information
amowogbaje committed Aug 7, 2024
2 parents d10e6a6 + 866e1a7 commit 8451ed2
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 1 deletion.
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
15 changes: 15 additions & 0 deletions app/Http/Controllers/Api/V1/User/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*/
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');
}
}
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.
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

});

Expand Down

0 comments on commit 8451ed2

Please sign in to comment.