feat(inco): mask internal allergen ids in api presentation responses
This commit is contained in:
parent
4434eb5757
commit
2606ac882e
7 changed files with 7 additions and 56 deletions
|
|
@ -1000,7 +1000,8 @@ components:
|
|||
allergens:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/IncoAllergen"
|
||||
type: string
|
||||
example: ["Gluten", "Lait"]
|
||||
brand:
|
||||
$ref: "#/components/schemas/IncoBrand"
|
||||
isSeasonal:
|
||||
|
|
@ -1120,20 +1121,6 @@ components:
|
|||
description: Indique si la portion est approximative.
|
||||
example: false
|
||||
|
||||
IncoAllergen:
|
||||
type: object
|
||||
description: Allergène présent ou en trace dans la recette.
|
||||
required:
|
||||
- code
|
||||
- label
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
example: 21
|
||||
label:
|
||||
type: string
|
||||
example: Aucun allergène
|
||||
|
||||
IncoNutriscore:
|
||||
type: object
|
||||
description: Note Nutri-Score affichée sur l'emballage.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ namespace Presentation\Api\V1\Dto\IncoSheets;
|
|||
use Presentation\Api\V1\Contracts\ApiResponseDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AdditiveDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AllegationsDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AllergenDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\BrandDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\NutriscoreDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\PortionsDto;
|
||||
|
|
@ -17,7 +16,7 @@ use Presentation\Api\V1\Dto\IncoSheets\Parts\WeightDto;
|
|||
final readonly class IncoSheetDto implements ApiResponseDto
|
||||
{
|
||||
/**
|
||||
* @param array<int, AllergenDto> $allergens
|
||||
* @param array<int, string> $allergens
|
||||
* @param array<int, AdditiveDto> $additives
|
||||
*/
|
||||
public function __construct(
|
||||
|
|
@ -52,7 +51,6 @@ final readonly class IncoSheetDto implements ApiResponseDto
|
|||
/** @var array<string, mixed> $vars */
|
||||
$vars = get_object_vars($this);
|
||||
|
||||
$vars['allergens'] = array_map(static fn (AllergenDto $dto): array => $dto->toArray(), $this->allergens);
|
||||
$vars['additives'] = array_map(static fn (AdditiveDto $dto): array => $dto->toArray(), $this->additives);
|
||||
|
||||
$vars['allegations'] = $this->allegations->toArray();
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Presentation\Api\V1\Dto\IncoSheets\Parts;
|
||||
|
||||
use Domain\Models\ValueObjects\Inco\Allergen;
|
||||
use Presentation\Api\V1\Contracts\ApiResponseDto;
|
||||
|
||||
final readonly class AllergenDto implements ApiResponseDto
|
||||
{
|
||||
public function __construct(
|
||||
public int $code,
|
||||
public string $label,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromDomain(Allergen $allergen): self
|
||||
{
|
||||
return new self(
|
||||
code: $allergen->code,
|
||||
label: $allergen->label,
|
||||
);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function toArray(): array
|
||||
{
|
||||
/** @var array<string, mixed> */
|
||||
return get_object_vars($this);
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,6 @@ use Presentation\Api\V1\Dto\IncoSheets\IncoSheetDto;
|
|||
use Presentation\Api\V1\Dto\IncoSheets\IncoShortSheetDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AdditiveDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AllegationsDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AllergenDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\BrandDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\NutriscoreDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\PortionsDto;
|
||||
|
|
@ -92,7 +91,7 @@ final readonly class IncoSheetsIndexResponse implements ApiResponse
|
|||
ingredients: $ingObject,
|
||||
portions: $sheet->portions !== null ? PortionsDto::fromDomain($sheet->portions) : null,
|
||||
allergens: array_values(array_map(
|
||||
static fn (Allergen $a): AllergenDto => AllergenDto::fromDomain($a),
|
||||
static fn (Allergen $a): string => $a->label,
|
||||
$sheet->allergens
|
||||
)),
|
||||
brand: BrandDto::fromDomain($sheet->brand),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use Presentation\Api\V1\Dto\IncoSheets\IncoSheetDto;
|
|||
use Presentation\Api\V1\Dto\IncoSheets\IncoShortSheetDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AdditiveDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AllegationsDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AllergenDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\BrandDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\NutriscoreDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\PortionsDto;
|
||||
|
|
@ -92,7 +91,7 @@ final readonly class IncoSheetsSearchResponse implements ApiResponse
|
|||
ingredients: $ingObject,
|
||||
portions: $sheet->portions !== null ? PortionsDto::fromDomain($sheet->portions) : null,
|
||||
allergens: array_values(array_map(
|
||||
static fn (Allergen $a): AllergenDto => AllergenDto::fromDomain($a),
|
||||
static fn (Allergen $a): string => $a->label,
|
||||
$sheet->allergens
|
||||
)),
|
||||
brand: BrandDto::fromDomain($sheet->brand),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ use Presentation\Api\V1\Contracts\ApiResponse;
|
|||
use Presentation\Api\V1\Dto\IncoSheets\IncoSheetDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AdditiveDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AllegationsDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\AllergenDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\BrandDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\NutriscoreDto;
|
||||
use Presentation\Api\V1\Dto\IncoSheets\Parts\PortionsDto;
|
||||
|
|
@ -60,7 +59,7 @@ final readonly class IncoSheetsShowResponse implements ApiResponse
|
|||
ingredients: $ingObject,
|
||||
portions: $output->portions !== null ? PortionsDto::fromDomain($output->portions) : null,
|
||||
allergens: array_values(array_map(
|
||||
static fn (Allergen $a): AllergenDto => AllergenDto::fromDomain($a),
|
||||
static fn (Allergen $a): string => $a->label,
|
||||
$output->allergens
|
||||
)),
|
||||
brand: BrandDto::fromDomain($output->brand),
|
||||
|
|
|
|||
|
|
@ -50,5 +50,6 @@ describe('IncoSheet Show Feature API', function (): void {
|
|||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('incoSheet.incoId', '47789');
|
||||
$response->assertJsonPath('incoSheet.sellFamilly', 'Panes du volailler <=400g');
|
||||
$response->assertJsonPath('incoSheet.allergens', ['Gluten', 'Lait']);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue