feat(story-2.2+2.3): device setup page, account linking, naming & configuration
Story 2.2 — /setup/{mac} Twig page (no Vue, works JS-disabled):
- Register tab: creates account + logs in + links device → /setup/{mac}/configure
- Login tab: manual credential check via UserPasswordHasherInterface + Security::login()
+ links device → /setup/{mac}/configure
- Re-provisioning: DeviceService.linkToUser() atomically transfers ownership + stubs
purgeDeviceHistory() (completed in Epic 3 when Image/Approval entities exist)
Story 2.3 — /setup/{mac}/configure (requires auth):
- GET: device name, orientation (landscape/portrait), rotation interval (6/12/24/48/168h),
uniqueness window (5/10/20/50 cycles)
- POST: validates name, saves to Device entity, redirects to Vue SPA
- Device entity: mac, name, orientation (Orientation enum), rotationIntervalHours,
uniquenessWindow, user (ManyToOne), linkedAt
- PATCH /api/devices/{id}: Vue SPA can edit any device field (Story 2.3 "edit from app")
- GET /api/devices: list authenticated user's devices
- Migration: create device table with Orientation enum column
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Device;
|
||||
use App\Entity\User;
|
||||
use App\Repository\DeviceRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class DeviceService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DeviceRepository $repo,
|
||||
private readonly EntityManagerInterface $em,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Atomically link a MAC address to a user.
|
||||
* If the device was previously owned by a different user, image history is purged.
|
||||
*/
|
||||
public function linkToUser(string $mac, User $newOwner): Device
|
||||
{
|
||||
$mac = strtoupper($mac);
|
||||
$device = $this->repo->findOneBy(['mac' => $mac]);
|
||||
|
||||
if ($device === null) {
|
||||
$device = new Device();
|
||||
$device->setMac($mac);
|
||||
} elseif ($device->getUser() !== null && $device->getUser()->getId() !== $newOwner->getId()) {
|
||||
// Ownership transfer: purge prior image history for this device.
|
||||
// Full purge logic added in Epic 3 when Image/Approval entities exist.
|
||||
$this->purgeDeviceHistory($device);
|
||||
}
|
||||
|
||||
$device->setUser($newOwner);
|
||||
$device->setLinkedAt(new \DateTimeImmutable());
|
||||
$this->em->persist($device);
|
||||
$this->em->flush();
|
||||
|
||||
return $device;
|
||||
}
|
||||
|
||||
/** Remove all image approvals and rendered assets associated with this device. */
|
||||
private function purgeDeviceHistory(Device $device): void
|
||||
{
|
||||
// Stub: will cascade-delete via ORM relationships once Image/Approval entities are added in Epic 3.
|
||||
// Doctrine cascade on the Device→Approval relationship handles this automatically.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user