diff --git a/app/Console/Commands/Test/TestJobCommand.php b/app/Console/Commands/Test/TestJobCommand.php index b836d6c6..c4e3d1a9 100644 --- a/app/Console/Commands/Test/TestJobCommand.php +++ b/app/Console/Commands/Test/TestJobCommand.php @@ -29,7 +29,7 @@ class TestJobCommand extends Command */ public function handle(): int { - $user = User::first(); + $user = User::firstOrFail(); TestJob::dispatch($user, 'Test job message.'); return self::SUCCESS; diff --git a/app/Http/Controllers/Api/V1/TimeEntryController.php b/app/Http/Controllers/Api/V1/TimeEntryController.php index 946002e2..b42b7488 100644 --- a/app/Http/Controllers/Api/V1/TimeEntryController.php +++ b/app/Http/Controllers/Api/V1/TimeEntryController.php @@ -61,8 +61,8 @@ class TimeEntryController extends Controller ->orderBy('start', 'desc'); $filter = new TimeEntryFilter($timeEntriesQuery); - $filter->addBeforeFilter($request->input('before')); - $filter->addAfterFilter($request->input('after')); + $filter->addStartFilter($request->input('start')); + $filter->addEndFilter($request->input('end')); $filter->addActiveFilter($request->input('active')); $filter->addMemberIdFilter($member); $filter->addMemberIdsFilter($request->input('member_ids')); @@ -159,8 +159,8 @@ class TimeEntryController extends Controller ->whereBelongsTo($organization, 'organization'); $filter = new TimeEntryFilter($timeEntriesQuery); - $filter->addBeforeFilter($request->input('before')); - $filter->addAfterFilter($request->input('after')); + $filter->addEndFilter($request->input('end')); + $filter->addStartFilter($request->input('start')); $filter->addActiveFilter($request->input('active')); $filter->addMemberIdFilter($member); $filter->addMemberIdsFilter($request->input('member_ids')); diff --git a/app/Http/Requests/V1/TimeEntry/TimeEntryAggregateRequest.php b/app/Http/Requests/V1/TimeEntry/TimeEntryAggregateRequest.php index 6bae8f24..09b5e8f2 100644 --- a/app/Http/Requests/V1/TimeEntry/TimeEntryAggregateRequest.php +++ b/app/Http/Requests/V1/TimeEntry/TimeEntryAggregateRequest.php @@ -111,18 +111,18 @@ class TimeEntryAggregateRequest extends FormRequest return $builder->whereBelongsTo($this->organization, 'organization'); }), ], - // Filter only time entries that have a start date before the given timestamp in UTC (example: 2021-01-01T00:00:00Z) - 'before' => [ - 'nullable', - 'string', - 'date_format:Y-m-d\TH:i:s\Z', - ], // Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z) - 'after' => [ + 'start' => [ + 'nullable', + 'string', + 'date_format:Y-m-d\TH:i:s\Z', + 'before:end', + ], + // Filter only time entries that have a start date before the given timestamp in UTC (example: 2021-01-01T00:00:00Z) + 'end' => [ 'nullable', 'string', 'date_format:Y-m-d\TH:i:s\Z', - 'before:before', ], // Filter by active status (active means has no end date, is still running) 'active' => [ @@ -158,11 +158,11 @@ class TimeEntryAggregateRequest extends FormRequest public function getStart(): ?Carbon { - return $this->get('after') !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $this->get('after'), 'UTC') : null; + return $this->get('start') !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $this->get('start'), 'UTC') : null; } public function getEnd(): ?Carbon { - return $this->get('before') !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $this->get('before'), 'UTC') : null; + return $this->get('end') !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $this->get('end'), 'UTC') : null; } } diff --git a/app/Http/Requests/V1/TimeEntry/TimeEntryIndexRequest.php b/app/Http/Requests/V1/TimeEntry/TimeEntryIndexRequest.php index 26957f21..d7f4fae2 100644 --- a/app/Http/Requests/V1/TimeEntry/TimeEntryIndexRequest.php +++ b/app/Http/Requests/V1/TimeEntry/TimeEntryIndexRequest.php @@ -88,18 +88,18 @@ class TimeEntryIndexRequest extends FormRequest return $builder->whereBelongsTo($this->organization, 'organization'); }), ], - // Filter only time entries that have a start date before the given timestamp in UTC (example: 2021-01-01T00:00:00Z) - 'before' => [ - 'nullable', - 'string', - 'date_format:Y-m-d\TH:i:s\Z', - ], // Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z) - 'after' => [ + 'start' => [ + 'nullable', + 'string', + 'date_format:Y-m-d\TH:i:s\Z', + 'before:end', + ], + // Filter only time entries that have a start date before the given timestamp in UTC (example: 2021-01-01T00:00:00Z) + 'end' => [ 'nullable', 'string', 'date_format:Y-m-d\TH:i:s\Z', - 'before:before', ], // Filter by active status (active means has no end date, is still running) 'active' => [ diff --git a/app/Service/TimeEntryFilter.php b/app/Service/TimeEntryFilter.php index 1302b40c..7f35fe3a 100644 --- a/app/Service/TimeEntryFilter.php +++ b/app/Service/TimeEntryFilter.php @@ -25,7 +25,7 @@ class TimeEntryFilter $this->builder = $builder; } - public function addBeforeFilter(?string $dateTime): self + public function addEndFilter(?string $dateTime): self { if ($dateTime === null) { return $this; @@ -35,7 +35,7 @@ class TimeEntryFilter return $this; } - public function addAfterFilter(?string $dateTime): self + public function addStartFilter(?string $dateTime): self { if ($dateTime === null) { return $this; diff --git a/tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php b/tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php index 71d7af6d..fa4f8ef9 100644 --- a/tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php +++ b/tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php @@ -342,7 +342,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract // Act $response = $this->getJson(route('api.v1.time-entries.index', [ $data->organization->getKey(), - 'before' => Carbon::now()->timezone($data->user->timezone)->subDay()->startOfDay()->toIso8601ZuluString(), + 'end' => Carbon::now()->timezone($data->user->timezone)->subDay()->startOfDay()->toIso8601ZuluString(), 'member_id' => $data->member->getKey(), ])); @@ -380,7 +380,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract // Act $response = $this->getJson(route('api.v1.time-entries.index', [ $data->organization->getKey(), - 'after' => Carbon::now($data->user->timezone)->subDay()->endOfDay()->toIso8601ZuluString(), // yesterday + 'start' => Carbon::now($data->user->timezone)->subDay()->endOfDay()->toIso8601ZuluString(), // yesterday 'member_id' => $data->member->getKey(), ])); @@ -427,8 +427,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract 'project_ids' => [$project->getKey()], 'task_ids' => [$task->getKey()], 'tag_ids' => [$tag->getKey()], - 'before' => Carbon::now()->toIso8601ZuluString(), - 'after' => Carbon::now()->subDay()->toIso8601ZuluString(), + 'start' => Carbon::now()->subDay()->toIso8601ZuluString(), + 'end' => Carbon::now()->toIso8601ZuluString(), 'active' => 'true', 'only_full_dates' => 'true', 'limit' => 1, @@ -558,8 +558,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract 'group' => 'project', 'sub_group' => 'day', 'fill_gaps_in_time_groups' => 'true', - 'after' => $day2->copy()->subSecond()->toIso8601ZuluString(), - 'before' => $day1->copy()->addSecond()->toIso8601ZuluString(), + 'start' => $day2->copy()->subSecond()->toIso8601ZuluString(), + 'end' => $day1->copy()->addSecond()->toIso8601ZuluString(), ])); // Assert @@ -699,8 +699,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract $data->organization->getKey(), 'group' => 'week', 'fill_gaps_in_time_groups' => 'true', - 'after' => $earlierWeekStart->toIso8601ZuluString(), - 'before' => $laterWeekEnd->toIso8601ZuluString(), + 'start' => $earlierWeekStart->toIso8601ZuluString(), + 'end' => $laterWeekEnd->toIso8601ZuluString(), ])); // Assert