From e5ebe21ed1b9e8eeb9e88aa80295f18757aed216 Mon Sep 17 00:00:00 2001 From: kusowl Date: Mon, 19 Jan 2026 16:39:49 +0530 Subject: [PATCH] feature (external link redirection count of deal): bind the link with the view deal button show the total redirection count reflect the total redirect count immediately add arch test so that dump statements are not left out --- app/Http/Controllers/ExplorePageController.php | 1 + app/Http/Controllers/InteractionController.php | 4 ++-- app/Models/Deal.php | 9 +++++++++ phpunit.xml | 3 +++ resources/js/interaction.js | 17 +++++++++++++++++ .../dashboard/user/action-toolbar.blade.php | 12 +----------- .../dashboard/user/listing-card.blade.php | 15 ++++++++------- resources/views/components/ui/button.blade.php | 8 ++++++-- tests/Arch/ArchTest.php | 5 +++++ 9 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 tests/Arch/ArchTest.php diff --git a/app/Http/Controllers/ExplorePageController.php b/app/Http/Controllers/ExplorePageController.php index 3906ca3..ae39c5d 100644 --- a/app/Http/Controllers/ExplorePageController.php +++ b/app/Http/Controllers/ExplorePageController.php @@ -35,6 +35,7 @@ protected function deals() // Check if the current user interacted with the deal ->withCurrentUserInteractions() ->withLikes() + ->withRedirections() ->latest() ->paginate(); } diff --git a/app/Http/Controllers/InteractionController.php b/app/Http/Controllers/InteractionController.php index 01bf254..2f09f05 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); } @@ -77,7 +77,7 @@ public function redirect(Deal $deal) 'user_id' => Auth::id(), ]); - if (!$interaction->wasRecentlyCreated) { + if (! $interaction->wasRecentlyCreated) { $interaction->increment('count'); } diff --git a/app/Models/Deal.php b/app/Models/Deal.php index 1c663c4..d7254dc 100644 --- a/app/Models/Deal.php +++ b/app/Models/Deal.php @@ -61,6 +61,15 @@ public function scopeWithLikes(Builder $query): Builder ]); } + public function scopeWithRedirections(Builder $query): Builder + { + return $query->withSum([ + 'interactions as total_redirection' => function ($query) { + $query->where('type', InteractionType::Redirection); + }, + ], 'count'); + } + public function reports(): BelongsToMany { return $this->belongsToMany(Report::class); diff --git a/phpunit.xml b/phpunit.xml index d703241..19a1428 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,6 +11,9 @@ tests/Feature + + tests/Arch + diff --git a/resources/js/interaction.js b/resources/js/interaction.js index fc61c61..6d5d632 100644 --- a/resources/js/interaction.js +++ b/resources/js/interaction.js @@ -66,5 +66,22 @@ function updateLikeCount(badge, change){ } } +function redirect(url, id){ + window.open(url, '_blank'); + let redirectBadge = document.getElementById("redirectBadge".concat(id)); + updateRedirectCount(redirectBadge, 1); + // increment the count in ui +} +function updateRedirectCount(badge, change){ + try{ + let likeCount = Math.max(parseInt( badge.dataset.count) + change, 0) + badge.querySelector('p').innerText = likeCount; + badge.dataset.count = likeCount.toString(); + } + catch(e) { + console.error(e); + } +} document.like = like; document.favorite = favorite; +document.redirect = redirect; diff --git a/resources/views/components/dashboard/user/action-toolbar.blade.php b/resources/views/components/dashboard/user/action-toolbar.blade.php index b245995..5324808 100644 --- a/resources/views/components/dashboard/user/action-toolbar.blade.php +++ b/resources/views/components/dashboard/user/action-toolbar.blade.php @@ -1,15 +1,5 @@ -@props(['deal_id', 'deal_title', 'like' => false, 'favourite' => false, 'deal_link' => '']) +@props(['deal_id', 'deal_title', 'like' => false, 'favourite' => false])
- @if(filled($deal_link)) - - - - @endif - $like]) onclick="like(this, {{$deal_id}})"> {{$deal->category->name}} - @ds($deal) - +

{{$deal->title}}

@@ -21,14 +20,16 @@ - + - -

View Deal

- -
+ @if(filled($deal->link)) + +

View Deal

+ +
+ @endif diff --git a/resources/views/components/ui/button.blade.php b/resources/views/components/ui/button.blade.php index bd5d342..2becb60 100644 --- a/resources/views/components/ui/button.blade.php +++ b/resources/views/components/ui/button.blade.php @@ -1,4 +1,4 @@ -@props(['variant' => '', 'icon' => '', 'link' => '']) +@props(['variant' => '', 'icon' => '', 'link' => '', 'external' => false]) @php $variants = [ 'neutral' => 'bg-primary-600 text-white', @@ -9,7 +9,11 @@ $variantClass = $variants[$variant] ?? ''; @endphp @if($link !== '') - merge(['class' => "block px-4 py-2 rounded-lg font-medium hover:opacity-80 active:scale-80 transition-all ease-in-out duration-300 $variantClass", 'href' => $link])}}> + merge(['class' => "block px-4 py-2 rounded-lg font-medium hover:opacity-80 active:scale-80 transition-all ease-in-out duration-300 $variantClass", 'href' => $link])}}>
@if($icon !=='') @svg("heroicon-o-$icon", 'w-5 h-5') diff --git a/tests/Arch/ArchTest.php b/tests/Arch/ArchTest.php new file mode 100644 index 0000000..916a6ea --- /dev/null +++ b/tests/Arch/ArchTest.php @@ -0,0 +1,5 @@ +expect(['ds', 'dsd', 'dsq', 'dd', 'ddd', 'dump', 'ray', 'die', 'var_dump', 'sleep', 'exit']) + ->not->toBeUsed();