spasmie

Untitled

Aug 19th, 2025
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.53 KB | None | 0 0
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Service\Api;
  6.  
  7. use App\Entity\Account;
  8. use App\Entity\Application;
  9. use App\Entity\User;
  10. use App\Model\ApplicationModel;
  11. use App\Model\Interface\BaseModelInterface;
  12. use App\Model\Pagination\PaginatedModel;
  13. use App\Service\Api\Interface\ByModelApiServiceInterface;
  14. use App\Service\ApiService;
  15. use App\Service\Entity\ApplicationService;
  16. use App\Service\Entity\UserService;
  17. use App\Trait\Service\Api\ByModelApiTrait;
  18.  
  19. /**
  20.  * @method ApplicationModel   map(Application $entity, array $context, int $tree = 0, array $propNameLimit = [], int $mappingModelHelperTree = -1, bool $showArchived = true)
  21.  * @method ApplicationModel[] mapAll(array $entities, array $context = [])
  22.  * @method ApplicationModel   get(?User $currentUser = null, ?string $id = null, array $criteria = [], array $context = [], array $orderBy = [], bool $criteriaAlreadyPrepared = false, array $limits = [])
  23.  * @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)
  24.  * @method Application|null   findByModel(?ApplicationModel $model, Account $account = null, array $criteria = [], $createNonExistent = false)
  25.  * @method Application        getByModel(?ApplicationModel $model, Account $account = null, array $criteria = [], $createNonExistent = false)
  26.  */
  27. class ApplicationApiService extends ApiService implements ByModelApiServiceInterface
  28. {
  29.     use ByModelApiTrait;
  30.  
  31.     public function __construct(
  32.         private readonly ApplicationService $applicationService,
  33.         private readonly UserService $userService,
  34.     ) {
  35.     }
  36.  
  37.     /**
  38.      * @param ApplicationModel $model
  39.      */
  40.     #[\Override]
  41.    public function create(
  42.         BaseModelInterface $model,
  43.         User $currentUser,
  44.         array $context,
  45.     ): ApplicationModel {
  46.         $isThirdParty = $model->getIsThirdParty();
  47.  
  48.         $vendor = $isThirdParty ? $currentUser : $this->userService->get(criteria: ['phone' => '00000000000'], criteriaAlreadyPrepared: true);
  49.  
  50.         $entity = $this->applicationService->create(
  51.             vendor: $vendor,
  52.             isThirdParty: $isThirdParty,
  53.             name: $model->getName(),
  54.             uid: $model->getUid(),
  55.             site: $model->getSite(),
  56.             developer: $model->getDeveloper(),
  57.             helpLink: $model->getHelpLink(),
  58.             note: $model->getNote(),
  59.         );
  60.  
  61.         return $this->map($entity, $context);
  62.     }
  63.  
  64.     /**
  65.      * @param ApplicationModel $model
  66.      */
  67.     #[\Override]
  68.    public function update(
  69.         BaseModelInterface $model,
  70.         User $currentUser,
  71.         array $context,
  72.     ): ApplicationModel {
  73.         $entity = $this->getByModel(model: $model);
  74.  
  75.         $this->applicationService->update(
  76.             application: $entity,
  77.             name: $model->getName(),
  78.             uid: $model->getUid(),
  79.             site: $model->getSite(),
  80.             developer: $model->getDeveloper(),
  81.             helpLink: $model->getHelpLink(),
  82.             note: $model->getNote(),
  83.         );
  84.  
  85.         return $this->map($entity, $context);
  86.     }
  87.  
  88.     public function updateSecretKey(
  89.         string $id,
  90.         User $currentUser,
  91.         array $context,
  92.     ): ApplicationModel {
  93.         $entity = $this->applicationService->get($id);
  94.         $this->applicationService->updateSecretKey($entity);
  95.  
  96.         return $this->map($entity, $context);
  97.     }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment