Proje dosyaları eklendi
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
namespace App\Http\Requests;use Illuminate\Validation\Rule;
|
||||
class LosersReportRequest extends VisibilityReportRequest{public function rules():array{return parent::rules()+['loss_type'=>['nullable',Rule::in(['top3','top10','top100','dropped_out'])],'min_lost'=>['nullable','integer','min:1','max:100'],'min_visibility_loss'=>['nullable','numeric','min:0','max:100'],'rank_range'=>['nullable',Rule::in(['top3','top10','top20','top100','unranked'])]];}}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\Http\Requests;
|
||||
use App\Enums\{KeywordDevice,SearchEngine};use App\Support\KeywordTargetOptions;use Illuminate\Foundation\Http\FormRequest;use Illuminate\Validation\Rule;
|
||||
class RankingHistoryRequest extends FormRequest{
|
||||
public function authorize():bool{return $this->user()!==null;}
|
||||
protected function prepareForValidation():void{$range=$this->input('range','30d');$now=now();[$from,$to]=match($range){'7d'=>[$now->copy()->subDays(6)->startOfDay(),$now->copy()->endOfDay()],'90d'=>[$now->copy()->subDays(89)->startOfDay(),$now->copy()->endOfDay()],'this_month'=>[$now->copy()->startOfMonth(),$now->copy()->endOfDay()],'last_month'=>[$now->copy()->subMonthNoOverflow()->startOfMonth(),$now->copy()->subMonthNoOverflow()->endOfMonth()],'custom'=>[$this->input('from'),$this->input('to')],default=>[$now->copy()->subDays(29)->startOfDay(),$now->copy()->endOfDay()]};if($range!=='custom')$this->merge(['range'=>in_array($range,['7d','30d','90d','this_month','last_month'],true)?$range:'30d','from'=>$from->toDateString(),'to'=>$to->toDateString()]);}
|
||||
public function rules():array{return ['range'=>['required',Rule::in(['7d','30d','90d','this_month','last_month','custom'])],'from'=>['required','date','before_or_equal:to','before_or_equal:today','after_or_equal:'.now()->subYears(2)->toDateString()],'to'=>['required','date','after_or_equal:from','before_or_equal:today'],'project'=>['nullable','string'],'keywords'=>['nullable','array','max:10'],'keywords.*'=>['string'],'engine'=>['nullable',Rule::enum(SearchEngine::class)],'country'=>['nullable',Rule::in(array_keys(KeywordTargetOptions::countries()))],'language'=>['nullable',Rule::in(array_keys(KeywordTargetOptions::languages()))],'device'=>['nullable',Rule::enum(KeywordDevice::class)],'movement'=>['nullable',Rule::in(['winner','loser','unchanged','new','unranked'])]];}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
namespace App\Http\Requests;use App\Services\ProjectUrlNormalizer;use Illuminate\Foundation\Http\FormRequest;use Illuminate\Validation\ValidationException;
|
||||
class StoreCompetitorRequest extends FormRequest{public function authorize():bool{return$this->user()!==null;}protected function prepareForValidation():void{try{$n=app(ProjectUrlNormalizer::class)->normalize((string)$this->input('domain'));$this->merge(['normalized_domain'=>$n->domain,'domain'=>$n->domain,'name'=>trim((string)$this->input('name'))?:$n->domain]);}catch(\InvalidArgumentException$e){throw ValidationException::withMessages(['domain'=>__('competitors.invalid_domain')]);}}public function rules():array{return['name'=>['required','string','max:150'],'domain'=>['required','string','max:253'],'normalized_domain'=>['required','string','max:253']];}}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class StoreEarnTaskResultsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Token ve cihaz yetkilendirmesi middleware'de tamamlandığı için isteğin doğrulanmasına izin verir.
|
||||
*
|
||||
* @author Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Görev sonucu listesinin tür, boyut ve HTTP durum alanlarını katı biçimde doğrular.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*
|
||||
* @author Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'tasks' => ['required', 'array', 'min:1', 'max:50'],
|
||||
'tasks.*.CID' => ['required', 'integer', 'min:1'],
|
||||
'tasks.*.task_id' => ['required', 'string', 'max:64'],
|
||||
'tasks.*.completed' => ['required'],
|
||||
'tasks.*.responseCode' => ['nullable', 'integer', 'between:100,599'],
|
||||
'tasks.*.error' => ['nullable', 'string', 'max:'.config('earn.api.task_result_max_error_length')],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean ve başarı alanlarının sessiz tür dönüşümü olmadan tutarlı olmasını denetler.
|
||||
*
|
||||
* @return array<int, callable(Validator): void>
|
||||
*
|
||||
* @author Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
|
||||
*/
|
||||
public function after(): array
|
||||
{
|
||||
// Tür dönüşümü yapmadan kayıtlar arası tutarlılığı denetler.
|
||||
// Yazar: Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
|
||||
return [function (Validator $validator): void {
|
||||
foreach ((array) $this->input('tasks', []) as $index => $task) {
|
||||
if (! is_int($task['CID'] ?? null)) {
|
||||
$validator->errors()->add("tasks.$index.CID", 'The CID field must be a JSON integer.');
|
||||
}
|
||||
if (array_key_exists('responseCode', $task) && $task['responseCode'] !== null && ! is_int($task['responseCode'])) {
|
||||
$validator->errors()->add("tasks.$index.responseCode", 'The responseCode field must be a JSON integer or null.');
|
||||
}
|
||||
if (! is_bool($task['completed'] ?? null)) {
|
||||
$validator->errors()->add("tasks.$index.completed", 'The completed field must be a JSON boolean.');
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($task['completed'] === true && (($task['error'] ?? null) !== null
|
||||
|| ! isset($task['responseCode']) || $task['responseCode'] < 200 || $task['responseCode'] > 399)) {
|
||||
$validator->errors()->add("tasks.$index.completed", 'A completed task requires a 2xx/3xx response and no error.');
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
namespace App\Http\Requests;
|
||||
use App\Enums\{KeywordDevice,SearchEngine};use App\Models\{Keyword,Project};use App\Support\KeywordTargetOptions;use Illuminate\Foundation\Http\FormRequest;use Illuminate\Validation\{Rule,Validator};
|
||||
class StoreKeywordRequest extends FormRequest{protected function prepareForValidation():void{if(!$this->has('phrases')&&$this->has('phrase'))$this->merge(['phrases'=>$this->input('phrase')]);}public function project():?Project{return $this->route('customerProject')?:$this->user()?->projects()->active()->where('ulid',$this->input('project'))->first();}public function authorize():bool{$p=$this->project();return $p&&($this->user()?->can('create',[Keyword::class,$p])??false);}public function rules():array{$legacy=$this->has('phrase');return ['project'=>['nullable','string'],'phrases'=>$legacy?['nullable','string']:['required','string','max:20000'],'phrase'=>$legacy?['required','string','max:190']:['nullable'],'search_engine'=>['required',Rule::enum(SearchEngine::class)],'country_code'=>['required',Rule::in(array_keys(KeywordTargetOptions::countries()))],'language_code'=>['required',Rule::in(array_keys(KeywordTargetOptions::languages()))],'device'=>['required',Rule::enum(KeywordDevice::class)]];}public function withValidator(Validator $v):void{$v->after(function(Validator $v){if(!$this->project())$v->errors()->add('project',__('keywords.validation.project'));if($this->filled(['country_code','language_code'])&&!KeywordTargetOptions::supports($this->input('country_code'),$this->input('language_code')))$v->errors()->add('language_code',__('keywords.validation.target_pair'));$lines=preg_split('/\R/u',(string)$this->input('phrases'))?:[];if(count(array_filter($lines,fn($x)=>trim($x)!==''))>100)$v->errors()->add($this->has('phrase')?'phrase':'phrases',__('keywords.validation.limit',['count'=>100]));});}}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Services\ProjectUrlNormalizer;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class StoreProjectRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return $this->user()?->can('create', Project::class) ?? false; }
|
||||
public function rules(): array { return ['name' => ['required', 'string', 'max:150'], 'website_url' => ['required', 'string', 'max:2048']]; }
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
if ($validator->errors()->has('website_url')) return;
|
||||
try {
|
||||
$normalized = app(ProjectUrlNormalizer::class)->normalize((string) $this->input('website_url'));
|
||||
if ($this->user()->projects()->where('domain', $normalized->domain)->exists()) {
|
||||
$validator->errors()->add('website_url', 'Bu alan adı hesabınızda zaten kayıtlı.');
|
||||
}
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
$validator->errors()->add('website_url', $exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
namespace App\Http\Requests;
|
||||
use App\Enums\{KeywordDevice,KeywordStatus};use App\Models\Keyword;use App\Support\KeywordTargetOptions;use Illuminate\Foundation\Http\FormRequest;use Illuminate\Validation\{Rule,Validator};
|
||||
class UpdateKeywordRequest extends FormRequest{public function keyword():?Keyword{return $this->route('customerKeyword')?:$this->route('keyword');}public function authorize():bool{$k=$this->keyword();return $k&&$k->archived_at===null&&$k->status!==KeywordStatus::Archived&&($this->user()?->can('update',$k)??false);}public function rules():array{return ['phrase'=>['required','string','max:190'],'country_code'=>['required',Rule::in(array_keys(KeywordTargetOptions::countries()))],'language_code'=>['required',Rule::in(array_keys(KeywordTargetOptions::languages()))],'device'=>['required',Rule::enum(KeywordDevice::class)],'status'=>['required',Rule::in([KeywordStatus::Active->value,KeywordStatus::Inactive->value])]];}public function withValidator(Validator $v):void{$v->after(function(Validator $v){if($this->filled(['country_code','language_code'])&&!KeywordTargetOptions::supports($this->input('country_code'),$this->input('language_code')))$v->errors()->add('language_code',__('keywords.validation.target_pair'));});}}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Services\ProjectUrlNormalizer;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class UpdateProjectRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
$project = $this->route('customerProject');
|
||||
return $project instanceof Project && ($this->user()?->can('update', $project) ?? false);
|
||||
}
|
||||
public function rules(): array { return ['name' => ['required', 'string', 'max:150'], 'website_url' => ['required', 'string', 'max:2048']]; }
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
if ($validator->errors()->has('website_url')) return;
|
||||
try {
|
||||
$project = $this->route('customerProject');
|
||||
$normalized = app(ProjectUrlNormalizer::class)->normalize((string) $this->input('website_url'));
|
||||
if ($this->user()->projects()->where('domain', $normalized->domain)->whereKeyNot($project->id)->exists()) {
|
||||
$validator->errors()->add('website_url', 'Bu alan adı hesabınızda zaten kayıtlı.');
|
||||
}
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
$validator->errors()->add('website_url', $exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
namespace App\Http\Requests;use App\Enums\{KeywordDevice,SearchEngine};use App\Support\KeywordTargetOptions;use Illuminate\Foundation\Http\FormRequest;use Illuminate\Validation\Rule;
|
||||
class VisibilityReportRequest extends FormRequest{public function authorize():bool{return$this->user()!==null;}protected function prepareForValidation():void{$range=$this->input('range','30d');$now=now();[$from,$to]=match($range){'7d'=>[$now->copy()->subDays(6),$now],'90d'=>[$now->copy()->subDays(89),$now],'this_month'=>[$now->copy()->startOfMonth(),$now],'last_month'=>[$now->copy()->subMonthNoOverflow()->startOfMonth(),$now->copy()->subMonthNoOverflow()->endOfMonth()],'custom'=>[$this->input('from'),$this->input('to')],default=>[$now->copy()->subDays(29),$now]};if($range!=='custom')$this->merge(['range'=>in_array($range,['7d','30d','90d','this_month','last_month'],true)?$range:'30d','from'=>$from->toDateString(),'to'=>$to->toDateString()]);}public function rules():array{return['range'=>['required',Rule::in(['7d','30d','90d','this_month','last_month','custom'])],'from'=>['required','date','before_or_equal:to','before_or_equal:today','after_or_equal:'.now()->subYears(2)->toDateString()],'to'=>['required','date','after_or_equal:from','before_or_equal:today'],'compare'=>['nullable',Rule::in(['previous','none'])],'project'=>['nullable','string'],'country'=>['nullable',Rule::in(array_keys(KeywordTargetOptions::countries()))],'language'=>['nullable',Rule::in(array_keys(KeywordTargetOptions::languages()))],'device'=>['nullable',Rule::enum(KeywordDevice::class)],'engine'=>['nullable',Rule::enum(SearchEngine::class)],'q'=>['nullable','string','max:190'],'min_gained'=>['nullable','integer','min:1','max:100'],'sort'=>['nullable',Rule::in(['current','gained','contribution','lost','visibility_loss','checked_at'])]];}}
|
||||
Reference in New Issue
Block a user