Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-server
Commits
bfefedb4
Commit
bfefedb4
authored
Dec 10, 2019
by
François Agneray
Browse files
Modifying dataset route to adapt instance feature
parent
4d2bae16
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/routes.php
View file @
bfefedb4
...
...
@@ -24,7 +24,7 @@ $app->map([OPTIONS, GET, POST], '/output-category', App\Action\OutputCategoryLis
$app
->
map
([
OPTIONS
,
GET
,
PUT
,
DELETE
],
'/output-category/{id}'
,
App\Action\OutputCategoryAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
POST
],
'/instance'
,
App\Action\InstanceListAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
PUT
,
DELETE
],
'/instance/{name}'
,
App\Action\InstanceAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
POST
],
'/dataset'
,
App\Action\DatasetListAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
POST
],
'/
instance/{name}/
dataset'
,
App\Action\DatasetListAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
PUT
,
DELETE
],
'/dataset/{name}'
,
App\Action\DatasetAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
],
'/dataset/{name}/attribute'
,
App\Action\AttributeListAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
PUT
],
'/dataset/{name}/attribute/{id}'
,
App\Action\AttributeAction
::
class
);
...
...
src/Action/DatasetListAction.php
View file @
bfefedb4
...
...
@@ -15,6 +15,7 @@ namespace App\Action;
use
Psr\Http\Message\ServerRequestInterface
as
Request
;
use
Psr\Http\Message\ResponseInterface
as
Response
;
use
Slim\Exception\HttpBadRequestException
;
use
Slim\Exception\HttpNotFoundException
;
use
Doctrine\ORM\EntityManagerInterface
;
use
App\Utils\DBALConnectionFactory
;
use
App\Entity\Database
;
...
...
@@ -56,8 +57,18 @@ final class DatasetListAction extends AbstractAction
return
$response
->
withHeader
(
'Access-Control-Allow-Methods'
,
'GET, POST, OPTIONS'
);
}
$instance
=
$this
->
em
->
find
(
'App\Entity\Instance'
,
$args
[
'name'
]);
// Returns HTTP 404 if the instance is not found
if
(
is_null
(
$instance
))
{
throw
new
HttpNotFoundException
(
$request
,
'Instance with name '
.
$args
[
'name'
]
.
' is not found'
);
}
if
(
$request
->
getMethod
()
===
GET
)
{
$datasets
=
$this
->
em
->
getRepository
(
'App\Entity\Dataset'
)
->
find
All
(
);
$datasets
=
$this
->
em
->
getRepository
(
'App\Entity\Dataset'
)
->
find
ByInstance
(
$instance
);
$payload
=
json_encode
(
$datasets
);
}
...
...
@@ -76,7 +87,6 @@ final class DatasetListAction extends AbstractAction
'data_path'
,
'selectable_row'
,
'project_name'
,
'instance_name'
,
'id_dataset_family'
);
foreach
(
$fields
as
$a
)
{
...
...
@@ -97,15 +107,6 @@ final class DatasetListAction extends AbstractAction
);
}
// Instance is mandatory to add a new dataset
$instance
=
$this
->
em
->
find
(
'App\Entity\Instance'
,
$parsedBody
[
'instance_name'
]);
if
(
is_null
(
$instance
))
{
throw
new
HttpBadRequestException
(
$request
,
'Instance with name '
.
$parsedBody
[
'instance_name'
]
.
' is not found'
);
}
$family
=
$this
->
em
->
find
(
'App\Entity\DatasetFamily'
,
$parsedBody
[
'id_dataset_family'
]);
if
(
is_null
(
$family
))
{
throw
new
HttpBadRequestException
(
...
...
tests/Action/DatasetListActionTest.php
View file @
bfefedb4
...
...
@@ -16,6 +16,7 @@ use PHPUnit\Framework\TestCase;
use
Nyholm\Psr7\ServerRequest
;
use
Nyholm\Psr7\Response
;
use
Slim\Exception\HttpBadRequestException
;
use
Slim\Exception\HttpNotFoundException
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Schema\SqliteSchemaManager
;
use
Doctrine\DBAL\Schema\Column
;
...
...
@@ -46,11 +47,20 @@ final class DatasetListActionTest extends TestCase
$this
->
assertSame
(
$response
->
getHeaderLine
(
'Access-Control-Allow-Methods'
),
'GET, POST, OPTIONS'
);
}
public
function
testInstanceNotFound
():
void
{
$this
->
expectException
(
HttpNotFoundException
::
class
);
$this
->
expectExceptionMessage
(
'Instance with name aspic is not found'
);
$request
=
$this
->
getRequest
(
'GET'
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'name'
=>
'aspic'
));
$this
->
assertEquals
(
404
,
(
int
)
$response
->
getStatusCode
());
}
public
function
testGetAllDatasets
():
void
{
$datasets
=
$this
->
addDatasets
();
$request
=
$this
->
getRequest
(
'GET'
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
());
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'name'
=>
'aspic'
));
$this
->
assertSame
(
json_encode
(
$datasets
),
(
string
)
$response
->
getBody
()
...
...
@@ -59,20 +69,22 @@ final class DatasetListActionTest extends TestCase
public
function
testAddANewDatasetEmptyNameField
():
void
{
$this
->
addInstance
();
$this
->
expectException
(
HttpBadRequestException
::
class
);
$this
->
expectExceptionMessage
(
'Param name needed to add a new dataset'
);
$request
=
$this
->
getRequest
(
'POST'
)
->
withParsedBody
(
array
());
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
());
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'name'
=>
'aspic'
));
$this
->
assertEquals
(
400
,
(
int
)
$response
->
getStatusCode
());
}
public
function
testAddANewDatasetProjectNotFound
():
void
{
$this
->
addInstance
();
$this
->
expectException
(
HttpBadRequestException
::
class
);
$this
->
expectExceptionMessage
(
'Project with name anis_project is not found'
);
$fields
=
$this
->
getNewDatasetFields
();
$request
=
$this
->
getRequest
(
'POST'
)
->
withParsedBody
(
$fields
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
());
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'name'
=>
'aspic'
));
$this
->
assertEquals
(
400
,
(
int
)
$response
->
getStatusCode
());
}
...
...
@@ -84,18 +96,7 @@ final class DatasetListActionTest extends TestCase
$this
->
expectExceptionMessage
(
'Dataset family with id 1 is not found'
);
$fields
=
$this
->
getNewDatasetFields
();
$request
=
$this
->
getRequest
(
'POST'
)
->
withParsedBody
(
$fields
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
());
$this
->
assertEquals
(
400
,
(
int
)
$response
->
getStatusCode
());
}
public
function
testAddANewDatasetInstanceNotFound
():
void
{
$this
->
addProject
();
$this
->
expectException
(
HttpBadRequestException
::
class
);
$this
->
expectExceptionMessage
(
'Instance with name aspic is not found'
);
$fields
=
$this
->
getNewDatasetFields
();
$request
=
$this
->
getRequest
(
'POST'
)
->
withParsedBody
(
$fields
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
());
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'name'
=>
'aspic'
));
$this
->
assertEquals
(
400
,
(
int
)
$response
->
getStatusCode
());
}
...
...
@@ -106,7 +107,7 @@ final class DatasetListActionTest extends TestCase
$this
->
addDatasetFamily
();
$fields
=
$this
->
getNewDatasetFields
();
$request
=
$this
->
getRequest
(
'POST'
)
->
withParsedBody
(
$fields
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
());
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'name'
=>
'aspic'
));
$this
->
assertSame
(
json_encode
(
$fields
),
(
string
)
$response
->
getBody
()
...
...
@@ -121,7 +122,7 @@ final class DatasetListActionTest extends TestCase
private
function
getRequest
(
string
$method
):
ServerRequest
{
return
new
ServerRequest
(
$method
,
'/dataset'
,
array
(
return
new
ServerRequest
(
$method
,
'/
instance/aspic/
dataset'
,
array
(
'Content-Type'
=>
'application/json'
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment