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 class BatchInteractionRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'songs' => 'required|array', 'songs' => 'required|array',

View file

@ -6,18 +6,8 @@ use App\Http\Requests\API\Request as BaseRequest;
class Request extends BaseRequest class Request extends BaseRequest
{ {
/** public function authorize(): bool
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{ {
return config('koel.download.allow'); 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 class SongRequest extends Request
{ {
/** public function rules(): array
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{ {
return [ return [
'songs' => 'required|array', '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; namespace App\Http\Requests\API\Interaction;
use Illuminate\Foundation\Http\FormRequest; use App\Http\Requests\API\Request;
/** /**
* @property string song * @property string song
*/ */
class StorePlayCountRequest extends FormRequest class StorePlayCountRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'song' => 'required', 'song' => 'required',

View file

@ -2,29 +2,12 @@
namespace App\Http\Requests\API; namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/** /**
* @property string token * @property string token
*/ */
class LastfmCallbackRequest extends FormRequest class LastfmCallbackRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'token' => 'required', 'token' => 'required',

View file

@ -2,29 +2,12 @@
namespace App\Http\Requests\API; namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/** /**
* @property string key * @property string key
*/ */
class LastfmSetSessionKeyRequest extends FormRequest class LastfmSetSessionKeyRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'key' => 'required', 'key' => 'required',

View file

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

View file

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

View file

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

View file

@ -7,22 +7,7 @@ namespace App\Http\Requests\API;
*/ */
class PlaylistStoreRequest extends Request class PlaylistStoreRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'name' => 'required', 'name' => 'required',

View file

@ -2,29 +2,12 @@
namespace App\Http\Requests\API; namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/** /**
* @property string songs * @property string songs
*/ */
class PlaylistSyncRequest extends FormRequest class PlaylistSyncRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'songs' => 'required', 'songs' => 'required',

View file

@ -7,22 +7,7 @@ namespace App\Http\Requests\API;
*/ */
class ProfileUpdateRequest extends Request class ProfileUpdateRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'name' => 'required', 'name' => 'required',

View file

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

View file

@ -9,25 +9,4 @@ use App\Models\Song;
*/ */
class SongLikeRequest extends Request 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; namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/** /**
* @property float time * @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 class SongUpdateRequest extends Request
{ {
/** public function authorize(): bool
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{ {
return $this->user()->is_admin; return $this->user()->is_admin;
} }
/** public function rules(): array
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{ {
return [ return [
'data' => 'required|array', 'data' => 'required|array',

View file

@ -4,22 +4,7 @@ namespace App\Http\Requests\API;
class UserLoginRequest extends Request class UserLoginRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'email' => 'required|email', 'email' => 'required|email',

View file

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

View file

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

View file

@ -2,29 +2,12 @@
namespace App\Http\Requests\API; namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/** /**
* @property string q * @property string q
*/ */
class ViewSongOnITunesRequest extends FormRequest class ViewSongOnITunesRequest extends Request
{ {
/** public function rules(): array
* 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 [ return [
'q' => 'required', 'q' => 'required',

View file

@ -2,32 +2,9 @@
namespace App\Http\Requests\API; namespace App\Http\Requests\API;
use Illuminate\Foundation\Http\FormRequest;
/** /**
* @property string pageToken * @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
{
//
}