Skip to content

Commit e738617

Browse files
committed
Some improvements as per #436
1 parent cec84c1 commit e738617

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

api.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,8 +1739,9 @@ class GenericDB
17391739
private $database;
17401740
private $pdo;
17411741
private $reflection;
1742-
private $columns;
1742+
private $definition;
17431743
private $conditions;
1744+
private $columns;
17441745
private $converter;
17451746

17461747
private function getDsn(String $address, String $port = null, String $database = null): String
@@ -1916,9 +1917,6 @@ public function selectAll(ReflectedTable $table, array $columnNames, Condition $
19161917
if ($limit == 0) {
19171918
return array();
19181919
}
1919-
if (!$columnOrdering) {
1920-
return $this->selectAllUnordered($table, $columnNames, $condition);
1921-
}
19221920
$selectColumns = $this->columns->getSelect($table, $columnNames);
19231921
$tableName = $table->getName();
19241922
$condition = $this->addAuthorizationCondition($condition);
@@ -3222,7 +3220,7 @@ public function handle(Request $request): Response
32223220

32233221
class DefaultOpenApiDefinition
32243222
{
3225-
private $root = [
3223+
protected $root = [
32263224
"openapi" => "3.0.0",
32273225
"info" => [
32283226
"title" => "JAVA-CRUD-API",
@@ -3281,7 +3279,7 @@ private function set(String $path, String $value) /*: void*/
32813279
public function setPaths(DatabaseDefinition $database) /*: void*/
32823280
{
32833281
$result = [];
3284-
foreach ($database->getTables() as $database) {
3282+
foreach ($database->getTables() as $table) {
32853283
$path = sprintf('/records/%s', $table->getName());
32863284
foreach (['get', 'post', 'put', 'patch', 'delete'] as $method) {
32873285
$this->set("/paths/$path/$method/description", "$method operation");
@@ -3830,6 +3828,11 @@ public function getColumnOrdering(ReflectedTable $table, array $params): array
38303828
$pk = $table->getPk();
38313829
if ($pk) {
38323830
$fields[] = [$pk->getName(), 'ASC'];
3831+
} else {
3832+
foreach ($table->columnNames() as $columnName) {
3833+
$fields[] = [$columnName, 'ASC'];
3834+
}
3835+
38333836
}
38343837
}
38353838
return $fields;

src/Tqdev/PhpCrudApi/Database/GenericDB.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class GenericDB
1313
private $database;
1414
private $pdo;
1515
private $reflection;
16-
private $columns;
16+
private $definition;
1717
private $conditions;
18+
private $columns;
1819
private $converter;
1920

2021
private function getDsn(String $address, String $port = null, String $database = null): String

src/Tqdev/PhpCrudApi/OpenApi/DefaultOpenApiDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class DefaultOpenApiDefinition
55
{
6-
private $root = [
6+
protected $root = [
77
"openapi" => "3.0.0",
88
"info" => [
99
"title" => "JAVA-CRUD-API",

src/Tqdev/PhpCrudApi/OpenApi/OpenApiDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private function set(String $path, String $value) /*: void*/
2020
public function setPaths(DatabaseDefinition $database) /*: void*/
2121
{
2222
$result = [];
23-
foreach ($database->getTables() as $database) {
23+
foreach ($database->getTables() as $table) {
2424
$path = sprintf('/records/%s', $table->getName());
2525
foreach (['get', 'post', 'put', 'patch', 'delete'] as $method) {
2626
$this->set("/paths/$path/$method/description", "$method operation");

0 commit comments

Comments
 (0)