Skip to content
Snippets Groups Projects
Commit bab1e74d authored by François Agneray's avatar François Agneray
Browse files

Fixed bug types (float, datatable null)

parent 569e1d06
No related branches found
No related tags found
2 merge requests!72Develop,!34New features
......@@ -41,7 +41,7 @@
</button>
</td>
<td *ngFor="let attribute of getOutputList()" class="align-middle">
<div *ngIf="datum[attribute.label]" [ngSwitch]="attribute.renderer">
<div *ngIf="datum[attribute.label] != null" [ngSwitch]="attribute.renderer">
<div *ngSwitchCase="'detail-link'">
<app-detail-link-renderer
[value]="datum[attribute.label]"
......
......@@ -107,7 +107,11 @@ export class ArchiveEffects {
resetArchive$ = createEffect(() =>
this.actions$.pipe(
ofType(archiveActions.resetArchive),
tap(() => this.kill$.unsubscribe())
tap(() => {
if (this.kill$) {
this.kill$.unsubscribe();
}
})
), { dispatch: false}
);
......
......@@ -13,7 +13,8 @@ max_input_time = 60
[xdebug]
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20210902/xdebug.so
xdebug.mode=debug
xdebug.default_enable=1
xdebug.mode=develop,debug
xdebug.client_host=127.0.0.1
xdebug.client_port="9003"
......
......@@ -32,14 +32,15 @@ class JsonResponse implements IResponse
*/
public function getResponse(ResponseInterface $response, AnisQueryBuilder $anisQueryBuilder): ResponseInterface
{
$stmt = $anisQueryBuilder->getDoctrineQueryBuilder()->execute();
$stmt = $anisQueryBuilder->getDoctrineQueryBuilder()->executeQuery();
$attributes = $anisQueryBuilder->getAttributesSelected();
$payload = json_encode($this->decodeNestedJson($stmt, $attributes), JSON_UNESCAPED_SLASHES);
$payload = json_encode($this->processesTypes($stmt, $attributes), JSON_UNESCAPED_SLASHES);
$response->getBody()->write($payload);
return $response;
}
/**
* Process types like float
* Decode each nsted json result and returns array results
*
* @param Result $stmt The doctrine statement of the query request
......@@ -47,34 +48,21 @@ class JsonResponse implements IResponse
*
* @return array
*/
private function decodeNestedJson(Result $stmt, array $attributes): array
private function processesTypes(Result $stmt, array $attributes): array
{
$rows = array();
$jsonAttributes = $this->getAttributesOfTypeJson($attributes);
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
foreach ($row as $key => $column) {
if (array_search($key, $jsonAttributes) !== false && !is_null($column)) {
$row[$key] = json_decode($column, true);
while ($row = $stmt->fetchAssociative()) {
foreach ($attributes as $attribute) {
$value = $row[$attribute->getLabel()];
if ($attribute->getType() === 'json' && !is_null($value)) {
$row[$attribute->getLabel()] = json_decode($value, true);
}
if ($attribute->getType() === 'float' && !is_null($value)) {
$row[$attribute->getLabel()] = floatval($value);
}
}
$rows[] = $row;
}
return $rows;
}
/**
* Returns array of attributes label for the attribute type json
*
* @param Attribute[] $attributes The query attributes selected
*
* @return string[]
*/
private function getAttributesOfTypeJson(array $attributes): array
{
return array_map(function ($attribute) {
return $attribute->getLabel();
}, array_filter($attributes, function ($attribute) {
return $attribute->getType() === 'json';
}));
}
}
......@@ -25,7 +25,7 @@ final class JsonResponseTest extends TestCase
public function testGetResponse(): void
{
$stmt = $this->getResultMock();
$stmt->method('fetch')->willReturnOnConsecutiveCalls(array(
$stmt->method('fetchAssociative')->willReturnOnConsecutiveCalls(array(
'id' => 1,
'ra' => 102.5,
'dec' => 0.1,
......@@ -34,19 +34,22 @@ final class JsonResponseTest extends TestCase
$id = $this->getAttributeMock();
$id->method('getLabel')->willReturn('id');
$id->method('getType')->willReturn('integer');
$ra = $this->getAttributeMock();
$ra->method('getLabel')->willReturn('ra');
$ra->method('getType')->willReturn('float');
$dec = $this->getAttributeMock();
$dec->method('getLabel')->willReturn('dec');
$dec = $this->getAttributeMock();
$dec->method('getLabel')->willReturn('json');
$dec->method('getType')->willReturn('json');
$dec->method('getType')->willReturn('float');
$json = $this->getAttributeMock();
$json->method('getLabel')->willReturn('json');
$json->method('getType')->willReturn('json');
$doctrineQueryBuilder = $this->getDoctrineQueryBuilderMock();
$doctrineQueryBuilder->method('execute')->willReturn($stmt);
$doctrineQueryBuilder->method('executeQuery')->willReturn($stmt);
$anisQueryBuilder = $this->getAnisQueryBuilderMock();
$anisQueryBuilder->method('getDoctrineQueryBuilder')->willReturn($doctrineQueryBuilder);
$anisQueryBuilder->method('getAttributesSelected')->willReturn(array($id, $ra, $dec));
$anisQueryBuilder->method('getAttributesSelected')->willReturn(array($id, $ra, $dec, $json));
$textResponse = new JsonResponse();
$r = new Response(200, array(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment