Skip to content

Commit

Permalink
add endpoint for languages with dictioaries
Browse files Browse the repository at this point in the history
  • Loading branch information
70ray committed Dec 24, 2024
1 parent 15d9310 commit 7fe56ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions SETUP/tests/unittests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,15 @@ public function test_unavailable_document(): void
$_SERVER["REQUEST_METHOD"] = "GET";
$router->route($path, ['language_code' => 'de']);
}

public function test_dictionaries(): void
{
$path = "v1/dictionaries";
$router = ApiRouter::get_router();
$_SERVER["REQUEST_METHOD"] = "GET";
$response = $router->route($path, []);
$this->assertEquals("Afrikaans", $response[0]);
}
}

// this mocks the function in index.php
Expand Down
1 change: 1 addition & 0 deletions api/v1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ $router->add_validator(":document", "validate_document");
// Add routes
$router->add_route("GET", "v1/documents", "api_v1_documents");
$router->add_route("GET", "v1/documents/:document", "api_v1_document");
$router->add_route("GET", "v1/dictionaries", "api_v1_dictionaries");

$router->add_route("GET", "v1/projects", "api_v1_projects");
$router->add_route("POST", "v1/projects", "api_v1_project");
Expand Down
7 changes: 7 additions & 0 deletions api/v1_docs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ function api_v1_document(string $method, array $data, array $query_params): stri
}
return $faq_url;
}

function api_v1_dictionaries(string $method, array $data, array $query_params): array
{
$dict_list = array_values(get_languages_with_dictionaries());
asort($dict_list);
return $dict_list;
}

0 comments on commit 7fe56ef

Please sign in to comment.