Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
134
src/Application/Api/Images/ImageApiController.php
Normal file
134
src/Application/Api/Images/ImageApiController.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Application\Api\Images;
|
||||
|
||||
use App\Domain\Media\ImageRepository;
|
||||
use App\Framework\Attributes\Route;
|
||||
use App\Framework\Http\Exception\NotFound;
|
||||
use App\Framework\Http\HttpRequest;
|
||||
use App\Framework\Http\Method;
|
||||
use App\Framework\Http\Responses\JsonResponse;
|
||||
|
||||
final readonly class ImageApiController
|
||||
{
|
||||
public function __construct(
|
||||
private ImageRepository $imageRepository
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(path: '/api/images', method: Method::GET)]
|
||||
public function getImages(HttpRequest $request): JsonResponse
|
||||
{
|
||||
$limit = (int) ($request->queryParams['limit'] ?? 50);
|
||||
$offset = (int) ($request->queryParams['offset'] ?? 0);
|
||||
$search = $request->queryParams['search'] ?? null;
|
||||
|
||||
$images = $this->imageRepository->findAll($limit, $offset, $search);
|
||||
$total = $this->imageRepository->count($search);
|
||||
|
||||
return new JsonResponse([
|
||||
'images' => array_map(fn ($image) => [
|
||||
'ulid' => $image->ulid,
|
||||
'filename' => $image->filename,
|
||||
'original_filename' => $image->originalFilename,
|
||||
'url' => '/media/images/' . $image->path,
|
||||
'thumbnail_url' => '/media/images/thumbnails/' . $image->path,
|
||||
'alt_text' => $image->altText,
|
||||
'width' => $image->width,
|
||||
'height' => $image->height,
|
||||
'mime_type' => $image->mimeType,
|
||||
'file_size' => $image->fileSize,
|
||||
], $images),
|
||||
'pagination' => [
|
||||
'total' => $total,
|
||||
'limit' => $limit,
|
||||
'offset' => $offset,
|
||||
'has_more' => ($offset + $limit) < $total,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/api/images/{ulid}', method: Method::GET)]
|
||||
public function getImage(string $ulid): JsonResponse
|
||||
{
|
||||
$image = $this->imageRepository->findByUlid($ulid);
|
||||
|
||||
if (! $image) {
|
||||
throw new NotFound("Image with ULID {$ulid} not found");
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'ulid' => $image->ulid,
|
||||
'filename' => $image->filename,
|
||||
'original_filename' => $image->originalFilename,
|
||||
'url' => '/media/images/' . $image->path,
|
||||
'alt_text' => $image->altText,
|
||||
'width' => $image->width,
|
||||
'height' => $image->height,
|
||||
'mime_type' => $image->mimeType,
|
||||
'file_size' => $image->fileSize,
|
||||
'hash' => $image->hash,
|
||||
'variants' => array_map(fn ($variant) => [
|
||||
'type' => $variant->type,
|
||||
'width' => $variant->width,
|
||||
'height' => $variant->height,
|
||||
'path' => $variant->path,
|
||||
'url' => '/media/images/' . $variant->path,
|
||||
], $image->variants ?? []),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/api/images/{ulid}', method: Method::PUT)]
|
||||
public function updateImage(string $ulid, HttpRequest $request): JsonResponse
|
||||
{
|
||||
$image = $this->imageRepository->findByUlid($ulid);
|
||||
|
||||
if (! $image) {
|
||||
throw new NotFound("Image with ULID {$ulid} not found");
|
||||
}
|
||||
|
||||
$data = $request->parsedBody->toArray();
|
||||
|
||||
// Update alt text if provided
|
||||
if (isset($data['alt_text'])) {
|
||||
$this->imageRepository->updateAltText($ulid, $data['alt_text']);
|
||||
}
|
||||
|
||||
// Update filename if provided
|
||||
if (isset($data['filename'])) {
|
||||
$this->imageRepository->updateFilename($ulid, $data['filename']);
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'success' => true,
|
||||
'message' => 'Image updated successfully',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/api/images/search', method: Method::GET)]
|
||||
public function searchImages(HttpRequest $request): JsonResponse
|
||||
{
|
||||
$query = $request->queryParams['q'] ?? '';
|
||||
$type = $request->queryParams['type'] ?? null; // jpeg, png, webp
|
||||
$minWidth = (int) ($request->queryParams['min_width'] ?? 0);
|
||||
$minHeight = (int) ($request->queryParams['min_height'] ?? 0);
|
||||
|
||||
$images = $this->imageRepository->search($query, $type, $minWidth, $minHeight);
|
||||
|
||||
return new JsonResponse([
|
||||
'results' => array_map(fn ($image) => [
|
||||
'ulid' => $image->ulid,
|
||||
'filename' => $image->filename,
|
||||
'url' => '/media/images/' . $image->path,
|
||||
'thumbnail_url' => '/media/images/thumbnails/' . $image->path,
|
||||
'alt_text' => $image->altText,
|
||||
'width' => $image->width,
|
||||
'height' => $image->height,
|
||||
'mime_type' => $image->mimeType,
|
||||
], $images),
|
||||
'count' => count($images),
|
||||
]);
|
||||
}
|
||||
}
|
||||
121
src/Application/Api/Images/ImageSlotController.php
Normal file
121
src/Application/Api/Images/ImageSlotController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Application\Api\Images;
|
||||
|
||||
use App\Domain\Media\ImageRepository;
|
||||
use App\Domain\Media\ImageSlotRepository;
|
||||
use App\Framework\Attributes\Route;
|
||||
use App\Framework\Http\Exception\NotFound;
|
||||
use App\Framework\Http\HttpRequest;
|
||||
use App\Framework\Http\Method;
|
||||
use App\Framework\Http\Responses\JsonResponse;
|
||||
|
||||
final readonly class ImageSlotController
|
||||
{
|
||||
public function __construct(
|
||||
private ImageSlotRepository $slotRepository,
|
||||
private ImageRepository $imageRepository
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(path: '/api/image-slots', method: Method::GET)]
|
||||
public function getSlots(): JsonResponse
|
||||
{
|
||||
$slots = $this->slotRepository->findAllWithImages();
|
||||
|
||||
return new JsonResponse([
|
||||
'slots' => array_map(fn ($slot) => [
|
||||
'id' => $slot->id,
|
||||
'slot_name' => $slot->slotName,
|
||||
'image' => $slot->image ? [
|
||||
'ulid' => $slot->image->ulid,
|
||||
'filename' => $slot->image->filename,
|
||||
'url' => '/media/images/' . $slot->image->path,
|
||||
'alt_text' => $slot->image->altText,
|
||||
'width' => $slot->image->width,
|
||||
'height' => $slot->image->height,
|
||||
'mime_type' => $slot->image->mimeType,
|
||||
] : null,
|
||||
], $slots),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/api/image-slots/{id}', method: Method::GET)]
|
||||
public function getSlot(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$slot = $this->slotRepository->findByIdWithImage($id);
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new NotFound($e->getMessage());
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'id' => $slot->id,
|
||||
'slot_name' => $slot->slotName,
|
||||
'image' => $slot->image ? [
|
||||
'ulid' => $slot->image->ulid,
|
||||
'filename' => $slot->image->filename,
|
||||
'url' => '/media/images/' . $slot->image->path,
|
||||
'alt_text' => $slot->image->altText,
|
||||
'width' => $slot->image->width,
|
||||
'height' => $slot->image->height,
|
||||
'mime_type' => $slot->image->mimeType,
|
||||
] : null,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/api/image-slots/{id}/image', method: Method::PUT)]
|
||||
public function assignImage(int $id, HttpRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$slot = $this->slotRepository->findById($id);
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new NotFound($e->getMessage());
|
||||
}
|
||||
|
||||
$data = $request->parsedBody->toArray();
|
||||
$imageUlid = $data['image_ulid'] ?? null;
|
||||
|
||||
if (! $imageUlid) {
|
||||
return new JsonResponse(['error' => 'image_ulid is required'], 400);
|
||||
}
|
||||
|
||||
$image = $this->imageRepository->findByUlid($imageUlid);
|
||||
|
||||
if (! $image) {
|
||||
throw new NotFound("Image with ULID {$imageUlid} not found");
|
||||
}
|
||||
|
||||
// Update slot with new image
|
||||
$this->slotRepository->updateImageId($id, $imageUlid);
|
||||
|
||||
return new JsonResponse([
|
||||
'success' => true,
|
||||
'slot' => [
|
||||
'id' => $slot->id,
|
||||
'slot_name' => $slot->slotName,
|
||||
'image_ulid' => $imageUlid,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/api/image-slots/{id}/image', method: Method::DELETE)]
|
||||
public function removeImage(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$slot = $this->slotRepository->findById($id);
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new NotFound($e->getMessage());
|
||||
}
|
||||
|
||||
// Remove image from slot
|
||||
$this->slotRepository->updateImageId($id, '');
|
||||
|
||||
return new JsonResponse([
|
||||
'success' => true,
|
||||
'message' => 'Image removed from slot',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user