2026-05-14 04:31:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Infrastructure\Persistence\Repository;
|
|
|
|
|
|
|
|
|
|
use App\Domain\Article\Article;
|
|
|
|
|
use App\Domain\Article\ArticleStatus;
|
|
|
|
|
use App\Domain\Article\Repository\ArticleRepositoryInterface;
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
|
|
|
|
|
|
final class DoctrineArticleRepository implements ArticleRepositoryInterface
|
|
|
|
|
{
|
feat: implement Plan 2 — Article Management API
- 6 new domain repository interfaces (StoragePath, ArticlePhoto, AttributeValue, ChannelField, ArticleTypePlatformConfig, AttributeMapping)
- 6 Doctrine repository implementations
- StorageManager with multi-path quota-aware file storage (LocalStorageManager)
- Application services: ArticleTypeService, ArticleService, ArticleValidator, PhotoService, PlatformService, MappingService
- REST controllers: ArticleType, Article, Photo, Platform, Mapping (all under /api prefix)
- inventory_number sequence migration
- 22 unit tests passing, PHPStan level 9 clean, CS Fixer clean
- Fixed phpdoc_to_comment CS Fixer rule (disabled) to preserve @var type annotations
- Fixed PHPStan: User::getUserIdentifier non-empty-string, AIPipelineJob nullable missingFields
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 05:19:20 +00:00
|
|
|
public function __construct(private readonly EntityManagerInterface $em)
|
|
|
|
|
{
|
|
|
|
|
}
|
2026-05-14 04:31:33 +00:00
|
|
|
|
|
|
|
|
public function findById(Uuid $id): ?Article
|
|
|
|
|
{
|
|
|
|
|
return $this->em->find(Article::class, $id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function findBySku(string $sku): ?Article
|
|
|
|
|
{
|
|
|
|
|
return $this->em->getRepository(Article::class)->findOneBy(['sku' => $sku]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function findByInventoryNumber(string $inventoryNumber): ?Article
|
|
|
|
|
{
|
|
|
|
|
return $this->em->getRepository(Article::class)->findOneBy(['inventoryNumber' => $inventoryNumber]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 22:44:11 +00:00
|
|
|
public function findByEbayListingId(string $ebayListingId): ?Article
|
|
|
|
|
{
|
|
|
|
|
return $this->em->getRepository(Article::class)->findOneBy(['ebayListingId' => $ebayListingId]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 04:31:33 +00:00
|
|
|
/** @return list<Article> */
|
|
|
|
|
public function findByStatus(ArticleStatus $status): array
|
|
|
|
|
{
|
|
|
|
|
/** @var list<Article> */
|
|
|
|
|
return $this->em->getRepository(Article::class)->findBy(['status' => $status]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function decrementStockAtomic(Uuid $articleId): bool
|
|
|
|
|
{
|
|
|
|
|
$affected = $this->em->getConnection()->executeStatement(
|
|
|
|
|
'UPDATE app.articles SET stock = stock - 1 WHERE id = :id AND stock > 0',
|
|
|
|
|
['id' => $articleId->toRfc4122()],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($affected > 0) {
|
|
|
|
|
$article = $this->em->find(Article::class, $articleId);
|
|
|
|
|
if (null !== $article) {
|
|
|
|
|
$this->em->refresh($article);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $affected > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function save(Article $article): void
|
|
|
|
|
{
|
|
|
|
|
$this->em->persist($article);
|
|
|
|
|
$this->em->flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function remove(Article $article): void
|
|
|
|
|
{
|
|
|
|
|
$this->em->remove($article);
|
|
|
|
|
$this->em->flush();
|
|
|
|
|
}
|
|
|
|
|
}
|