mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 12:59:36 +00:00
Add stock quantity, datasheet URL, and HTTP caching to KiCad API
- Add Stock field showing total available quantity across all part lots - Add Storage Location field when parts have stored locations - Resolve actual datasheet PDF from attachments (by type name, attachment name, or first PDF) instead of always linking to Part-DB page - Keep Part-DB page URL as separate "Part-DB URL" field - Add ETag and Cache-Control headers to all KiCad API endpoints - Support conditional requests (If-None-Match) returning 304 - Categories/part lists cached 5 min, part details cached 1 min
This commit is contained in:
parent
70cde4c3a8
commit
cc77007b49
3 changed files with 157 additions and 12 deletions
|
|
@ -148,6 +148,11 @@ final class KiCadApiControllerTest extends WebTestCase
|
|||
'value' => 'http://localhost/en/part/1/info',
|
||||
'visible' => 'False',
|
||||
),
|
||||
'Part-DB URL' =>
|
||||
array(
|
||||
'value' => 'http://localhost/en/part/1/info',
|
||||
'visible' => 'False',
|
||||
),
|
||||
'description' =>
|
||||
array(
|
||||
'value' => '',
|
||||
|
|
@ -168,6 +173,11 @@ final class KiCadApiControllerTest extends WebTestCase
|
|||
'value' => '1',
|
||||
'visible' => 'False',
|
||||
),
|
||||
'Stock' =>
|
||||
array(
|
||||
'value' => '0',
|
||||
'visible' => 'False',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
|
@ -221,6 +231,11 @@ final class KiCadApiControllerTest extends WebTestCase
|
|||
'value' => 'http://localhost/en/part/1/info',
|
||||
'visible' => 'False',
|
||||
),
|
||||
'Part-DB URL' =>
|
||||
array (
|
||||
'value' => 'http://localhost/en/part/1/info',
|
||||
'visible' => 'False',
|
||||
),
|
||||
'description' =>
|
||||
array (
|
||||
'value' => '',
|
||||
|
|
@ -241,10 +256,42 @@ final class KiCadApiControllerTest extends WebTestCase
|
|||
'value' => '1',
|
||||
'visible' => 'False',
|
||||
),
|
||||
'Stock' =>
|
||||
array (
|
||||
'value' => '0',
|
||||
'visible' => 'False',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
self::assertEquals($expected, $data);
|
||||
}
|
||||
|
||||
public function testCategoriesHasCacheHeaders(): void
|
||||
{
|
||||
$client = $this->createClientWithCredentials();
|
||||
$client->request('GET', self::BASE_URL.'/categories.json');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
$response = $client->getResponse();
|
||||
self::assertNotNull($response->headers->get('ETag'));
|
||||
self::assertStringContainsString('max-age=', $response->headers->get('Cache-Control'));
|
||||
}
|
||||
|
||||
public function testConditionalRequestReturns304(): void
|
||||
{
|
||||
$client = $this->createClientWithCredentials();
|
||||
$client->request('GET', self::BASE_URL.'/categories.json');
|
||||
|
||||
$etag = $client->getResponse()->headers->get('ETag');
|
||||
self::assertNotNull($etag);
|
||||
|
||||
//Make a conditional request with the ETag
|
||||
$client->request('GET', self::BASE_URL.'/categories.json', [], [], [
|
||||
'HTTP_IF_NONE_MATCH' => $etag,
|
||||
]);
|
||||
|
||||
self::assertResponseStatusCodeSame(304);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue