diff --git a/app/Http/Controllers/InteractionController.php b/app/Http/Controllers/InteractionController.php index e646959..01bf254 100644 --- a/app/Http/Controllers/InteractionController.php +++ b/app/Http/Controllers/InteractionController.php @@ -18,7 +18,7 @@ class InteractionController extends Controller */ public function togglesState(Deal $deal, InteractionType $type) { - if (! in_array($type, [InteractionType::Like, InteractionType::Favorite])) { + if (!in_array($type, [InteractionType::Like, InteractionType::Favorite])) { return response()->json(['error' => 'This interaction is not supported'], 400); } @@ -53,7 +53,7 @@ public function togglesState(Deal $deal, InteractionType $type) Log::error('Error when liked a deal', [ 'deal_id' => $deal->id, - 'use_id' => Auth::id(), + 'user_id' => Auth::id(), 'type' => $type, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), @@ -63,4 +63,37 @@ public function togglesState(Deal $deal, InteractionType $type) return response()->json(['error' => 'Something went wrong.'], 500); } } + + public function redirect(Deal $deal) + { + if (blank($deal->link)) { + abort(404); + } + + \Illuminate\Support\defer(function () use ($deal) { + try { + $interaction = $deal->interactions()->firstOrCreate([ + 'type' => InteractionType::Redirection, + 'user_id' => Auth::id(), + ]); + + if (!$interaction->wasRecentlyCreated) { + $interaction->increment('count'); + } + + } catch (\Throwable $e) { + Log::error('Error when redirecting a deal external link', + [ + 'deal_id' => $deal->id, + 'user_id' => Auth::id(), + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString(), + ] + ); + abort(500); + } + }); + + return redirect()->away($deal->link); + } } diff --git a/app/Http/Requests/DealOutboundRequest.php b/app/Http/Requests/DealOutboundRequest.php new file mode 100644 index 0000000..d0574d9 --- /dev/null +++ b/app/Http/Requests/DealOutboundRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Models/Interaction.php b/app/Models/Interaction.php index 43b8ff0..ec074c8 100644 --- a/app/Models/Interaction.php +++ b/app/Models/Interaction.php @@ -8,6 +8,11 @@ class Interaction extends Model { + protected $fillable = [ + 'type', + 'user_id', + ]; + public function user(): BelongsTo { return $this->belongsTo(Deal::class); diff --git a/resources/views/components/dashboard/broker/listing-card.blade.php b/resources/views/components/dashboard/broker/listing-card.blade.php index 305ed5f..088c217 100644 --- a/resources/views/components/dashboard/broker/listing-card.blade.php +++ b/resources/views/components/dashboard/broker/listing-card.blade.php @@ -1,14 +1,14 @@ -@props(['id' => '', 'image' => '', 'title' => '', 'category' => '', 'impressions' => 0, 'likes' => 0, 'clicks' => 0, 'status' => false, 'external_link' => '']) +@props(['deal']) - +
-

{{$title}}

+

{{$deal->title}}

- @if($external_link !== '') - link)) + @@ -16,7 +16,7 @@ class="text-xs underline text-accent-601 mt-1">
- @if($status == 1) + @if($deal->active == 1) @else @@ -25,15 +25,15 @@ class="text-xs underline text-accent-601 mt-1">
-

{{$category}}

+

{{$deal->category->name}}

- +
- Edit -
+ @csrf @method("DELETE") Delete diff --git a/resources/views/components/dashboard/broker/listing.blade.php b/resources/views/components/dashboard/broker/listing.blade.php index 40610eb..0730fac 100644 --- a/resources/views/components/dashboard/broker/listing.blade.php +++ b/resources/views/components/dashboard/broker/listing.blade.php @@ -4,17 +4,7 @@

My Listings

@forelse($deals as $deal) - + @empty

No Deals created

@endforelse diff --git a/resources/views/components/dashboard/user/action-toolbar.blade.php b/resources/views/components/dashboard/user/action-toolbar.blade.php index 5324808..b245995 100644 --- a/resources/views/components/dashboard/user/action-toolbar.blade.php +++ b/resources/views/components/dashboard/user/action-toolbar.blade.php @@ -1,5 +1,15 @@ -@props(['deal_id', 'deal_title', 'like' => false, 'favourite' => false]) +@props(['deal_id', 'deal_title', 'like' => false, 'favourite' => false, 'deal_link' => ''])
+ @if(filled($deal_link)) + + + + @endif + $like]) onclick="like(this, {{$deal_id}})"> category->name}} @ds($deal) - +

{{$deal->title}}

diff --git a/resources/views/components/ui/button-sm.blade.php b/resources/views/components/ui/button-sm.blade.php index b9c97a6..74ce6e0 100644 --- a/resources/views/components/ui/button-sm.blade.php +++ b/resources/views/components/ui/button-sm.blade.php @@ -1,4 +1,4 @@ -@props(['variant' => '', 'link' => '']) +@props(['variant' => '', 'link' => '', 'external' => false]) @php $variants = [ 'neutral' => 'bg-primary-600 text-white', @@ -8,7 +8,7 @@ $variantClass = $variants[$variant] ?? ''; @endphp @if($link !== '') - merge(['class' => "px-2 py-1 text-xs rounded-md font-medium hover:opacity-80 hover: active:scale-80 transition-all duration-300 ease-in-out $variantClass"])}}> + merge(['class' => "inline-flex px-2 py-1 text-xs rounded-md font-medium hover:opacity-80 hover: active:scale-80 transition-all duration-300 ease-in-out $variantClass"])}}> {{$slot}} @else diff --git a/routes/web/interaction.php b/routes/web/interaction.php index ee7337f..7a84ec1 100644 --- a/routes/web/interaction.php +++ b/routes/web/interaction.php @@ -17,5 +17,11 @@ ->middleware('throttle:30,1') ->name('favorite'); - Route::post('/report/{deal}', [ReportController::class, 'store'])->name('report.store'); + Route::post('/report/{deal}', [ReportController::class, 'store']) + ->middleware('throttle:5,1') + ->name('report.store'); + + Route::get('/redirect/{deal}', [InteractionController::class, 'redirect']) + ->middleware(['throttle:10,1', 'signed']) + ->name('redirect'); });