ver. 0.320: API słowniki — ensure_producer; ProductRepository — producer_name w odpowiedzi
- DictionariesApiController: nowy endpoint POST ensure_producer (znajdź lub utwórz producenta) - ProducerRepository: metoda ensureProducerForApi() - ProductRepository: pole producer_name w odpowiedzi GET product - ApiRouter: wstrzyknięto ProducerRepository do DictionariesApiController - Zaktualizowano docs/API.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -357,4 +357,34 @@ class ProducerRepository
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Znajdź producenta po nazwie lub utwórz nowego (dla API).
|
||||
*
|
||||
* @return array{id: int, created: bool}
|
||||
*/
|
||||
public function ensureProducerForApi(string $name): array
|
||||
{
|
||||
$name = trim($name);
|
||||
if ($name === '') {
|
||||
return ['id' => 0, 'created' => false];
|
||||
}
|
||||
|
||||
$existing = $this->db->get('pp_shop_producer', 'id', ['name' => $name]);
|
||||
if (!empty($existing)) {
|
||||
return ['id' => (int)$existing, 'created' => false];
|
||||
}
|
||||
|
||||
$this->db->insert('pp_shop_producer', [
|
||||
'name' => $name,
|
||||
'status' => 1,
|
||||
'img' => null,
|
||||
]);
|
||||
$id = (int)$this->db->id();
|
||||
if ($id <= 0) {
|
||||
return ['id' => 0, 'created' => false];
|
||||
}
|
||||
|
||||
return ['id' => $id, 'created' => true];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user