Skip to content

Commit 7c48978

Browse files
committed
feat: add fau/v1/degree-program/index endpoint
1 parent 381097c commit 7c48978

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/Application/DegreeProgramViewTranslated.php

+12
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,18 @@ public function asArray(): array
377377
];
378378
}
379379

380+
public function asSimplifiedArray(): array
381+
{
382+
return [
383+
DegreeProgram::ID => $this->id->asInt(),
384+
DegreeProgram::SLUG => $this->slug,
385+
self::LINK => $this->link,
386+
DegreeProgram::CAMPO_KEYS => $this->campoKeys->asArray(),
387+
self::DATE => $this->date,
388+
self::MODIFIED => $this->modified,
389+
];
390+
}
391+
380392
public function jsonSerialize(): array
381393
{
382394
return $this->asArray();

src/Infrastructure/RestApi/TranslatedDegreeProgramController.php

+39
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public function register_routes(): void
7070
'args' => $this->get_collection_params(),
7171
],
7272
]);
73+
register_rest_route($this->namespace, '/' . $this->rest_base . '/index', [
74+
[
75+
'methods' => WP_REST_Server::READABLE,
76+
'callback' => [$this, 'getIndex'],
77+
'permission_callback' => [$this, 'get_items_permissions_check'],
78+
],
79+
]);
7380
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', [
7481
[
7582
'methods' => WP_REST_Server::READABLE,
@@ -176,6 +183,38 @@ public function get_items($request): WP_Error|WP_REST_Response
176183
return $response;
177184
}
178185

186+
public function getIndex(WP_REST_Request $request): WP_Error|WP_REST_Response
187+
{
188+
$criteria = CollectionCriteria::new()
189+
->withoutPagination();
190+
191+
$views = $this->degreeProgramCollectionRepository->findTranslatedCollection(
192+
$criteria,
193+
MultilingualString::DE
194+
);
195+
196+
if (!$views instanceof PaginationAwareCollection) {
197+
return new WP_Error(
198+
'unexpected_error',
199+
_x(
200+
'Something went wrong. Please try again later.',
201+
'rest_api: response status',
202+
'fau-degree-program-common'
203+
),
204+
['status' => 500]
205+
);
206+
}
207+
208+
$data = [];
209+
foreach ($views as $view) {
210+
$data[] = $this->prepare_response_for_collection(
211+
new WP_REST_Response($view->asSimplifiedArray())
212+
);
213+
}
214+
215+
return new WP_REST_Response($data);
216+
}
217+
179218
/**
180219
* @param WP_REST_Request $request Full data about the request.
181220
*/

0 commit comments

Comments
 (0)