feat: Add LMI API integration for fetching sales data

- Integrate LMI API to fetch current sales data using the provided API key.
- Update SaleController to use Http facade for making API requests.
- Modify services configuration to include LMI API key.
This commit is contained in:
Rico van Zelst
2024-04-18 19:44:09 +02:00
parent 984690b758
commit 267a2e4b67
4 changed files with 64 additions and 60 deletions

View File

@@ -14,6 +14,8 @@ APP_MAINTENANCE_STORE=database
BCRYPT_ROUNDS=12
LMI_API_KEY=
APP_STAGING=false
OCTANE_SERVER=swoole

View File

@@ -3,19 +3,20 @@
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
class SaleController extends Controller
{
public function index()
{
$sales = Cache::remember('sales_data', 60 * 60 * 8, static function () {
$shopData = json_decode(
file_get_contents('https://rico-vz.github.io/shop-depr-temp/download.json'),
true
);
$salesData = array_filter($shopData, static fn ($collection) => $collection['path'] === '/event/sales');
$lmi_api_key = config('services.lmi.api_key');
return reset($salesData)['dynamicCollection']['discountedProductsByProductType'] ?? [];
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $lmi_api_key,
])->get('https://lmi.orianna.dev/api/lol-sales');
return $response->json();
});
return view('sales.index', ['sales' => $sales]);

View File

@@ -9,4 +9,8 @@ return [
'scheme' => 'https',
],
'lmi' => [
'api_key' => env('LMI_API_KEY'),
],
];

View File

@@ -4,24 +4,26 @@
@endphp
<section class="max-w-screen-xl mx-auto mt-12">
<h3 class="mt-8 mb-2 text-lg font-bold text-center text-transparent uppercase sm:text-xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">Sale Rotation is currently undergoing maintenance. This data is not up-to-date. Check back soon.</h3>
<h1
class="text-3xl font-bold text-center text-transparent uppercase sm:text-4xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">
Sale Rotation</h1>
<h2 class="text-lg font-bold text-center text-transparent uppercase sm:text-xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">All champions & skins on sale</h2>
<h2
class="text-lg font-bold text-center text-transparent uppercase sm:text-xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">
All champions & skins on sale</h2>
<h3 class="mt-8 mb-2 text-2xl font-bold text-center text-transparent uppercase sm:text-3xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">Champions on Sale</h3>
<h3
class="mt-8 mb-2 text-2xl font-bold text-center text-transparent uppercase sm:text-3xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">
Champions on Sale</h3>
<div class="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
@foreach($sales['CHAMPION'] as $sale)
@foreach ($sales['champion_sales'] as $sale)
@php
$champion = Champion::where('champion_id', $sale['id'])->first();
$originalPrice = $sale['prices'][0]['originalPrice']['cost'];
$discountedPrice = $sale['prices'][0]['discount']['discountedProductPrice']['cost'];
$discountPercentage = round((1 - ($discountedPrice / $originalPrice)) * 100);
$champion = Champion::where('champion_id', $sale['item_id'])->first();
$discountPercentage = $sale['percent_off'];
$discountedPrice = $sale['rp'];
@endphp
<a href="/champion/{{$champion->slug}}">
<a href="/champion/{{ $champion->slug }}">
<div
class="flex flex-col items-center text-gray-700 border shadow-md bg-stone-800/40 rounded-2xl bg-clip-border border-stone-800 hover:border-orange-500/10 hover:shadow-orange-500/10">
<div class="absolute px-3 py-1 mt-4 text-white rounded-full bg-black/60">
@@ -29,11 +31,8 @@
</div>
<div
class="w-auto mx-4 mt-3 overflow-hidden border-2 rounded-2xl bg-clip-border border-orange-400/40 aspect-video">
<img
src="//wsrv.nl/?url={{ $champion->getChampionImageAttribute() }}&w=450&output=webp&q=80&il&default=ssl:wsrv.nl%2F%3Furl%3Dhttps://i.ibb.co/5s6YyvN/aaaa.png"
class="aspect-video"
alt="{{ $champion->name }} Splash Art"
/>
<img src="//wsrv.nl/?url={{ $champion->getChampionImageAttribute() }}&w=450&output=webp&q=80&il&default=ssl:wsrv.nl%2F%3Furl%3Dhttps://i.ibb.co/5s6YyvN/aaaa.png"
class="aspect-video" alt="{{ $champion->name }} Splash Art" />
</div>
<div class="px-4 py-2">
@@ -50,15 +49,16 @@
</div>
<h3 class="mt-8 text-2xl font-bold text-center text-transparent uppercase sm:text-3xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">Skins on Sale</h3>
<h3
class="mt-8 text-2xl font-bold text-center text-transparent uppercase sm:text-3xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">
Skins on Sale</h3>
<div class="container flex flex-col items-center justify-center p-4 mx-auto text-white">
<div class="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
@foreach($sales['CHAMPION_SKIN'] as $sale)
@foreach ($sales['skin_sales'] as $sale)
@php
$skin = ChampionSkin::where('full_skin_id', $sale['id'])->first();
$originalPrice = $sale['prices'][0]['originalPrice']['cost'];
$discountedPrice = $sale['prices'][0]['discount']['discountedProductPrice']['cost'];
$discountPercentage = round((1 - ($discountedPrice / $originalPrice)) * 100);
$skin = ChampionSkin::where('full_skin_id', $sale['item_id'])->first();
$discountPercentage = $sale['percent_off'];
$discountedPrice = $sale['rp'];
@endphp
<a href="/skin/{{ $skin->slug }}">
<div
@@ -68,11 +68,8 @@
</div>
<div
class="w-auto mx-4 mt-3 overflow-hidden border-2 rounded-2xl bg-clip-border border-orange-400/40 aspect-video">
<img
src="//wsrv.nl/?url={{ $skin->getSkinImageAttribute() }}&w=450&output=webp&q=80&il&default=ssl:wsrv.nl%2F%3Furl%3Dhttps://i.ibb.co/5s6YyvN/aaaa.png"
class="aspect-video"
alt="{{ $skin->skin_name }} Splash Art"
/>
<img src="//wsrv.nl/?url={{ $skin->getSkinImageAttribute() }}&w=450&output=webp&q=80&il&default=ssl:wsrv.nl%2F%3Furl%3Dhttps://i.ibb.co/5s6YyvN/aaaa.png"
class="aspect-video" alt="{{ $skin->skin_name }} Splash Art" />
</div>
<div class="px-4 py-2">