api code global jain
This commit is contained in:
77
app/Http/Requests/Api/Vihar/DeleteViharRequest.php
Normal file
77
app/Http/Requests/Api/Vihar/DeleteViharRequest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api\Vihar;
|
||||
|
||||
use App\Rules\DeleteVihar;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class DeleteViharRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function getValidatorInstance()
|
||||
{
|
||||
$this->request->set('delete', 1);
|
||||
|
||||
return parent::getValidatorInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$array = [
|
||||
'delete' => 'sometimes',
|
||||
];
|
||||
|
||||
$startDate = Carbon::createFromFormat('Y-m-d H:i:s', $this->vihar->start_date .' '. '00:00:00');
|
||||
$todayDate = Carbon::createFromFormat('Y-m-d H:i:s', Carbon::now()->format('Y-m-d') .' '. '00:00:00');
|
||||
$result = $todayDate->eq($startDate);
|
||||
|
||||
if ($result) {
|
||||
$array['delete'] = [new DeleteVihar($this->vihar)];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
if (Request::wantsJson()) {
|
||||
throw new HttpResponseException(response()->json(['message' => $validator->errors()->first(), 'error' => true, 'status' => 422], 422));
|
||||
} else {
|
||||
throw new ValidationException($validator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'start_time.after' => 'Please enter a time after the current time.',
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/Http/Requests/Api/Vihar/GetViharRequest.php
Normal file
33
app/Http/Requests/Api/Vihar/GetViharRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api\Vihar;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GetViharRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* 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 [
|
||||
'page' => 'integer',
|
||||
'limit' => 'integer',
|
||||
'sant_id' => 'required|exists:sants,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
98
app/Http/Requests/Api/Vihar/StoreViharRequest.php
Normal file
98
app/Http/Requests/Api/Vihar/StoreViharRequest.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api\Vihar;
|
||||
|
||||
use App\Rules\ViharCanNotAfterTwoHours;
|
||||
use Carbon\Carbon;
|
||||
use App\Rules\ViharDoesNotStoreForSameDateTime;
|
||||
use App\Rules\ViharStorePerDay;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class StoreViharRequest extends FormRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Indicates if the validator should stop on the first rule failure.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $stopOnFirstFailure = true;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function getValidatorInstance()
|
||||
{
|
||||
$this->request->set('per_day', 2);
|
||||
$this->request->set('date_time', 1);
|
||||
$this->request->set('next_vihar', 1);
|
||||
|
||||
return parent::getValidatorInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(Request $request)
|
||||
{
|
||||
$array = [
|
||||
'sant_id' => 'exists:sants,id',
|
||||
'from' => 'required',
|
||||
'to' => 'required',
|
||||
'start_date' => 'required|date_format:Y-m-d',
|
||||
'start_time' => 'date_format:H:i',
|
||||
// 'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date',
|
||||
'per_day' => [new ViharStorePerDay($request->all())],
|
||||
'date_time' => [new ViharDoesNotStoreForSameDateTime($request->all())],
|
||||
'next_vihar' => [new ViharCanNotAfterTwoHours($request->all())],
|
||||
];
|
||||
|
||||
$startDate = Carbon::createFromFormat('Y-m-d H:i:s', $request->start_date .' '. '00:00:00');
|
||||
$todayDate = Carbon::createFromFormat('Y-m-d H:i:s', Carbon::now()->format('Y-m-d') .' '. '00:00:00');
|
||||
$result = $todayDate->eq($startDate);
|
||||
|
||||
if ($result) {
|
||||
$array['start_time'] = 'date_format:H:i|after:'.Carbon::now()->format('H:i');
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
if (Request::wantsJson()) {
|
||||
throw new HttpResponseException(response()->json(['message' => $validator->errors()->first(), 'error' => true, 'status' => 422], 422));
|
||||
} else {
|
||||
throw new ValidationException($validator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'start_time.after' => 'Please enter a time after the current time.',
|
||||
];
|
||||
}
|
||||
}
|
||||
92
app/Http/Requests/Api/Vihar/UpdateViharRequest.php
Normal file
92
app/Http/Requests/Api/Vihar/UpdateViharRequest.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api\Vihar;
|
||||
|
||||
use App\Rules\ViharCanNotAfterTwoHours;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Rules\ViharDoesNotStoreForSameDateTime;
|
||||
use App\Rules\ViharStorePerDay;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateViharRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function getValidatorInstance()
|
||||
{
|
||||
$this->request->set('per_day', 2);
|
||||
$this->request->set('date_time', 1);
|
||||
$this->request->set('next_vihar', 1);
|
||||
|
||||
return parent::getValidatorInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(Request $request)
|
||||
{
|
||||
$array = [
|
||||
'sant_id' => 'exists:sants,id',
|
||||
'from' => 'required',
|
||||
'to' => 'required',
|
||||
'start_date' => 'required|date_format:Y-m-d',
|
||||
'start_time' => 'required|date_format:H:i',
|
||||
// 'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date',
|
||||
// 'end_time' => 'date_format:H:i|after:start_time',
|
||||
// 'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date',
|
||||
'date_time' => [new ViharDoesNotStoreForSameDateTime($request->all(), $this->vihar->id)],
|
||||
'per_day' => [new ViharStorePerDay($request->all(), $this->vihar->id)],
|
||||
'next_vihar' => [new ViharCanNotAfterTwoHours($request->all(), $this->vihar->id)],
|
||||
];
|
||||
|
||||
$startDate = Carbon::createFromFormat('Y-m-d H:i:s', $request->start_date .' '. '00:00:00');
|
||||
$todayDate = Carbon::createFromFormat('Y-m-d H:i:s', Carbon::now()->format('Y-m-d') .' '. '00:00:00');
|
||||
$result = $todayDate->eq($startDate);
|
||||
|
||||
if ($result) {
|
||||
$array['start_time'] = 'date_format:H:i|after:'.Carbon::now()->format('H:i');
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
if (Request::wantsJson()) {
|
||||
throw new HttpResponseException(response()->json(['message' => $validator->errors()->first(), 'error' => true, 'status' => 422], 422));
|
||||
} else {
|
||||
throw new ValidationException($validator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'start_time.after' => 'Please enter a time after the current time.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user