first commit

This commit is contained in:
Ümit Tunç
2025-01-17 21:38:08 +03:00
commit f6ef9fafdc
105 changed files with 17540 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Jobs\FetchCurrencyRates;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* These should be classes that implement the ShouldQueue interface.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->job(new FetchCurrencyRates())->hourly();
}
/**
* Register the commands for your application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers;
use App\Jobs\FetchCurrencyRates;
use Illuminate\Support\Facades\Storage;
class CurrencyController extends Controller
{
public function getCurrentRates()
{
// Job'ı çalıştır
// $data = FetchCurrencyRates::dispatchSync();
// JSON dosyasından oku
if (Storage::exists('currency/today.json')) {
return response()->json(
json_decode(Storage::get('currency/today.json'), true)
);
}
return response()->json(['error' => 'Veri bulunamadı'], 404);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* @var array
*/
protected $middleware = [
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\EnsurePasswordIsConfirmed::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'api' => \App\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
];
/**
* The application's middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
// Web middleware'leri
],
'api' => [
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
}
?>
+78
View File
@@ -0,0 +1,78 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
class FetchCurrencyRates implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
$data = [];
$data['Update_Date'] = now()->format('Y-m-d H:i:s');
// Döviz kurları
$response = Http::withHeaders([
'User-Agent' => 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10',
'Accept-Language' => 'en'
])->get('https://kur.doviz.com');
// DOM işlemleri için veri çekme
$dom = new \DOMDocument();
@$dom->loadHTML($response->body());
$xpath = new \DOMXPath($dom);
// Döviz kurlarını çekme
$elements = $xpath->query("//*[@data-socket-key]");
foreach ($elements as $element) {
$name = $element->getAttribute('data-socket-key');
$type = $element->getAttribute('data-socket-attr');
$value = $this->virgulToNokta(trim($element->nodeValue));
if (trim($name) !== '') {
if ($name == "JPY") $value = $value / 100;
if ($type == "bid") $data[$name]['Buying'] = $value;
if ($type == "ask") $data[$name]['Selling'] = $value;
if ($type == "c") $data[$name]['Change'] = $value;
$data[$name]['Type'] = "Currency";
}
}
// AZN kuru için
$aznResponse = Http::get('https://wise.com/tr/currency-converter/azn-to-try-rate?amount=1');
preg_match('/(\d+\.\d+)\s+TRY/', $aznResponse->body(), $matches);
if (isset($matches[1])) {
$data['AZN'] = [
'Buying' => $matches[1],
'Selling' => $matches[1],
'Change' => "0.00",
'Type' => "Currency"
];
}
// Altın kurları
$goldResponse = Http::get('https://altin.doviz.com');
// ... Altın kurları için benzer DOM işlemleri ...
// JSON dosyasını kaydet
Storage::put('currency/today.json', json_encode($data, JSON_UNESCAPED_UNICODE));
return $data;
}
private function virgulToNokta($text)
{
$text = str_replace(".", "", $text);
$text = str_replace(",", ".", $text);
$text = str_replace("%", "", $text);
return $text;
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to your application's "home" route.
*
* Typically, users are redirected here after authentication.
*
* @var string
*/
public const HOME = '/home';
/**
* Define your route model bindings, pattern filters, and other route configuration.
*/
public function boot(): void
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
$this->routes(function () {
Route::middleware('api')
->prefix('api')
->group(base_path('routes/api.php'));
Route::middleware('web')
->group(base_path('routes/web.php'));
});
}
}