2021-11-05 09:04:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Api\V2;
|
|
|
|
|
|
|
|
|
|
use App\Http\Requests\Api\V2\BaseApiRequest;
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
|
|
2023-09-06 17:24:53 +02:00
|
|
|
/**
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
2021-11-05 09:04:24 +01:00
|
|
|
class GetBrandStatsRequest extends BaseApiRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
2023-06-22 17:25:52 +02:00
|
|
|
* @throws \Illuminate\Validation\ValidationException If given dates are unparsable of
|
|
|
|
|
* period is bigger than 3 months.
|
2021-12-19 15:57:24 +01:00
|
|
|
* @throws \Exception If carbon date processing failed.
|
2021-11-05 09:04:24 +01:00
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-04-23 10:10:37 +02:00
|
|
|
if (Carbon::parse($this->end)->floatDiffInMonths(Carbon::parse($this->start), true) > 3) {
|
2021-11-05 09:04:24 +01:00
|
|
|
throw ValidationException::withMessages([
|
|
|
|
|
'Vous devez sélectionner une période de maximum 3 mois'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2021-12-19 15:57:24 +01:00
|
|
|
} catch (\Exception $e) {
|
2021-11-05 09:04:24 +01:00
|
|
|
if (\get_class($e) !== ValidationException::class) {
|
|
|
|
|
throw ValidationException::withMessages([
|
|
|
|
|
'Les dates séléectionnées ne sembles pas être valides'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
return [
|
2025-04-17 11:32:43 +02:00
|
|
|
'start' => 'required|date|date_format:Y-m-d|before_or_equal:end',
|
2023-09-04 13:08:34 +02:00
|
|
|
'end' => 'required|date|date_format:Y-m-d|after_or_equal:start',
|
2021-11-05 09:04:24 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|