Skip to content

Commit 66dfc51

Browse files
committed
add no project, no task, no client, no task, no tag support to the API
1 parent 8524e01 commit 66dfc51

File tree

7 files changed

+550
-69
lines changed

7 files changed

+550
-69
lines changed

app/Http/Requests/V1/TimeEntry/TimeEntryAggregateExportRequest.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use App\Models\Tag;
1717
use App\Models\Task;
1818
use App\Models\User;
19+
use App\Service\TimeEntryFilter;
1920
use Illuminate\Contracts\Validation\ValidationRule;
2021
use Illuminate\Database\Eloquent\Builder;
2122
use Illuminate\Support\Carbon;
@@ -30,7 +31,7 @@ class TimeEntryAggregateExportRequest extends BaseFormRequest
3031
/**
3132
* Get the validation rules that apply to the request.
3233
*
33-
* @return array<string, array<string|ValidationRule|\Illuminate\Contracts\Validation\Rule>>
34+
* @return array<string, array<string|ValidationRule|\Illuminate\Contracts\Validation\Rule|\Closure>>
3435
*/
3536
public function rules(): array
3637
{
@@ -94,10 +95,15 @@ public function rules(): array
9495
],
9596
'project_ids.*' => [
9697
'string',
97-
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
98-
/** @var Builder<Project> $builder */
99-
return $builder->whereBelongsTo($this->organization, 'organization');
100-
})->uuid(),
98+
function (string $attribute, mixed $value, \Closure $fail): void {
99+
if ($value === TimeEntryFilter::NONE_VALUE) {
100+
return;
101+
}
102+
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
103+
/** @var Builder<Project> $builder */
104+
return $builder->whereBelongsTo($this->organization, 'organization');
105+
})->uuid()->validate($attribute, $value, $fail);
106+
},
101107
],
102108
// Filter by client IDs, client IDs are OR combined
103109
'client_ids' => [
@@ -106,10 +112,15 @@ public function rules(): array
106112
],
107113
'client_ids.*' => [
108114
'string',
109-
ExistsEloquent::make(Client::class, null, function (Builder $builder): Builder {
110-
/** @var Builder<Client> $builder */
111-
return $builder->whereBelongsTo($this->organization, 'organization');
112-
})->uuid(),
115+
function (string $attribute, mixed $value, \Closure $fail): void {
116+
if ($value === TimeEntryFilter::NONE_VALUE) {
117+
return;
118+
}
119+
ExistsEloquent::make(Client::class, null, function (Builder $builder): Builder {
120+
/** @var Builder<Client> $builder */
121+
return $builder->whereBelongsTo($this->organization, 'organization');
122+
})->uuid()->validate($attribute, $value, $fail);
123+
},
113124
],
114125
// Filter by tag IDs, tag IDs are OR combined
115126
'tag_ids' => [
@@ -118,10 +129,15 @@ public function rules(): array
118129
],
119130
'tag_ids.*' => [
120131
'string',
121-
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
122-
/** @var Builder<Tag> $builder */
123-
return $builder->whereBelongsTo($this->organization, 'organization');
124-
})->uuid(),
132+
function (string $attribute, mixed $value, \Closure $fail): void {
133+
if ($value === TimeEntryFilter::NONE_VALUE) {
134+
return;
135+
}
136+
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
137+
/** @var Builder<Tag> $builder */
138+
return $builder->whereBelongsTo($this->organization, 'organization');
139+
})->uuid()->validate($attribute, $value, $fail);
140+
},
125141
],
126142
// Filter by task IDs, task IDs are OR combined
127143
'task_ids' => [
@@ -130,9 +146,14 @@ public function rules(): array
130146
],
131147
'task_ids.*' => [
132148
'string',
133-
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
134-
return $builder->whereBelongsTo($this->organization, 'organization');
135-
})->uuid(),
149+
function (string $attribute, mixed $value, \Closure $fail): void {
150+
if ($value === TimeEntryFilter::NONE_VALUE) {
151+
return;
152+
}
153+
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
154+
return $builder->whereBelongsTo($this->organization, 'organization');
155+
})->uuid()->validate($attribute, $value, $fail);
156+
},
136157
],
137158
// Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z)
138159
'start' => [

app/Http/Requests/V1/TimeEntry/TimeEntryAggregateRequest.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Models\Tag;
1515
use App\Models\Task;
1616
use App\Models\User;
17+
use App\Service\TimeEntryFilter;
1718
use Illuminate\Contracts\Validation\ValidationRule;
1819
use Illuminate\Database\Eloquent\Builder;
1920
use Illuminate\Support\Carbon;
@@ -28,7 +29,7 @@ class TimeEntryAggregateRequest extends BaseFormRequest
2829
/**
2930
* Get the validation rules that apply to the request.
3031
*
31-
* @return array<string, array<string|ValidationRule|\Illuminate\Contracts\Validation\Rule>>
32+
* @return array<string, array<string|ValidationRule|\Illuminate\Contracts\Validation\Rule|\Closure>>
3233
*/
3334
public function rules(): array
3435
{
@@ -80,10 +81,15 @@ public function rules(): array
8081
],
8182
'project_ids.*' => [
8283
'string',
83-
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
84-
/** @var Builder<Project> $builder */
85-
return $builder->whereBelongsTo($this->organization, 'organization');
86-
})->uuid(),
84+
function (string $attribute, mixed $value, \Closure $fail): void {
85+
if ($value === TimeEntryFilter::NONE_VALUE) {
86+
return;
87+
}
88+
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
89+
/** @var Builder<Project> $builder */
90+
return $builder->whereBelongsTo($this->organization, 'organization');
91+
})->uuid()->validate($attribute, $value, $fail);
92+
},
8793
],
8894
// Filter by client IDs, client IDs are OR combined
8995
'client_ids' => [
@@ -92,10 +98,15 @@ public function rules(): array
9298
],
9399
'client_ids.*' => [
94100
'string',
95-
ExistsEloquent::make(Client::class, null, function (Builder $builder): Builder {
96-
/** @var Builder<Client> $builder */
97-
return $builder->whereBelongsTo($this->organization, 'organization');
98-
})->uuid(),
101+
function (string $attribute, mixed $value, \Closure $fail): void {
102+
if ($value === TimeEntryFilter::NONE_VALUE) {
103+
return;
104+
}
105+
ExistsEloquent::make(Client::class, null, function (Builder $builder): Builder {
106+
/** @var Builder<Client> $builder */
107+
return $builder->whereBelongsTo($this->organization, 'organization');
108+
})->uuid()->validate($attribute, $value, $fail);
109+
},
99110
],
100111
// Filter by tag IDs, tag IDs are OR combined
101112
'tag_ids' => [
@@ -104,10 +115,15 @@ public function rules(): array
104115
],
105116
'tag_ids.*' => [
106117
'string',
107-
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
108-
/** @var Builder<Tag> $builder */
109-
return $builder->whereBelongsTo($this->organization, 'organization');
110-
})->uuid(),
118+
function (string $attribute, mixed $value, \Closure $fail): void {
119+
if ($value === TimeEntryFilter::NONE_VALUE) {
120+
return;
121+
}
122+
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
123+
/** @var Builder<Tag> $builder */
124+
return $builder->whereBelongsTo($this->organization, 'organization');
125+
})->uuid()->validate($attribute, $value, $fail);
126+
},
111127
],
112128
// Filter by task IDs, task IDs are OR combined
113129
'task_ids' => [
@@ -116,9 +132,14 @@ public function rules(): array
116132
],
117133
'task_ids.*' => [
118134
'string',
119-
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
120-
return $builder->whereBelongsTo($this->organization, 'organization');
121-
})->uuid(),
135+
function (string $attribute, mixed $value, \Closure $fail): void {
136+
if ($value === TimeEntryFilter::NONE_VALUE) {
137+
return;
138+
}
139+
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
140+
return $builder->whereBelongsTo($this->organization, 'organization');
141+
})->uuid()->validate($attribute, $value, $fail);
142+
},
122143
],
123144
// Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z)
124145
'start' => [

app/Http/Requests/V1/TimeEntry/TimeEntryIndexExportRequest.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Models\Project;
1212
use App\Models\Tag;
1313
use App\Models\Task;
14+
use App\Service\TimeEntryFilter;
1415
use Illuminate\Contracts\Validation\ValidationRule;
1516
use Illuminate\Database\Eloquent\Builder;
1617
use Illuminate\Support\Carbon;
@@ -25,7 +26,7 @@ class TimeEntryIndexExportRequest extends TimeEntryIndexRequest
2526
/**
2627
* Get the validation rules that apply to the request.
2728
*
28-
* @return array<string, array<string|ValidationRule|\Illuminate\Contracts\Validation\Rule>>
29+
* @return array<string, array<string|ValidationRule|\Illuminate\Contracts\Validation\Rule|\Closure>>
2930
*/
3031
public function rules(): array
3132
{
@@ -64,11 +65,15 @@ public function rules(): array
6465
],
6566
'project_ids.*' => [
6667
'string',
67-
'uuid',
68-
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder {
69-
/** @var Builder<Project> $builder */
70-
return $builder->whereBelongsTo($this->organization, 'organization');
71-
}),
68+
function (string $attribute, mixed $value, \Closure $fail): void {
69+
if ($value === TimeEntryFilter::NONE_VALUE) {
70+
return;
71+
}
72+
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
73+
/** @var Builder<Project> $builder */
74+
return $builder->whereBelongsTo($this->organization, 'organization');
75+
})->uuid()->validate($attribute, $value, $fail);
76+
},
7277
],
7378
// Filter by tag IDs, tag IDs are OR combined
7479
'tag_ids' => [
@@ -77,11 +82,15 @@ public function rules(): array
7782
],
7883
'tag_ids.*' => [
7984
'string',
80-
'uuid',
81-
new ExistsEloquent(Tag::class, null, function (Builder $builder): Builder {
82-
/** @var Builder<Tag> $builder */
83-
return $builder->whereBelongsTo($this->organization, 'organization');
84-
}),
85+
function (string $attribute, mixed $value, \Closure $fail): void {
86+
if ($value === TimeEntryFilter::NONE_VALUE) {
87+
return;
88+
}
89+
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
90+
/** @var Builder<Tag> $builder */
91+
return $builder->whereBelongsTo($this->organization, 'organization');
92+
})->uuid()->validate($attribute, $value, $fail);
93+
},
8594
],
8695
// Filter by task IDs, task IDs are OR combined
8796
'task_ids' => [
@@ -90,11 +99,15 @@ public function rules(): array
9099
],
91100
'task_ids.*' => [
92101
'string',
93-
'uuid',
94-
new ExistsEloquent(Task::class, null, function (Builder $builder): Builder {
95-
/** @var Builder<Task> $builder */
96-
return $builder->whereBelongsTo($this->organization, 'organization');
97-
}),
102+
function (string $attribute, mixed $value, \Closure $fail): void {
103+
if ($value === TimeEntryFilter::NONE_VALUE) {
104+
return;
105+
}
106+
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
107+
/** @var Builder<Task> $builder */
108+
return $builder->whereBelongsTo($this->organization, 'organization');
109+
})->uuid()->validate($attribute, $value, $fail);
110+
},
98111
],
99112
// Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z)
100113
'start' => [

app/Http/Requests/V1/TimeEntry/TimeEntryIndexRequest.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Models\Project;
1313
use App\Models\Tag;
1414
use App\Models\Task;
15+
use App\Service\TimeEntryFilter;
1516
use Illuminate\Contracts\Validation\Rule as RuleContract;
1617
use Illuminate\Contracts\Validation\ValidationRule;
1718
use Illuminate\Database\Eloquent\Builder;
@@ -26,7 +27,7 @@ class TimeEntryIndexRequest extends BaseFormRequest
2627
/**
2728
* Get the validation rules that apply to the request.
2829
*
29-
* @return array<string, array<string|ValidationRule|RuleContract>>
30+
* @return array<string, array<string|ValidationRule|RuleContract|\Closure>>
3031
*/
3132
public function rules(): array
3233
{
@@ -58,10 +59,15 @@ public function rules(): array
5859
],
5960
'client_ids.*' => [
6061
'string',
61-
ExistsEloquent::make(Client::class, null, function (Builder $builder): Builder {
62-
/** @var Builder<Client> $builder */
63-
return $builder->whereBelongsTo($this->organization, 'organization');
64-
})->uuid(),
62+
function (string $attribute, mixed $value, \Closure $fail): void {
63+
if ($value === TimeEntryFilter::NONE_VALUE) {
64+
return;
65+
}
66+
ExistsEloquent::make(Client::class, null, function (Builder $builder): Builder {
67+
/** @var Builder<Client> $builder */
68+
return $builder->whereBelongsTo($this->organization, 'organization');
69+
})->uuid()->validate($attribute, $value, $fail);
70+
},
6571
],
6672
// Filter by project IDs, project IDs are OR combined
6773
'project_ids' => [
@@ -70,10 +76,15 @@ public function rules(): array
7076
],
7177
'project_ids.*' => [
7278
'string',
73-
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
74-
/** @var Builder<Project> $builder */
75-
return $builder->whereBelongsTo($this->organization, 'organization');
76-
})->uuid(),
79+
function (string $attribute, mixed $value, \Closure $fail): void {
80+
if ($value === TimeEntryFilter::NONE_VALUE) {
81+
return;
82+
}
83+
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
84+
/** @var Builder<Project> $builder */
85+
return $builder->whereBelongsTo($this->organization, 'organization');
86+
})->uuid()->validate($attribute, $value, $fail);
87+
},
7788
],
7889
// Filter by tag IDs, tag IDs are OR combined
7990
'tag_ids' => [
@@ -82,10 +93,15 @@ public function rules(): array
8293
],
8394
'tag_ids.*' => [
8495
'string',
85-
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
86-
/** @var Builder<Tag> $builder */
87-
return $builder->whereBelongsTo($this->organization, 'organization');
88-
})->uuid(),
96+
function (string $attribute, mixed $value, \Closure $fail): void {
97+
if ($value === TimeEntryFilter::NONE_VALUE) {
98+
return;
99+
}
100+
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
101+
/** @var Builder<Tag> $builder */
102+
return $builder->whereBelongsTo($this->organization, 'organization');
103+
})->uuid()->validate($attribute, $value, $fail);
104+
},
89105
],
90106
// Filter by task IDs, task IDs are OR combined
91107
'task_ids' => [
@@ -94,10 +110,15 @@ public function rules(): array
94110
],
95111
'task_ids.*' => [
96112
'string',
97-
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
98-
/** @var Builder<Task> $builder */
99-
return $builder->whereBelongsTo($this->organization, 'organization');
100-
})->uuid(),
113+
function (string $attribute, mixed $value, \Closure $fail): void {
114+
if ($value === TimeEntryFilter::NONE_VALUE) {
115+
return;
116+
}
117+
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
118+
/** @var Builder<Task> $builder */
119+
return $builder->whereBelongsTo($this->organization, 'organization');
120+
})->uuid()->validate($attribute, $value, $fail);
121+
},
101122
],
102123
// Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z)
103124
'start' => [

0 commit comments

Comments
 (0)