currentUserId = $UserId; $this->mailManager = $mailManager; $this->accountService = $accountService; } /** * @NoAdminRequired * * @param string $displayName * @param string $color * * @return JSONResponse * @throws ClientException */ #[TrapError] public function create(string $displayName, string $color): JSONResponse { $this->validateDisplayName($displayName); $this->validateColor($color); $tag = $this->mailManager->createTag($displayName, $color, $this->currentUserId); return new JSONResponse($tag); } /** * @NoAdminRequired * * @param int $id * @param string $displayName * @param string $color * * @return JSONResponse * @throws ClientException */ #[TrapError] public function update(int $id, string $displayName, string $color): JSONResponse { $this->validateDisplayName($displayName); $this->validateColor($color); $tag = $this->mailManager->updateTag($id, $displayName, $color, $this->currentUserId); return new JSONResponse($tag); } /** * @NoAdminRequired * * @throws ClientException */ #[TrapError] public function delete(int $id, int $accountId): JSONResponse { try { $accounts = $this->accountService->findByUserId($this->currentUserId); } catch (DoesNotExistException $e) { return new JSONResponse([], Http::STATUS_FORBIDDEN); } $this->mailManager->deleteTag($id, $this->currentUserId, $accounts); return new JSONResponse([$id]); } /** * @throws ClientException */ private function validateDisplayName(string $displayName): void { if (mb_strlen($displayName) > 128) { throw new ClientException('The maximum length for displayName is 128'); } } /** * @throws ClientException */ private function validateColor(string $color): void { if (mb_strlen($color) > 9) { throw new ClientException('The maximum length for color is 9'); } } }