src/Lms/UserInterface/Rest/Controller/UsersController.php line 41

Open in your IDE?
  1. <?php
  2. namespace CodersLab\Lms\UserInterface\Rest\Controller;
  3. use CodersLab\Lms\Modules\Courses\Application\Query\ProductFilter;
  4. use CodersLab\Lms\Modules\Courses\Application\Query\ProductQuery;
  5. use CodersLab\Lms\Modules\IdentityAccess\Application\Command\SendGithubTeamInvitation;
  6. use CodersLab\Lms\Modules\IdentityAccess\Application\Query\UserQuery;
  7. use CodersLab\Lms\SharedKernel\Application\Command\UpdateShowWelcomePage;
  8. use CodersLab\Lms\SharedKernel\Application\Filter;
  9. use CodersLab\Lms\SharedKernel\Application\Response\LmsApiResponse;
  10. use CodersLab\Lms\SharedKernel\Application\SecurityContext;
  11. use CodersLab\Lms\SharedKernel\Domain\Bus\CommandBus;
  12. use Nelmio\ApiDocBundle\Annotation\Model;
  13. use OpenApi\Annotations as OA;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. /**
  18.  * @OA\Tag(name="User")
  19.  */
  20. final class UsersController
  21. {
  22.     public function __construct(
  23.         private SecurityContext $securityContext,
  24.         private ProductQuery $productQuery,
  25.         private CommandBus $commandBus,
  26.         private UserQuery $userQuery
  27.     ) {
  28.     }
  29.     /**
  30.      * @Route("/users/me", name="user_me", methods={"GET"})
  31.      * @OA\Response(
  32.      *     response=200,
  33.      *     description="Logged User",
  34.      *     @OA\Schema(ref=@Model(type="CodersLab\Lms\Modules\IdentityAccess\Application\Query\Model\User"))
  35.      * )
  36.      */
  37.     public function currentUser(): LmsApiResponse
  38.     {
  39.         $userId $this->securityContext->getLoggedUser()->id();
  40.         $user $this->userQuery->getById($userId);
  41.         if ($this->userQuery->hasCourseWithRepositories($userId) && $user->getGithub() === null) {
  42.             $user->showGithubWarning();
  43.         }
  44.         return new LmsApiResponse($user);
  45.     }
  46.     /**
  47.      * @Route("/user/direct-access/list", name="user_direct_access_list", methods={"GET"})
  48.      * @OA\Response(
  49.      *     response=200,
  50.      *     description="User menu",
  51.      *     @OA\JsonContent(type="array", @OA\Items(ref=@Model(type="CodersLab\Lms\Modules\Courses\Application\Query\Model\Product")))
  52.      * )
  53.      */
  54.     public function menu(): LmsApiResponse
  55.     {
  56.         $productFilter = new ProductFilter(new Filter());
  57.         $productFilter->getFilter()->disablePagination();
  58.         $productFilter->forUser($this->securityContext->getLoggedUser()->id());
  59.         $this->productQuery->find($productFilter);
  60.         return new LmsApiResponse($this->productQuery->find($productFilter));
  61.     }
  62.     /**
  63.      * @Route("/user/{id}/welcome-page", name="update_show_welcome_page", methods={"PUT"})
  64.      * @OA\Parameter(name="id", in="path", @OA\Schema(type="string"), required=true)
  65.      * @OA\RequestBody(
  66.      *     @OA\MediaType(
  67.      *          mediaType="application/x-www-form-urlencoded",
  68.      *          @OA\Schema(
  69.      *              required={"show"},
  70.      *              @OA\Property(property="show", type="boolean")
  71.      *          )
  72.      *     )
  73.      * )
  74.      * @OA\Response(
  75.      *     response=200,
  76.      *     description="User menu",
  77.      *     @OA\Schema(ref=@Model(type="CodersLab\Lms\Modules\IdentityAccess\Application\Query\Model\Menu"))
  78.      * )
  79.      */
  80.     public function updateShowWelcomePage(string $idRequest $request): Response
  81.     {
  82.         $this->commandBus->dispatch(new UpdateShowWelcomePage($id$request->request->getBoolean('show')));
  83.         return new Response();
  84.     }
  85.     /**
  86.      * @Route("/student/{githubLogin}/instance/{instanceId}", name="user_invite", methods={"PUT"})
  87.      * @OA\Response(
  88.      *     response=200,
  89.      *     description="Command executed"
  90.      * )
  91.      */
  92.     public function inviteStudentToOrganisation(string $githubLoginstring $instanceId): Response
  93.     {
  94.         $user $this->userQuery->getByGithubLogin($githubLogin);
  95.         $this->commandBus->dispatch(new SendGithubTeamInvitation($user->getGithubId(), $instanceId));
  96.         return new Response();
  97.     }
  98. }