Refactor and fix requests

This commit is contained in:
Phan An 2018-08-30 10:11:47 +07:00
parent 86cd0fbb4f
commit 453fb76c5d
25 changed files with 59 additions and 317 deletions

View file

@ -7,22 +7,7 @@ namespace App\Http\Requests\API;
*/
class BatchInteractionRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'songs' => 'required|array',

View file

@ -6,18 +6,8 @@ use App\Http\Requests\API\Request as BaseRequest;
class Request extends BaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
public function authorize(): bool
{
return config('koel.download.allow');
}
public function rules()
{
return [];
}
}

View file

@ -7,12 +7,7 @@ namespace App\Http\Requests\API\Download;
*/
class SongRequest extends Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'songs' => 'required|array',

View file

@ -0,0 +1,9 @@
<?php
namespace App\Http\Requests\API\Interaction;
use App\Http\Requests\API\Request as BaseRequest;
class Request extends BaseRequest
{
}

View file

@ -2,29 +2,14 @@
namespace App\Http\Requests\API\Interaction;
use Illuminate\Foundation\Http\FormRequest;
use App\Http\Requests\API\Request;
/**
* @property string song
*/
class StorePlayCountRequest extends FormRequest
class StorePlayCountRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'song' => 'required',

View file

@ -2,29 +2,12 @@
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/**
* @property string token
*/
class LastfmCallbackRequest extends FormRequest
class LastfmCallbackRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'token' => 'required',

View file

@ -2,29 +2,12 @@
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/**
* @property string key
*/
class LastfmSetSessionKeyRequest extends FormRequest
class LastfmSetSessionKeyRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'key' => 'required',

View file

@ -6,17 +6,7 @@ use App\Http\Requests\API\Request as BaseRequest;
class Request extends BaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
public function rules()
public function rules(): array
{
return [
'bucket' => 'required',

View file

@ -11,7 +11,7 @@ use App\Http\Requests\API\ObjectStorage\S3\Request as BaseRequest;
*/
class PutSongRequest extends BaseRequest
{
public function rules()
public function rules(): array
{
return [
'bucket' => 'required',

View file

@ -10,7 +10,7 @@ use App\Http\Requests\API\ObjectStorage\S3\Request as BaseRequest;
*/
class RemoveSongRequest extends BaseRequest
{
public function rules()
public function rules(): array
{
return [
'bucket' => 'required',

View file

@ -7,22 +7,7 @@ namespace App\Http\Requests\API;
*/
class PlaylistStoreRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'name' => 'required',

View file

@ -2,29 +2,12 @@
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/**
* @property string songs
*/
class PlaylistSyncRequest extends FormRequest
class PlaylistSyncRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'songs' => 'required',

View file

@ -7,22 +7,7 @@ namespace App\Http\Requests\API;
*/
class ProfileUpdateRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'name' => 'required',

View file

@ -2,9 +2,8 @@
namespace App\Http\Requests\API;
use App\Http\Requests\Request as BaseRequest;
use App\Http\Requests\AbstractRequest;
class Request extends BaseRequest
class Request extends AbstractRequest
{
//
}

View file

@ -7,22 +7,12 @@ namespace App\Http\Requests\API;
*/
class SettingRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
public function authorize(): bool
{
return auth()->user()->is_admin;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'media_path' => 'string|required|path.valid',

View file

@ -9,25 +9,4 @@ use App\Models\Song;
*/
class SongLikeRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
];
}
}

View file

@ -2,31 +2,9 @@
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/**
* @property float time
*/
class SongPlayRequest extends FormRequest
class SongPlayRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
];
}
}

View file

@ -8,22 +8,12 @@ namespace App\Http\Requests\API;
*/
class SongUpdateRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
public function authorize(): bool
{
return $this->user()->is_admin;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'data' => 'required|array',

View file

@ -4,22 +4,7 @@ namespace App\Http\Requests\API;
class UserLoginRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'email' => 'required|email',

View file

@ -9,22 +9,12 @@ namespace App\Http\Requests\API;
*/
class UserStoreRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
public function authorize(): bool
{
return auth()->user()->is_admin;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'name' => 'required',

View file

@ -7,22 +7,12 @@ namespace App\Http\Requests\API;
*/
class UserUpdateRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
public function authorize(): bool
{
return auth()->user()->is_admin;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'name' => 'required',

View file

@ -2,29 +2,12 @@
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/**
* @property string q
*/
class ViewSongOnITunesRequest extends FormRequest
class ViewSongOnITunesRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'q' => 'required',

View file

@ -2,32 +2,9 @@
namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/**
* @property string pageToken
*/
class YouTubeSearchRequest extends FormRequest
class YouTubeSearchRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
];
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
abstract class AbstractRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [];
}
}

View file

@ -1,10 +0,0 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
abstract class Request extends FormRequest
{
//
}