feat(brands): remove internal uuid from brand responses and query only by brandCode
This commit is contained in:
parent
7312289811
commit
bc6a603913
11 changed files with 38 additions and 101 deletions
|
|
@ -5,12 +5,12 @@ info:
|
|||
|
||||
http:
|
||||
method: GET
|
||||
url: "{{ENDPOINT}}/api/{{APIV1}}/brands/:identifier"
|
||||
url: "{{ENDPOINT}}/api/{{APIV1}}/brands/:brandCode"
|
||||
params:
|
||||
- name: identifier
|
||||
value: "{{BRAND_IDENTIFIER}}"
|
||||
- name: brandCode
|
||||
value: "{{BRAND_CODE}}"
|
||||
type: path
|
||||
description: "Brand UUID v7 or public code (e.g. LGL01)"
|
||||
description: "Brand public code (e.g. LGL01)"
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ variables:
|
|||
- name: INCOSHEET_ID
|
||||
value: "47789"
|
||||
description: Arcadia ID of an IncoSheet (e.g. 47789, 47996)
|
||||
- name: BRAND_IDENTIFIER
|
||||
- name: BRAND_CODE
|
||||
value: LGL01
|
||||
description: Brand public code (e.g. LGL01) or UUID
|
||||
description: Brand public code (e.g. LGL01)
|
||||
- name: CLIENT_IDENTIFIER
|
||||
value: arcadia_id_00000000000000000000000000000001
|
||||
description: API Client Identifier for HMAC Authentication
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ variables:
|
|||
- name: INCOSHEET_ID
|
||||
value: "47789"
|
||||
description: Arcadia ID of an IncoSheet (e.g. 47789, 47996)
|
||||
- name: BRAND_IDENTIFIER
|
||||
- name: BRAND_CODE
|
||||
value: LGL01
|
||||
description: Brand public code (e.g. LGL01) or UUID
|
||||
description: Brand public code (e.g. LGL01)
|
||||
- name: CLIENT_IDENTIFIER
|
||||
value: arcadia_id_00000000000000000000000000000001
|
||||
description: API Client Identifier for HMAC Authentication
|
||||
|
|
|
|||
|
|
@ -216,17 +216,16 @@ paths:
|
|||
"503":
|
||||
$ref: "#/components/responses/ServiceUnavailable"
|
||||
|
||||
/brands/{identifier}:
|
||||
/brands/{brandCode}:
|
||||
get:
|
||||
tags:
|
||||
- Brands
|
||||
summary: Détail d'une marque par son identifiant UUID ou code public
|
||||
summary: Détail d'une marque par son code public
|
||||
description: |
|
||||
Retourne la fiche d'une marque spécifiée soit par son identifiant unique UUID v7,
|
||||
soit par son code public (ex: LGL01).
|
||||
Retourne la fiche d'une marque spécifiée par son code public (ex: LGL01).
|
||||
operationId: getBrand
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/BrandIdentifierPath"
|
||||
- $ref: "#/components/parameters/BrandCodePath"
|
||||
responses:
|
||||
"200":
|
||||
description: Fiche marque trouvée.
|
||||
|
|
@ -378,13 +377,14 @@ components:
|
|||
description: Signature HMAC-SHA256 calculée avec la clé secrète partagée.
|
||||
|
||||
parameters:
|
||||
BrandIdentifierPath:
|
||||
name: identifier
|
||||
BrandCodePath:
|
||||
name: brandCode
|
||||
in: path
|
||||
required: true
|
||||
description: Identifiant UUID v7 ou code public (ex. LGL01) de la marque.
|
||||
description: Code public unique trigramme + 2 chiffres de la marque (ex. LGL01).
|
||||
schema:
|
||||
type: string
|
||||
pattern: '^[A-Z]{3}\d{2}$'
|
||||
example: "LGL01"
|
||||
|
||||
EmployeeIdPath:
|
||||
|
|
@ -708,17 +708,11 @@ components:
|
|||
type: object
|
||||
description: Représentation canonique d'une marque dans Arcadia API.
|
||||
required:
|
||||
- id
|
||||
- code
|
||||
- name
|
||||
- arcadiaId
|
||||
- createdAt
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: uuid
|
||||
description: Identifiant UUID v7 unique de la marque.
|
||||
example: "01918a3c-1b77-7000-8000-000000000001"
|
||||
code:
|
||||
type: string
|
||||
pattern: '^[A-Z]{3}\d{2}$'
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ Route::middleware('auth.hmac')->group(function (): void {
|
|||
// * BRANDS
|
||||
Route::prefix('brands')->group(function (): void {
|
||||
Route::get('/', BrandsIndexController::class)->name('brands.index');
|
||||
Route::get('/{identifier}', BrandShowController::class)->name('brands.show');
|
||||
Route::get('/{brandCode}', BrandShowController::class)->name('brands.show');
|
||||
});
|
||||
|
||||
// * INCO SHEETS
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ use Shared\Time\Utc;
|
|||
final readonly class BrandDto implements ApiResponseDto
|
||||
{
|
||||
public function __construct(
|
||||
public string $id,
|
||||
public string $code,
|
||||
public string $name,
|
||||
public string $arcadiaId,
|
||||
|
|
@ -23,7 +22,6 @@ final readonly class BrandDto implements ApiResponseDto
|
|||
public static function fromView(BrandShowView $view): self
|
||||
{
|
||||
return new self(
|
||||
id: $view->id->value,
|
||||
code: $view->code->value,
|
||||
name: $view->name->value,
|
||||
arcadiaId: $view->arcadiaId->value,
|
||||
|
|
@ -34,7 +32,6 @@ final readonly class BrandDto implements ApiResponseDto
|
|||
public static function fromBrandItem(BrandItem $item): self
|
||||
{
|
||||
return new self(
|
||||
id: $item->id->value,
|
||||
code: $item->code->value,
|
||||
name: $item->name->value,
|
||||
arcadiaId: $item->arcadiaId->value,
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ final readonly class BrandShowController
|
|||
|
||||
private function inputFrom(BrandShowRequest $request): Input
|
||||
{
|
||||
return new Input(
|
||||
identifier: $request->identifier(),
|
||||
);
|
||||
return Input::byCode($request->brandCode());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ declare(strict_types=1);
|
|||
namespace Presentation\Api\V1\Http\Requests\Brands;
|
||||
|
||||
use Domain\Models\ValueObjects\Brand\BrandCode;
|
||||
use Domain\Models\ValueObjects\Brand\BrandId;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
final class BrandShowRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -15,10 +13,10 @@ final class BrandShowRequest extends FormRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'identifier' => [
|
||||
'brandCode' => [
|
||||
'required',
|
||||
'string',
|
||||
'regex:/^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[A-Z]{3}\d{2})$/i',
|
||||
'regex:/^[A-Z]{3}\d{2}$/i',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
@ -27,17 +25,13 @@ final class BrandShowRequest extends FormRequest
|
|||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'identifier' => $this->route('identifier'),
|
||||
'brandCode' => $this->route('brandCode') ?? $this->route('identifier'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function identifier(): BrandId | BrandCode
|
||||
public function brandCode(): BrandCode
|
||||
{
|
||||
$val = $this->string('identifier')->value();
|
||||
|
||||
if (Uuid::isValid($val)) {
|
||||
return new BrandId(Uuid::fromString($val));
|
||||
}
|
||||
$val = $this->string('brandCode')->value();
|
||||
|
||||
return new BrandCode(strtoupper($val));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,34 +43,7 @@ describe('Brand OpenAPI Conformance', function (): void {
|
|||
$response->assertValidResponse(200);
|
||||
});
|
||||
|
||||
it('validates GET /api/v1/brands/{identifier} detail response by UUID against openapi spec', function (): void {
|
||||
// GIVEN
|
||||
/** @var \Tests\TestCase $test */
|
||||
$test = $this;
|
||||
|
||||
$arcadia = MarqueFactory::new()->create([
|
||||
'COD_MARQ' => 1,
|
||||
'LIB_MARQ' => 'Le Gaulois',
|
||||
]);
|
||||
|
||||
$uuid = Uuid::uuid7()->toString();
|
||||
Brand::factory()->create([
|
||||
'id' => $uuid,
|
||||
'arcadia_id' => $arcadia['COD_MARQ'],
|
||||
'uwil_public_id' => 'LGL01',
|
||||
]);
|
||||
|
||||
// WHEN
|
||||
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
|
||||
$response = $test->getJson("/api/v1/brands/{$uuid}");
|
||||
|
||||
// THEN
|
||||
$response->assertStatus(200);
|
||||
$response->assertValidRequest();
|
||||
$response->assertValidResponse(200);
|
||||
});
|
||||
|
||||
it('validates GET /api/v1/brands/{identifier} detail response by BrandCode against openapi spec', function (): void {
|
||||
it('validates GET /api/v1/brands/{brandCode} detail response by BrandCode against openapi spec', function (): void {
|
||||
// GIVEN
|
||||
/** @var \Tests\TestCase $test */
|
||||
$test = $this;
|
||||
|
|
@ -96,15 +69,15 @@ describe('Brand OpenAPI Conformance', function (): void {
|
|||
$response->assertValidResponse(200);
|
||||
});
|
||||
|
||||
it('validates GET /api/v1/brands/{identifier} not found response against openapi spec', function (): void {
|
||||
it('validates GET /api/v1/brands/{brandCode} not found response against openapi spec', function (): void {
|
||||
// GIVEN
|
||||
/** @var \Tests\TestCase $test */
|
||||
$test = $this;
|
||||
$unexistingId = Uuid::uuid7()->toString();
|
||||
$test = $this;
|
||||
$unexistingCode = 'ZZZ98';
|
||||
|
||||
// WHEN
|
||||
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
|
||||
$response = $test->getJson("/api/v1/brands/{$unexistingId}");
|
||||
$response = $test->getJson("/api/v1/brands/{$unexistingCode}");
|
||||
|
||||
// THEN
|
||||
$response->assertStatus(404);
|
||||
|
|
@ -112,7 +85,7 @@ describe('Brand OpenAPI Conformance', function (): void {
|
|||
$response->assertValidResponse(404);
|
||||
});
|
||||
|
||||
it('validates GET /api/v1/brands/{identifier} validation error for invalid identifier', function (): void {
|
||||
it('validates GET /api/v1/brands/{brandCode} validation error for invalid identifier', function (): void {
|
||||
// GIVEN
|
||||
/** @var \Tests\TestCase $test */
|
||||
$test = $this;
|
||||
|
|
|
|||
|
|
@ -37,13 +37,11 @@ describe('BrandDto Unit Tests', function (): void {
|
|||
$dto = BrandDto::fromView($view);
|
||||
|
||||
// THEN
|
||||
expect($dto->id)->toBe((string) $id)
|
||||
->and($dto->name)->toBe('Le Gaulois')
|
||||
expect($dto->name)->toBe('Le Gaulois')
|
||||
->and($dto->code)->toBe('LGL01')
|
||||
->and($dto->arcadiaId)->toBe('1')
|
||||
->and($dto->createdAt)->toBe(DatesHelper::toRfc3339($createdAt))
|
||||
->and($dto->toArray())->toBe([
|
||||
'id' => (string) $id,
|
||||
'code' => 'LGL01',
|
||||
'name' => 'Le Gaulois',
|
||||
'arcadiaId' => '1',
|
||||
|
|
@ -71,8 +69,7 @@ describe('BrandDto Unit Tests', function (): void {
|
|||
$dto = BrandDto::fromBrandItem($item);
|
||||
|
||||
// THEN
|
||||
expect($dto->id)->toBe((string) $id)
|
||||
->and($dto->name)->toBe('Maître Coq')
|
||||
expect($dto->name)->toBe('Maître Coq')
|
||||
->and($dto->code)->toBe('MCQ02')
|
||||
->and($dto->arcadiaId)->toBe('2');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,45 +5,29 @@ declare(strict_types=1);
|
|||
namespace Tests\Unit\Presentation\Api\V1\Http\Requests\Brands;
|
||||
|
||||
use Domain\Models\ValueObjects\Brand\BrandCode;
|
||||
use Domain\Models\ValueObjects\Brand\BrandId;
|
||||
use Presentation\Api\V1\Http\Requests\Brands\BrandShowRequest;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
covers(BrandShowRequest::class);
|
||||
|
||||
describe('BrandShowRequest Unit Tests', function (): void {
|
||||
it('returns validation rules', function (): void {
|
||||
it('returns validation rules for brandCode', function (): void {
|
||||
// GIVEN
|
||||
$request = new BrandShowRequest();
|
||||
|
||||
// WHEN & THEN
|
||||
expect($request->rules())->toHaveKey('identifier');
|
||||
expect($request->rules())->toHaveKey('brandCode');
|
||||
});
|
||||
|
||||
it('parses UUID identifier into BrandId', function (): void {
|
||||
// GIVEN
|
||||
$uuid = Uuid::uuid7()->toString();
|
||||
$request = new BrandShowRequest();
|
||||
$request->merge(['identifier' => $uuid]);
|
||||
|
||||
// WHEN
|
||||
$identifier = $request->identifier();
|
||||
|
||||
// THEN
|
||||
expect($identifier)->toBeInstanceOf(BrandId::class)
|
||||
->and($identifier->value)->toBe($uuid);
|
||||
});
|
||||
|
||||
it('parses code identifier into BrandCode', function (): void {
|
||||
it('parses code parameter into BrandCode', function (): void {
|
||||
// GIVEN
|
||||
$request = new BrandShowRequest();
|
||||
$request->merge(['identifier' => 'LGL01']);
|
||||
$request->merge(['brandCode' => 'LGL01']);
|
||||
|
||||
// WHEN
|
||||
$identifier = $request->identifier();
|
||||
$code = $request->brandCode();
|
||||
|
||||
// THEN
|
||||
expect($identifier)->toBeInstanceOf(BrandCode::class)
|
||||
->and($identifier->value)->toBe('LGL01');
|
||||
expect($code)->toBeInstanceOf(BrandCode::class)
|
||||
->and($code->value)->toBe('LGL01');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue