diff --git a/src/QueryParameters/GetAllocationsParameters.php b/src/QueryParameters/GetAllocationsParameters.php new file mode 100644 index 0000000..cc060fb --- /dev/null +++ b/src/QueryParameters/GetAllocationsParameters.php @@ -0,0 +1,62 @@ + $fields + * @param ?array $expand + */ + public function __construct( + public ?int $clientId = null, + public ?int $projectId = null, + public ?int $phaseId = null, + public ?int $taskMetaId = null, + public ?int $peopleId = null, + public ?string $startDate = null, + public ?string $endDate = null, + public ?int $billable = null, + public ?int $status = null, + public ?int $repeatState = null, + public ?string $modifiedSince = null, + public ?array $fields = null, + public ?array $expand = null, + ?int $page = null, + ?int $perPage = null, + ?string $sort = null, + ) { + $this->page = $page; + $this->perPage = $perPage; + $this->sort = $sort; + } + + /** + * @return array + */ + public function toArray(): array + { + return array_filter([ + 'client_id' => $this->clientId, + 'project_id' => $this->projectId, + 'phase_id' => $this->phaseId, + 'task_meta_id' => $this->taskMetaId, + 'people_id' => $this->peopleId, + 'start_date' => $this->startDate, + 'end_date' => $this->endDate, + 'billable' => $this->billable, + 'status' => $this->status, + 'repeat_state' => $this->repeatState, + 'modified_since' => $this->modifiedSince, + 'fields' => $this->fields ? implode(',', $this->fields) : null, + 'expand' => $this->expand ? implode(',', $this->expand) : null, + 'page' => $this->page, + 'per-page' => $this->perPage, + 'sort' => $this->sort, + ], fn ($value) => $value !== null); + } +} diff --git a/src/Requests/GetAllocation.php b/src/Requests/GetAllocation.php new file mode 100644 index 0000000..4e7cb44 --- /dev/null +++ b/src/Requests/GetAllocation.php @@ -0,0 +1,25 @@ +id}"; + } + + public function createDtoFromResponse(Response $response): AllocationResource + { + return AllocationResource::createFromResponse($response->json()); + } +} diff --git a/src/Requests/GetAllocations.php b/src/Requests/GetAllocations.php new file mode 100644 index 0000000..fdc3d25 --- /dev/null +++ b/src/Requests/GetAllocations.php @@ -0,0 +1,37 @@ +parameters ? $this->parameters->toArray() : []; + } + + public function resolveEndpoint(): string + { + return '/tasks'; + } + + /** @return array */ + public function createDtoFromResponse(Response $response): array + { + return array_map( + fn (array $object) => TaskResource::createFromResponse($object), + $response->json() + ); + } +} diff --git a/src/Resources/AllocationResource.php b/src/Resources/AllocationResource.php new file mode 100644 index 0000000..4e58561 --- /dev/null +++ b/src/Resources/AllocationResource.php @@ -0,0 +1,62 @@ + $data */ + public static function createFromResponse(array $data): self + { + return new self( + taskId: $data['task_id'] ?? null, + rootTaskId: $data['root_task_id'] ?? null, + parentTaskId: $data['parent_task_id'] ?? null, + projectId: $data['project_id'] ?? null, + phaseId: $data['phase_id'] ?? null, + startDate: $data['start_date'] ?? null, + endDate: $data['end_date'] ?? null, + startTime: $data['start_time'] ?? null, + hours: $data['hours'] ?? null, + peopleId: $data['people_id'] ?? null, + peopleIds: $data['people_ids'] ?? [], + status: $data['status'] ?? null, + billable: $data['billable'] ?? null, + name: $data['name'] ?? null, + notes: $data['notes'] ?? null, + repeatState: $data['repeat_state'] ?? null, + repeatEndDate: $data['repeat_end_date'] ?? null, + createdBy: $data['created_by'] ?? null, + created: $data['created'] ?? null, + modifiedBy: $data['modified_by'] ?? null, + modified: $data['modified'] ?? null, + ); + } +}