Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- namespace App\Service\Api;
- use App\Entity\Account;
- use App\Entity\Application;
- use App\Entity\User;
- use App\Model\ApplicationModel;
- use App\Model\Interface\BaseModelInterface;
- use App\Model\Pagination\PaginatedModel;
- use App\Service\Api\Interface\ByModelApiServiceInterface;
- use App\Service\ApiService;
- use App\Service\Entity\ApplicationService;
- use App\Service\Entity\UserService;
- use App\Trait\Service\Api\ByModelApiTrait;
- /**
- * @method ApplicationModel map(Application $entity, array $context, int $tree = 0, array $propNameLimit = [], int $mappingModelHelperTree = -1, bool $showArchived = true)
- * @method ApplicationModel[] mapAll(array $entities, array $context = [])
- * @method ApplicationModel get(?User $currentUser = null, ?string $id = null, array $criteria = [], array $context = [], array $orderBy = [], bool $criteriaAlreadyPrepared = false, array $limits = [])
- * @method PaginatedModel getAll(?User $currentUser = null, ?int $limit = null, int $offset = 0, array $filter = [], string $search = '', array $context = [], array $orderBy = [], bool $criteriaAlreadyPrepared = false, bool $isAccurateSearch = false)
- * @method Application|null findByModel(?ApplicationModel $model, Account $account = null, array $criteria = [], $createNonExistent = false)
- * @method Application getByModel(?ApplicationModel $model, Account $account = null, array $criteria = [], $createNonExistent = false)
- */
- class ApplicationApiService extends ApiService implements ByModelApiServiceInterface
- {
- use ByModelApiTrait;
- public function __construct(
- private readonly ApplicationService $applicationService,
- private readonly UserService $userService,
- ) {
- }
- /**
- * @param ApplicationModel $model
- */
- #[\Override]
- public function create(
- BaseModelInterface $model,
- User $currentUser,
- array $context,
- ): ApplicationModel {
- $isThirdParty = $model->getIsThirdParty();
- $vendor = $isThirdParty ? $currentUser : $this->userService->get(criteria: ['phone' => '00000000000'], criteriaAlreadyPrepared: true);
- $entity = $this->applicationService->create(
- vendor: $vendor,
- isThirdParty: $isThirdParty,
- name: $model->getName(),
- uid: $model->getUid(),
- site: $model->getSite(),
- developer: $model->getDeveloper(),
- helpLink: $model->getHelpLink(),
- note: $model->getNote(),
- );
- return $this->map($entity, $context);
- }
- /**
- * @param ApplicationModel $model
- */
- #[\Override]
- public function update(
- BaseModelInterface $model,
- User $currentUser,
- array $context,
- ): ApplicationModel {
- $entity = $this->getByModel(model: $model);
- $this->applicationService->update(
- application: $entity,
- name: $model->getName(),
- uid: $model->getUid(),
- site: $model->getSite(),
- developer: $model->getDeveloper(),
- helpLink: $model->getHelpLink(),
- note: $model->getNote(),
- );
- return $this->map($entity, $context);
- }
- public function updateSecretKey(
- string $id,
- User $currentUser,
- array $context,
- ): ApplicationModel {
- $entity = $this->applicationService->get($id);
- $this->applicationService->updateSecretKey($entity);
- return $this->map($entity, $context);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment