fix: empty recent searches, user cannot report deals, category filter is not working with search
This commit is contained in:
parent
94ef8f360d
commit
62c306986c
@ -46,7 +46,6 @@ protected function deals(FormRequest $request, Builder $query, AddRecentSearchAc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add sorting filters
|
// Add sorting filters
|
||||||
if ($request->has('sortBy')) {
|
|
||||||
$query = match (ExplorePageFilters::tryFrom($request->sortBy)) {
|
$query = match (ExplorePageFilters::tryFrom($request->sortBy)) {
|
||||||
ExplorePageFilters::Like => $query->orderBy('total_likes', 'desc'),
|
ExplorePageFilters::Like => $query->orderBy('total_likes', 'desc'),
|
||||||
ExplorePageFilters::Click => $query->orderBy('total_redirection', 'desc'),
|
ExplorePageFilters::Click => $query->orderBy('total_redirection', 'desc'),
|
||||||
@ -54,7 +53,6 @@ protected function deals(FormRequest $request, Builder $query, AddRecentSearchAc
|
|||||||
'((COALESCE(total_likes, 0) * 70.0) / 100.0) + ((COALESCE(total_redirection, 0) * 30.0) / 100.0) DESC'
|
'((COALESCE(total_likes, 0) * 70.0) / 100.0) + ((COALESCE(total_redirection, 0) * 30.0) / 100.0) DESC'
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return $query->latest()->paginate();
|
return $query->latest()->paginate();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class ReportController extends Controller
|
class ReportController extends Controller
|
||||||
@ -30,9 +31,9 @@ public function store(StoreReportRequest $request, Deal $deal)
|
|||||||
$data['user_id'] = Auth::id();
|
$data['user_id'] = Auth::id();
|
||||||
|
|
||||||
// Check if the user already reported the deal
|
// Check if the user already reported the deal
|
||||||
$alreadyReported = $deal->reports()->where('user_id', Auth::id())->first();
|
$alreadyReported = $deal->reports()->where('user_id', Auth::id())->exists();
|
||||||
if ($alreadyReported) {
|
if ($alreadyReported) {
|
||||||
return response()->json(['message' => 'You already reported this report'], 405);
|
return response()->json(['message' => 'You had already reported this deal'], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -42,7 +43,7 @@ public function store(StoreReportRequest $request, Deal $deal)
|
|||||||
Report::reguard();
|
Report::reguard();
|
||||||
});
|
});
|
||||||
|
|
||||||
return response()->json(['message' => 'Report created'], 201);
|
return response()->json(['message' => 'Report submitted. Thank you for keeping DealHub safe'], 201);
|
||||||
|
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
Log::error('Error creating report', [
|
Log::error('Error creating report', [
|
||||||
|
|||||||
@ -105,9 +105,10 @@ public function withViewPerDeal(Builder $query): Builder
|
|||||||
#[Scope]
|
#[Scope]
|
||||||
public function search(Builder $query, string $search): Builder
|
public function search(Builder $query, string $search): Builder
|
||||||
{
|
{
|
||||||
return $query
|
return $query->where(function (Builder $query) use ($search) {
|
||||||
->where('title', 'LIKE', "%$search%")
|
$query->where('title', 'LIKE', "%$search%")
|
||||||
->orWhereRelation('broker', 'name', 'LIKE', "%$search%");
|
->orWhereRelation('broker', 'name', 'LIKE', "%$search%");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -28,20 +28,16 @@ if (reportForm) {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
let response = await axios.post(
|
let response = await axios.post(
|
||||||
`report/${dealId}`,
|
`api/report/${dealId}`,
|
||||||
formData
|
formData
|
||||||
);
|
);
|
||||||
|
|
||||||
showToast('Report submitted. Thank you for keeping DealHub safe!');
|
showToast(response.data.message);
|
||||||
closeModal('report-modal')
|
closeModal('report-modal')
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
if (error.response.status === 405) {
|
|
||||||
closeModal('report-modal');
|
|
||||||
showToast('You already have reported this deal !');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over the all error messages spans and show validation errors
|
// Iterate over the all error messages spans and show validation errors
|
||||||
if (error.response.status === 422) {
|
if (error.response.status === 422) {
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
@props(['searches'])
|
@props(['searches' => []])
|
||||||
|
@if(filled($searches))
|
||||||
<ol class="absolute bg-white shadow-xl border border-gray-300 -top-15 w-full rounded-xl py-4 px-4 flex flex-col opacity-0 scale-y-17 group-focus-within:scale-y-100 group-focus-within:top-15 group-focus-within:opacity-100 transition-all duration-300 ease-out">
|
<ol class="absolute bg-white shadow-xl border border-gray-300 -top-15 w-full rounded-xl py-4 px-4 flex flex-col opacity-0 scale-y-17 group-focus-within:scale-y-100 group-focus-within:top-15 group-focus-within:opacity-100 transition-all duration-300 ease-out">
|
||||||
@foreach($searches as $search)
|
@foreach($searches as $search)
|
||||||
<x-dashboard.user.recent-search.recent-search-item :item="$search"/>
|
<x-dashboard.user.recent-search.recent-search-item :item="$search"/>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ol>
|
</ol>
|
||||||
|
@endif
|
||||||
|
|||||||
@ -138,7 +138,7 @@ class=" h-full items-center flex justify-center">
|
|||||||
<td class="text-sm px-4">{{$report->deals->first()->title}}</td>
|
<td class="text-sm px-4">{{$report->deals->first()->title}}</td>
|
||||||
<x-slot:actions>
|
<x-slot:actions>
|
||||||
<div class="flex items-center justify-center py-1 px-2">
|
<div class="flex items-center justify-center py-1 px-2">
|
||||||
<x-ui.button-sm link="{{route('explore', ['show' => $deal->id])}}" variant="ghost">
|
<x-ui.button-sm link="{{route('explore', ['show' => $report->deals->first()->id])}}" variant="ghost">
|
||||||
<x-heroicon-o-eye class="w-4"/>
|
<x-heroicon-o-eye class="w-4"/>
|
||||||
</x-ui.button-sm>
|
</x-ui.button-sm>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,7 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\Interaction\InteractionController;
|
use App\Http\Controllers\Interaction\InteractionController;
|
||||||
|
use App\Http\Controllers\Interaction\ReportController;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::post('/view/{deal}', [InteractionController::class, 'view'])
|
Route::post('/view/{deal}', [InteractionController::class, 'view'])
|
||||||
->middleware('throttle:30,1')
|
->middleware('throttle:30,1')
|
||||||
->name('view-deal');
|
->name('view-deal');
|
||||||
|
|
||||||
|
Route::middleware('throttle:30,1')->group(function () {
|
||||||
|
Route::post('/report/{deal}', [ReportController::class, 'store'])->name('report-deal');
|
||||||
|
Route::delete('/report/{deal}', [ReportController::class, 'destroy']);
|
||||||
|
});
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use App\Enums\InteractionType;
|
use App\Enums\InteractionType;
|
||||||
use App\Http\Controllers\Interaction\InteractionController;
|
use App\Http\Controllers\Interaction\InteractionController;
|
||||||
use App\Http\Controllers\Interaction\ReportController;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::middleware('auth')->group(function () {
|
Route::middleware('auth')->group(function () {
|
||||||
@ -17,10 +16,6 @@
|
|||||||
->middleware('throttle:30,1')
|
->middleware('throttle:30,1')
|
||||||
->name('favorite');
|
->name('favorite');
|
||||||
|
|
||||||
Route::resource('report', ReportController::class)
|
|
||||||
->middleware('throttle:5,1')
|
|
||||||
->only(['store', 'destroy']);
|
|
||||||
|
|
||||||
Route::get('/redirect/{deal}', [InteractionController::class, 'redirect'])
|
Route::get('/redirect/{deal}', [InteractionController::class, 'redirect'])
|
||||||
->middleware(['throttle:10,1', 'signed'])
|
->middleware(['throttle:10,1', 'signed'])
|
||||||
->name('redirect');
|
->name('redirect');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user