Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
ngdream committed Nov 8, 2024
1 parent 583e228 commit 8e6f8d5
Show file tree
Hide file tree
Showing 42 changed files with 544 additions and 125 deletions.
7 changes: 4 additions & 3 deletions app/Http/Controllers/AdController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function index(Request $request)
$query->whereIn('id', $user->unlockedAds->pluck('ad_id'));
}

$ads = $query->with('adable')->paginate(10);
$ads = $query->with('adable')->paginate(20);

return AdResource::collection($ads);
}
Expand All @@ -82,9 +82,11 @@ public function store(StoreAdRequest $request)
}
// Create ad and associate it with the specific ad type
$ad = new Ad($validated);
$adable->ad()->save($ad);
$announcer = $request->user()->announcer;

$ad->announcer()->associate($announcer);

$adable->ad()->save($ad);
if ($request->hasFile("medias")) {
$medias = new Collection();
foreach ($request->medias as $file) {
Expand All @@ -96,7 +98,6 @@ public function store(StoreAdRequest $request)
$img->type = $mimetype;
$img->announcer()->associate($ad->announcer);
$img->save();

$medias->push($img);
}
$ad->medias()->syncWithoutDetaching($medias);
Expand Down
7 changes: 2 additions & 5 deletions app/Http/Controllers/AdMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
use App\Models\Media;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class AdMediaController extends Controller
{

/**
* Display a listing of the resource.
*/
public function index(Ad $ad)
{
$medias = $ad->medias()->get();
$medias = $ad->medias()->paginate(15);
return MediaResource::collection($medias);
}

Expand All @@ -26,7 +26,6 @@ public function index(Ad $ad)
*/
public function store(Request $request, Ad $ad)
{

if ($request->hasFile("medias")) {
$medias = new Collection();
foreach ($request->medias as $file) {
Expand All @@ -36,8 +35,6 @@ public function store(Request $request, Ad $ad)
$savedfile = $img->file->storeAs('public/medias', $filename);
$img->file = $savedfile;
$img->type = $mimetype;


$img->save();
$img->announcer()->associate($ad->announcer);
$medias->push($img);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/AnnouncerAdController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AnnouncerAdController extends Controller
*/
public function index(Announcer $announcer)
{
$ads = $announcer->ads;
$ads = $announcer->ads()->paginate(15);
return Adresource::collection($ads);
}
}
5 changes: 5 additions & 0 deletions app/Http/Controllers/AnnouncerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public function show(Announcer $announcer)
return new AnnouncerResource($announcer);
}

public function updatePresentation() {}


public function updateAvatar() {}

/**
* Update the specified announcer in storage.
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/AnnouncerMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AnnouncerMediaController extends Controller
*/
public function index(Announcer $announcer)
{
$medias = $announcer->medias()->get();
$medias = $announcer->medias()->paginate();
return MediaResource::collection($medias);
}
}
5 changes: 1 addition & 4 deletions app/Http/Controllers/AnnouncerRequestsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace App\Http\Controllers;

use App\Http\Requests\StoreAnnouncerRequest;
use App\Http\Resources\AnnouncerResource;

use App\Models\Announcer;
use App\Models\AnnouncerRequest;
use App\Models\User;
use Illuminate\Http\Request;

class AnnouncerRequestsController extends Controller
Expand Down Expand Up @@ -79,7 +77,6 @@ public function update(Request $request, $id)
// If approved, create announcer account and update user role
if ($request->status === 'approved') {
$user = $announcerRequest->user;

// Create announcer account
Announcer::create([
'user_id' => $user->id,
Expand Down
43 changes: 20 additions & 23 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ public function register(Request $request)

public function resendVerificationCode($user_id)
{
// $request->validate([
// 'user_id' => 'required|exists:users,id',
// ]);

$user = User::find($user_id);

Expand Down Expand Up @@ -171,15 +168,14 @@ public function login(Request $request)
$token = Auth::guard('api')->attempt($credentials);
if (!$token) {
return response()->json([
'status' => 'error',
'message' => 'Unauthorized',
], 401);
'code' => '403',
'message' => 'bad credentials',
], 403);
}

// Réponse de succès
$user = Auth::guard('api')->user();
return response()->json([
'status' => 'success',
'user' => $user,
'authorisation' => [
'token' => $token,
Expand All @@ -195,30 +191,31 @@ public function logout()
if (!Auth::guard('api')->check()) {
return response()->json(['message' => 'Non authentifié.'], 401);
}
Auth::guard('api')->user();

// Récupérez l'utilisateur actuellement authentifié
$user = Auth::guard('api')->user();

// Invalider le token actuel (deconnexion)
Auth::guard('api')->logout();

// Réponse de succès
return response()->json([
'status' => 'success',
'message' => 'Déconnexion réussie.',
]);
return response()->json(null, 203);
}


public function refresh()
{
return response()->json([
'status' => 'success',
'user' => Auth::guard('api')->user(),
'authorisation' => [
'token' => Auth::guard('api')->refresh(),
'type' => 'bearer',
]
]);
try {
return response()->json([
'status' => 'success',
'user' => Auth::guard('api')->user(),
'authorisation' => [
'token' => Auth::guard('api')->refresh(),
'type' => 'bearer',
]
]);
} catch (\Throwable $th) {
return response()->json([
'code' => 400,
'message' => "token cannot be longer refreshed"
], 400);
}
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class CategoryController extends Controller
public function index()
{

$categories = Category::paginate();
$categories = Category::paginate(20);

return CategoryResource::collection($categories);
}

Expand All @@ -38,7 +39,6 @@ public function show(Category $Category)
return new CategoryResource($Category);
}


/**
* Update the specified resource in storage.
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/MediaAdController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MediaAdController extends Controller
*/
public function index(Media $media)
{
$ads = $media->ads;
$ads = $media->ads()->paginate(15);
return Adresource::collection($ads);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MediaController extends Controller

public function index()
{
$medias = Media::all();
$medias = Media::paginate(15);
return MediaResource::collection($medias);
}
/**
Expand Down
9 changes: 7 additions & 2 deletions app/Http/Controllers/StatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Ad;
use App\Models\Announcer;
use App\Models\User;
use Illuminate\Http\Request;

class StatController extends Controller
Expand All @@ -14,10 +15,14 @@ class StatController extends Controller
public function __invoke(Request $request)
{
return response()->json([
"furnitures"=>Ad::where("item_type",1)->count(),
"furnitures" => Ad::where("item_type", 1)->count(),
"houses" => Ad::where("item_type", 0)->count(),
"announcers" => Announcer::count(),
"verified_announcers"=>Announcer::where("verified",true)->count()
"users" => User::count(),
"month_income" => 0,
"mont" => 9,
"verified_announcers" => Announcer::where("verified", true)->count()

]);
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/SubscriptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Http\Requests\StoreSubscriptionRequest;
use App\Http\Resources\SubscriptionResource;
use App\Models\Subscription;
use App\Models\SubscriptionPlan;
use App\Services\PaymentService;
Expand All @@ -21,7 +22,7 @@ public function index(Request $request)
$user = $request->user();
$subscriptions = Subscription::where('user_id', $user->id)->get();

return response()->json($subscriptions);
return SubscriptionResource::collection($subscriptions);
}

/**
Expand All @@ -43,7 +44,7 @@ public function show(Request $request, Subscription $subscription)
return response()->json(['error' => 'Unauthorized'], 403);
}

return response()->json($subscription);
return new SubscriptionResource($subscription);
}

/**
Expand Down
14 changes: 5 additions & 9 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,11 @@ public function update(Request $request, User $user)
$validated = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email,' . $user->id,
'password' => 'nullable|string|min:8|confirmed',
'phone_number' => 'nullable|string|max:15',
'phone_verified' => 'nullable|boolean',
'is_admin' => 'nullable|boolean',
]);

if (isset($validated['password'])) {
$validated['password'] = Hash::make($validated['password']);
}

$user->update($validated);

return new UserResource($user);
}

Expand All @@ -56,7 +49,7 @@ public function update(Request $request, User $user)
public function destroy(User $user)
{
$user->delete();
return response()->json(['message' => 'User deleted successfully'], 204);
return response()->json(null, 204);
}

/**
Expand All @@ -66,7 +59,10 @@ public function becomeAnnouncer(Request $request, User $user)
{
// Check if a request already exists for this user
if (AnnouncerRequest::where('user_id', $user->id)->exists()) {
return response()->json(['message' => 'A request to become an announcer already exists'], 400);
return response()->json([
'status' => 400,
'message' => 'A request to become an announcer already exists'
], 400);
}

// Create a new announcer request
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/WebhooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class WebhooksController extends Controller
{



//we inject the payment service
public function __construct(protected PaymentService $paymentService) {}
/**
* Subscribe a user to a plan.
Expand All @@ -23,13 +21,10 @@ public function campay(Request $request)
// Retrieve the payment plan by name
$payment = Payment::where('id', $request->external_reference)->firstOrFail();


// Retrieve the subscription plan by name
$subscriptionPlan = SubscriptionPlan::where('name', $payment->payment_type_info)->firstOrFail();

// Create a new subscription for the user


Subscription::create([
'subscription_plan_id' => $subscriptionPlan->id,
'user_id' => $payment->user_id,
Expand Down
Loading

0 comments on commit 8e6f8d5

Please sign in to comment.