From 0c134d9eac81f4537fbec2cf13516e5760e3d9ce Mon Sep 17 00:00:00 2001 From: Dave M Date: Thu, 26 Oct 2023 16:22:35 +0000 Subject: [PATCH] - First commit of a big WIP --- composer.json | 31 ++++++++++ src/ApiResponseHandler.php | 27 +++++++++ src/Entity/Issue.php | 110 ++++++++++++++++++++++++++++++++++++ src/Entity/IssueComment.php | 92 ++++++++++++++++++++++++++++++ src/Entity/Repository.php | 104 ++++++++++++++++++++++++++++++++++ src/Entity/User.php | 98 ++++++++++++++++++++++++++++++++ 6 files changed, 462 insertions(+) create mode 100644 composer.json create mode 100644 src/ApiResponseHandler.php create mode 100644 src/Entity/Issue.php create mode 100644 src/Entity/IssueComment.php create mode 100644 src/Entity/Repository.php create mode 100644 src/Entity/User.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..dfcd256 --- /dev/null +++ b/composer.json @@ -0,0 +1,31 @@ +{ + "name": "mcnd/ulmus-api-gitea", + "description": "A package made for mcnd/ulmus-api", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Dave Mc Nicoll", + "email": "info@mcnd.ca" + } + ], + "require": { + "mcnd/ulmus": "dev-master", + "mcnd/ulmus-api": "^1.x@dev" + }, + "repositories": [ + { + "type": "vcs", + "url": "https://git.mcnd.ca/mcndave/ulmus.git" + }, + { + "type": "vcs", + "url": "https://git.mcnd.ca/mcndave/ulmus-api.git" + } + ], + "autoload": { + "psr-4": { + "Ulmus\\Api\\Gitea": "src/" + } + } +} diff --git a/src/ApiResponseHandler.php b/src/ApiResponseHandler.php new file mode 100644 index 0000000..3a49e8b --- /dev/null +++ b/src/ApiResponseHandler.php @@ -0,0 +1,27 @@ +render(); + + if ($json['message'] ?? false) { + if ( array_key_exists('errors', $json) && null === $json['errors'] ?? null) { + if ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Collection) { + return []; + } + elseif ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Read) { + return null; + } + elseif ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Create) { + return false; + } + } + + throw new \Exception($json['message']); + } + + return $json; + } +} \ No newline at end of file diff --git a/src/Entity/Issue.php b/src/Entity/Issue.php new file mode 100644 index 0000000..4ed79c4 --- /dev/null +++ b/src/Entity/Issue.php @@ -0,0 +1,110 @@ +getQueryParams(), function($i) { return $i !== ""; })); + + $this->page = $get->offsetExists('page') ? $get['page'] : 1; + $this->file = $get->offsetExists('file') ? $get['file'] : null; + $this->createdAt = $get->offsetExists('created_at') ? $get['created_at'] : "DESC"; + } + + public function filter(\Ulmus\Repository $repository): \Ulmus\Repository { + return $repository; + } + + public function wheres() : iterable + { + return array_filter([ + ], function($i) { return ! is_null($i); }); + } + + public function likes(): iterable + { + return array_filter([ + ], function($i) { return ! is_null($i) && $i !== ""; }); + } + + public function groups(): iterable + { + return []; + } + + public function orders(): iterable + { + return array_filter([ + ], function($i) { return ! is_null($i) && $i !== ""; }); + } + }; + } +} \ No newline at end of file diff --git a/src/Entity/IssueComment.php b/src/Entity/IssueComment.php new file mode 100644 index 0000000..dae9d53 --- /dev/null +++ b/src/Entity/IssueComment.php @@ -0,0 +1,92 @@ +getQueryParams(), function($i) { return $i !== ""; })); + + $this->page = $get->offsetExists('page') ? $get['page'] : 1; + $this->file = $get->offsetExists('file') ? $get['file'] : null; + $this->createdAt = $get->offsetExists('created_at') ? $get['created_at'] : "DESC"; + } + + public function filter(\Ulmus\Repository $repository): \Ulmus\Repository { + return $repository; + } + + public function wheres() : iterable + { + return array_filter([ + ], function($i) { return ! is_null($i); }); + } + + public function likes(): iterable + { + return array_filter([ + ], function($i) { return ! is_null($i) && $i !== ""; }); + } + + public function groups(): iterable + { + return []; + } + + public function orders(): iterable + { + return array_filter([ + ], function($i) { return ! is_null($i) && $i !== ""; }); + } + }; + } +} \ No newline at end of file diff --git a/src/Entity/Repository.php b/src/Entity/Repository.php new file mode 100644 index 0000000..ce6543c --- /dev/null +++ b/src/Entity/Repository.php @@ -0,0 +1,104 @@ +getQueryParams(), function($i) { return $i !== ""; })); + + $this->page = $get->offsetExists('page') ? $get['page'] : 1; + $this->file = $get->offsetExists('file') ? $get['file'] : null; + $this->createdAt = $get->offsetExists('created_at') ? $get['created_at'] : "DESC"; + } + + public function filter(\Ulmus\Repository $repository): \Ulmus\Repository { + return $repository; + } + + public function wheres() : iterable + { + return array_filter([ + ], function($i) { return ! is_null($i); }); + } + + public function likes(): iterable + { + return array_filter([ + ], function($i) { return ! is_null($i) && $i !== ""; }); + } + + public function groups(): iterable + { + return []; + } + + public function orders(): iterable + { + return array_filter([ + ], function($i) { return ! is_null($i) && $i !== ""; }); + } + }; + } +} \ No newline at end of file diff --git a/src/Entity/User.php b/src/Entity/User.php new file mode 100644 index 0000000..3c33899 --- /dev/null +++ b/src/Entity/User.php @@ -0,0 +1,98 @@ +getQueryParams(), function($i) { return $i !== ""; })); + + $this->page = $get->offsetExists('page') ? $get['page'] : 1; + $this->file = $get->offsetExists('file') ? $get['file'] : null; + $this->createdAt = $get->offsetExists('created_at') ? $get['created_at'] : "DESC"; + } + + public function filter(\Ulmus\Repository $repository): \Ulmus\Repository { + return $repository; + } + + public function wheres() : iterable + { + return array_filter([ + #(string) Bug::field('software_id') => $this->softwareId, + ], function($i) { return ! is_null($i); }); + } + + public function likes(): iterable + { + return array_filter([ + #(string) Bug::field('title') => $this->title ? "%$this->title%" : null, + #(string) Bug::field('file') => $this->file ? "%$this->file%" : null, + ], function($i) { return ! is_null($i) && $i !== ""; }); + } + + public function groups(): iterable + { + return []; + } + + public function orders(): iterable + { + return array_filter([ + #(string) Bug::field('created_at') => $this->createdAt, + ], function($i) { return ! is_null($i) && $i !== ""; }); + } + }; + } +} \ No newline at end of file