New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Api][Administrator] refactor endpoints for admin and admin avatar #11776
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,11 @@ private function __construct(string $url, string $method, array $headers = []) | |
$this->headers = array_merge($this->headers, $headers); | ||
} | ||
|
||
public static function index(string $resource, ?string $token = null): RequestInterface | ||
public static function index(?string $section, string $resource, ?string $token = null): RequestInterface | ||
{ | ||
$headers = $token ? ['HTTP_Authorization' => 'Bearer ' . $token] : []; | ||
|
||
return new self('/new-api/' . $resource, HttpRequest::METHOD_GET, $headers); | ||
return new self(sprintf('/new-api/%s%s', self::prepareSection($section), $resource), HttpRequest::METHOD_GET, $headers); | ||
} | ||
|
||
public static function subResourceIndex(string $resource, string $id, string $subResource): RequestInterface | ||
|
@@ -57,16 +57,16 @@ public static function subResourceIndex(string $resource, string $id, string $su | |
); | ||
} | ||
|
||
public static function show(string $resource, string $id, string $token): RequestInterface | ||
public static function show(?string $section, string $resource, string $id, string $token): RequestInterface | ||
{ | ||
return new self( | ||
sprintf('/new-api/%s/%s', $resource, $id), | ||
sprintf('/new-api/%s%s/%s', self::prepareSection($section), $resource, $id), | ||
HttpRequest::METHOD_GET, | ||
['HTTP_Authorization' => 'Bearer ' . $token] | ||
); | ||
} | ||
|
||
public static function create(string $resource, ?string $token = null): RequestInterface | ||
public static function create(?string $section, string $resource, ?string $token = null): RequestInterface | ||
{ | ||
$headers = ['CONTENT_TYPE' => 'application/ld+json']; | ||
|
||
|
@@ -75,25 +75,25 @@ public static function create(string $resource, ?string $token = null): RequestI | |
} | ||
|
||
return new self( | ||
sprintf('/new-api/%s', $resource), | ||
sprintf('/new-api/%s%s', self::prepareSection($section), $resource), | ||
HttpRequest::METHOD_POST, | ||
$headers | ||
); | ||
} | ||
|
||
public static function update(string $resource, string $id, string $token): RequestInterface | ||
public static function update(?string $section, string $resource, string $id, string $token): RequestInterface | ||
{ | ||
return new self( | ||
sprintf('/new-api/%s/%s', $resource, $id), | ||
sprintf('/new-api/%s%s/%s', self::prepareSection($section), $resource, $id), | ||
HttpRequest::METHOD_PUT, | ||
['CONTENT_TYPE' => 'application/ld+json', 'HTTP_Authorization' => 'Bearer ' . $token] | ||
); | ||
} | ||
|
||
public static function delete(string $resource, string $id, string $token): RequestInterface | ||
public static function delete(?string $section, string $resource, string $id, string $token): RequestInterface | ||
{ | ||
return new self( | ||
sprintf('/new-api/%s/%s', $resource, $id), | ||
sprintf('/new-api/%s%s/%s', self::prepareSection($section), $resource, $id), | ||
HttpRequest::METHOD_DELETE, | ||
['HTTP_Authorization' => 'Bearer ' . $token] | ||
); | ||
|
@@ -113,10 +113,10 @@ public static function customItemAction(string $resource, string $id, string $ty | |
); | ||
} | ||
|
||
public static function upload(string $resource, string $token): RequestInterface | ||
public static function upload(?string $section, string $resource, string $token): RequestInterface | ||
{ | ||
return new self( | ||
sprintf('/new-api/%s', $resource), | ||
sprintf('/new-api/%s%s', self::prepareSection($section), $resource), | ||
HttpRequest::METHOD_POST, | ||
['CONTENT_TYPE' => 'multipart/form-data', 'HTTP_Authorization' => 'Bearer ' . $token] | ||
); | ||
|
@@ -211,4 +211,13 @@ private function mergeArraysUniquely(array $firstArray, array $secondArray): arr | |
|
||
return $firstArray; | ||
} | ||
|
||
private static function prepareSection(?string $section): string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function should be deleted after refactor all new API endpoints, for now only refactored endpoint have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, we can leave it for the future, to give possibility of using this class without any section |
||
{ | ||
if($section === null) { | ||
return ''; | ||
} | ||
|
||
return $section . '/'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix it in the next PR.