- First commit of a big WIP
This commit is contained in:
commit
0c134d9eac
31
composer.json
Normal file
31
composer.json
Normal file
@ -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/"
|
||||
}
|
||||
}
|
||||
}
|
27
src/ApiResponseHandler.php
Normal file
27
src/ApiResponseHandler.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class ApiResponseHandler
|
||||
{
|
||||
public static function handle(\Psr\Http\Message\ResponseInterface $response, \Ulmus\Api\Attribute\Obj\Api\ApiAction $attribute) : mixed
|
||||
{
|
||||
$json = $response->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;
|
||||
}
|
||||
}
|
110
src/Entity/Issue.php
Normal file
110
src/Entity/Issue.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Api\Gitea\Entity;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\{Api\Attribute\Property\Entity,
|
||||
Attribute\Property\Field,
|
||||
Entity\Field\Datetime,
|
||||
EntityTrait,
|
||||
SearchRequest\SearchRequestInterface,
|
||||
SearchRequest\SearchRequestPaginationTrait};
|
||||
use Ulmus\Api\Attribute\Obj\Api;
|
||||
|
||||
#[Api(adapter: "gitea")]
|
||||
#[Api\Create(url: "/repos/{owner}/{repo}/issues")]
|
||||
#[Api\Read(url: "/repos/{owner}/{repo}/issues/{index}")]
|
||||
#[Api\Collection(url: "/repos/{owner}/{repo}/issues")]
|
||||
#[Api\Update(url: "/repos/{owner}/{repo}/issues/{index}")]
|
||||
#[Api\Delete(url: "/repos/{owner}/{repo}/issues/{index}")]
|
||||
class Issue
|
||||
{
|
||||
use EntityTrait;
|
||||
|
||||
#[Field\Id]
|
||||
public int $id;
|
||||
|
||||
#[Field]
|
||||
public string $title;
|
||||
|
||||
#[Field]
|
||||
public string $body;
|
||||
|
||||
#[Field]
|
||||
public int $number;
|
||||
|
||||
#[Field(name: "html_url")]
|
||||
public string $htmlUrl;
|
||||
|
||||
#[Field]
|
||||
public string $url;
|
||||
|
||||
#[Field(name: "is_locked")]
|
||||
public bool $isLocked;
|
||||
|
||||
#[Field]
|
||||
public array $labels = [];
|
||||
|
||||
#[Field\CreatedAt(name: "closed_at")]
|
||||
public ? string $closedAt;
|
||||
|
||||
#[Field\CreatedAt(name: "due_date")]
|
||||
public ? string $dueDate;
|
||||
|
||||
#[Field\CreatedAt(name: "created_at")]
|
||||
public ? Datetime $createdAt;
|
||||
|
||||
#[Field\UpdatedAt(name: "updated_at")]
|
||||
public ? Datetime $updatedAt;
|
||||
|
||||
#[Entity]
|
||||
public User $user;
|
||||
|
||||
public static function searchRequest(...$arguments) : SearchRequestInterface
|
||||
{
|
||||
return new class($arguments[0]) implements SearchRequestInterface
|
||||
{
|
||||
use SearchRequestPaginationTrait;
|
||||
|
||||
public ? string $file = null;
|
||||
|
||||
public string $createdAt = "ASC";
|
||||
|
||||
public function __construct(ServerRequestInterface $request)
|
||||
{
|
||||
$get = new \ArrayObject(array_filter($request->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 !== ""; });
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
92
src/Entity/IssueComment.php
Normal file
92
src/Entity/IssueComment.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Api\Gitea\Entity;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\{Api\Attribute\Property\Entity,
|
||||
Attribute\Property\Field,
|
||||
Entity\Field\Datetime,
|
||||
EntityTrait,
|
||||
SearchRequest\SearchRequestInterface,
|
||||
SearchRequest\SearchRequestPaginationTrait};
|
||||
use Ulmus\Api\Attribute\Obj\Api;
|
||||
|
||||
#[Api(adapter: "gitea")]
|
||||
#[Api\Create(url: "/repos/{owner}/{repo}/issues/{index}/comments")]
|
||||
#[Api\Collection(url: "/repos/{owner}/{repo}/issues/{index}/comments")]
|
||||
#[Api\Read(url: "/repos/{owner}/{repo}/issues/comments/{id}")]
|
||||
#[Api\Update(url: "/repos/{owner}/{repo}/issues/comments/{id}")]
|
||||
#[Api\Delete(url: "/repos/{owner}/{repo}/issues/comments/{id}")]
|
||||
class IssueComment
|
||||
{
|
||||
use EntityTrait;
|
||||
|
||||
#[Field\Id]
|
||||
public int $id;
|
||||
|
||||
#[Field]
|
||||
public string $body;
|
||||
|
||||
#[Field(name: "html_url")]
|
||||
public string $htmlUrl;
|
||||
|
||||
#[Field(name:"issue_url")]
|
||||
public string $issueUrl;
|
||||
|
||||
#[Field\CreatedAt(name: "created_at")]
|
||||
public ? Datetime $createdAt;
|
||||
|
||||
#[Field\UpdatedAt(name: "updated_at")]
|
||||
public ? Datetime $updatedAt;
|
||||
|
||||
#[Entity]
|
||||
public User $user;
|
||||
|
||||
public static function searchRequest(...$arguments) : SearchRequestInterface
|
||||
{
|
||||
return new class($arguments[0]) implements SearchRequestInterface
|
||||
{
|
||||
use SearchRequestPaginationTrait;
|
||||
|
||||
public ? string $file = null;
|
||||
|
||||
public string $createdAt = "ASC";
|
||||
|
||||
public function __construct(ServerRequestInterface $request)
|
||||
{
|
||||
$get = new \ArrayObject(array_filter($request->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 !== ""; });
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
104
src/Entity/Repository.php
Normal file
104
src/Entity/Repository.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Api\Gitea\Entity;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\{Api\Attribute\Property\Entity,
|
||||
Attribute\Property\Field,
|
||||
Entity\Field\Datetime,
|
||||
EntityTrait,
|
||||
SearchRequest\SearchRequestInterface,
|
||||
SearchRequest\SearchRequestPaginationTrait};
|
||||
use Ulmus\Api\Attribute\Obj\Api;
|
||||
|
||||
#[Api(adapter: "gitea")]
|
||||
#[Api\Create(url: "/repos/{owner}/{id}")]
|
||||
#[Api\Collection(url: "/repos/{owner}/{id}")]
|
||||
#[Api\Read(url: "/repos/{owner}/{id}")]
|
||||
#[Api\Update(url: "/repos/{owner}/{id}")]
|
||||
#[Api\Delete(url: "/repos/{owner}/{id}")]
|
||||
class Repository
|
||||
{
|
||||
use EntityTrait;
|
||||
|
||||
#[Field\Id]
|
||||
public int $id;
|
||||
|
||||
#[Field]
|
||||
public string $title;
|
||||
|
||||
#[Field]
|
||||
public string $body;
|
||||
|
||||
#[Field]
|
||||
public int $number;
|
||||
|
||||
#[Field(name: "html_url")]
|
||||
public string $htmlUrl;
|
||||
|
||||
#[Field(name:"original_url")]
|
||||
public ? string $originalUrl;
|
||||
|
||||
#[Field(name: "is_locked")]
|
||||
public bool $isLocked;
|
||||
|
||||
#[Field]
|
||||
public array $labels = [];
|
||||
|
||||
#[Field\CreatedAt(name: "created_at")]
|
||||
public ? Datetime $createdAt;
|
||||
|
||||
#[Field\UpdatedAt(name: "updated_at")]
|
||||
public ? Datetime $updatedAt;
|
||||
|
||||
#[Entity]
|
||||
public User $owner;
|
||||
|
||||
public static function searchRequest(...$arguments) : SearchRequestInterface
|
||||
{
|
||||
return new class($arguments[0]) implements SearchRequestInterface
|
||||
{
|
||||
use SearchRequestPaginationTrait;
|
||||
|
||||
public ? string $file = null;
|
||||
|
||||
public string $createdAt = "ASC";
|
||||
|
||||
public function __construct(ServerRequestInterface $request)
|
||||
{
|
||||
$get = new \ArrayObject(array_filter($request->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 !== ""; });
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
98
src/Entity/User.php
Normal file
98
src/Entity/User.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Api\Gitea\Entity;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\{Attribute\Property\Field,
|
||||
Entity\Field\Datetime,
|
||||
EntityTrait,
|
||||
SearchRequest\SearchRequestInterface,
|
||||
SearchRequest\SearchRequestPaginationTrait};
|
||||
use Ulmus\Api\Attribute\Obj\Api;
|
||||
|
||||
#[Api(adapter: "gitea")]
|
||||
##[Api\Create(url: "/repos/{owner}/{repo}/issues")]
|
||||
##[Api\Collection(url: "/repos/{owner}/{repo}/issues")]
|
||||
##[Api\Read(url: "/repos/{owner}/{repo}/issues/{id}")]
|
||||
##[Api\Update(url: "/repos/{owner}/{repo}/issues/{id}")]
|
||||
##[Api\Delete(url: "/repos/{owner}/{repo}/issues/{id}")]
|
||||
class User
|
||||
{
|
||||
use EntityTrait;
|
||||
|
||||
#[Field\Id]
|
||||
public int $id;
|
||||
|
||||
#[Field(name:"login")]
|
||||
public string $login;
|
||||
|
||||
#[Field(name:"full_name")]
|
||||
public string $fullName;
|
||||
|
||||
#[Field]
|
||||
public string $email;
|
||||
|
||||
#[Field]
|
||||
public string $username;
|
||||
|
||||
#[Field(name: "is_admin")]
|
||||
public bool $isAdmin;
|
||||
|
||||
#[Field(name: "avatar_url")]
|
||||
public string $avatarUrl;
|
||||
|
||||
#[Field\CreatedAt(name: "created")]
|
||||
public ? Datetime $created;
|
||||
|
||||
public static function searchRequest(...$arguments) : SearchRequestInterface
|
||||
{
|
||||
return new class($arguments[0]) implements SearchRequestInterface
|
||||
{
|
||||
use SearchRequestPaginationTrait;
|
||||
|
||||
public ? string $file = null;
|
||||
|
||||
public string $createdAt = "ASC";
|
||||
|
||||
public function __construct(ServerRequestInterface $request)
|
||||
{
|
||||
$get = new \ArrayObject(array_filter($request->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 !== ""; });
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user