Renamed filter attributes in time entry endpoints

This commit is contained in:
Constantin Graf
2024-05-21 17:42:32 +02:00
parent 2a8ab12017
commit 2e710795ec
6 changed files with 33 additions and 33 deletions

View File

@@ -29,7 +29,7 @@ class TestJobCommand extends Command
*/ */
public function handle(): int public function handle(): int
{ {
$user = User::first(); $user = User::firstOrFail();
TestJob::dispatch($user, 'Test job message.'); TestJob::dispatch($user, 'Test job message.');
return self::SUCCESS; return self::SUCCESS;

View File

@@ -61,8 +61,8 @@ class TimeEntryController extends Controller
->orderBy('start', 'desc'); ->orderBy('start', 'desc');
$filter = new TimeEntryFilter($timeEntriesQuery); $filter = new TimeEntryFilter($timeEntriesQuery);
$filter->addBeforeFilter($request->input('before')); $filter->addStartFilter($request->input('start'));
$filter->addAfterFilter($request->input('after')); $filter->addEndFilter($request->input('end'));
$filter->addActiveFilter($request->input('active')); $filter->addActiveFilter($request->input('active'));
$filter->addMemberIdFilter($member); $filter->addMemberIdFilter($member);
$filter->addMemberIdsFilter($request->input('member_ids')); $filter->addMemberIdsFilter($request->input('member_ids'));
@@ -159,8 +159,8 @@ class TimeEntryController extends Controller
->whereBelongsTo($organization, 'organization'); ->whereBelongsTo($organization, 'organization');
$filter = new TimeEntryFilter($timeEntriesQuery); $filter = new TimeEntryFilter($timeEntriesQuery);
$filter->addBeforeFilter($request->input('before')); $filter->addEndFilter($request->input('end'));
$filter->addAfterFilter($request->input('after')); $filter->addStartFilter($request->input('start'));
$filter->addActiveFilter($request->input('active')); $filter->addActiveFilter($request->input('active'));
$filter->addMemberIdFilter($member); $filter->addMemberIdFilter($member);
$filter->addMemberIdsFilter($request->input('member_ids')); $filter->addMemberIdsFilter($request->input('member_ids'));

View File

@@ -111,18 +111,18 @@ class TimeEntryAggregateRequest extends FormRequest
return $builder->whereBelongsTo($this->organization, 'organization'); 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) // 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', 'nullable',
'string', 'string',
'date_format:Y-m-d\TH:i:s\Z', 'date_format:Y-m-d\TH:i:s\Z',
'before:before',
], ],
// Filter by active status (active means has no end date, is still running) // Filter by active status (active means has no end date, is still running)
'active' => [ 'active' => [
@@ -158,11 +158,11 @@ class TimeEntryAggregateRequest extends FormRequest
public function getStart(): ?Carbon 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 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;
} }
} }

View File

@@ -88,18 +88,18 @@ class TimeEntryIndexRequest extends FormRequest
return $builder->whereBelongsTo($this->organization, 'organization'); 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) // 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', 'nullable',
'string', 'string',
'date_format:Y-m-d\TH:i:s\Z', 'date_format:Y-m-d\TH:i:s\Z',
'before:before',
], ],
// Filter by active status (active means has no end date, is still running) // Filter by active status (active means has no end date, is still running)
'active' => [ 'active' => [

View File

@@ -25,7 +25,7 @@ class TimeEntryFilter
$this->builder = $builder; $this->builder = $builder;
} }
public function addBeforeFilter(?string $dateTime): self public function addEndFilter(?string $dateTime): self
{ {
if ($dateTime === null) { if ($dateTime === null) {
return $this; return $this;
@@ -35,7 +35,7 @@ class TimeEntryFilter
return $this; return $this;
} }
public function addAfterFilter(?string $dateTime): self public function addStartFilter(?string $dateTime): self
{ {
if ($dateTime === null) { if ($dateTime === null) {
return $this; return $this;

View File

@@ -342,7 +342,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
// Act // Act
$response = $this->getJson(route('api.v1.time-entries.index', [ $response = $this->getJson(route('api.v1.time-entries.index', [
$data->organization->getKey(), $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(), 'member_id' => $data->member->getKey(),
])); ]));
@@ -380,7 +380,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
// Act // Act
$response = $this->getJson(route('api.v1.time-entries.index', [ $response = $this->getJson(route('api.v1.time-entries.index', [
$data->organization->getKey(), $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(), 'member_id' => $data->member->getKey(),
])); ]));
@@ -427,8 +427,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
'project_ids' => [$project->getKey()], 'project_ids' => [$project->getKey()],
'task_ids' => [$task->getKey()], 'task_ids' => [$task->getKey()],
'tag_ids' => [$tag->getKey()], 'tag_ids' => [$tag->getKey()],
'before' => Carbon::now()->toIso8601ZuluString(), 'start' => Carbon::now()->subDay()->toIso8601ZuluString(),
'after' => Carbon::now()->subDay()->toIso8601ZuluString(), 'end' => Carbon::now()->toIso8601ZuluString(),
'active' => 'true', 'active' => 'true',
'only_full_dates' => 'true', 'only_full_dates' => 'true',
'limit' => 1, 'limit' => 1,
@@ -558,8 +558,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
'group' => 'project', 'group' => 'project',
'sub_group' => 'day', 'sub_group' => 'day',
'fill_gaps_in_time_groups' => 'true', 'fill_gaps_in_time_groups' => 'true',
'after' => $day2->copy()->subSecond()->toIso8601ZuluString(), 'start' => $day2->copy()->subSecond()->toIso8601ZuluString(),
'before' => $day1->copy()->addSecond()->toIso8601ZuluString(), 'end' => $day1->copy()->addSecond()->toIso8601ZuluString(),
])); ]));
// Assert // Assert
@@ -699,8 +699,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
$data->organization->getKey(), $data->organization->getKey(),
'group' => 'week', 'group' => 'week',
'fill_gaps_in_time_groups' => 'true', 'fill_gaps_in_time_groups' => 'true',
'after' => $earlierWeekStart->toIso8601ZuluString(), 'start' => $earlierWeekStart->toIso8601ZuluString(),
'before' => $laterWeekEnd->toIso8601ZuluString(), 'end' => $laterWeekEnd->toIso8601ZuluString(),
])); ]));
// Assert // Assert