src/Controller/UserGroup/PublicGroupController.php line 121

Open in your IDE?
  1. <?php
  2. namespace App\Controller\UserGroup;
  3. use App\Entity\Member;
  4. use App\Entity\UserGroup;
  5. use App\Service\UserGroups\GroupMemberService;
  6. use App\Service\UserGroups\GroupService;
  7. use App\StructSerializer\Main\StructGroup;
  8. use App\StructSerializer\Main\StructOptions;
  9. use App\StructSerializer\Main\StructSerializer;
  10. use Nelmio\ApiDocBundle\Annotation\Model;
  11. use Swagger\Annotations as SWG;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. /**
  17.  * @Route("/api/public/group")
  18.  */
  19. class PublicGroupController extends AbstractController
  20. {
  21.     protected GroupService $service;
  22.     protected GroupMemberService $groupMemberService;
  23.     protected StructSerializer $structSerializer;
  24.     public function __construct(GroupService $serviceGroupMemberService $groupMemberService,
  25.         StructSerializer $structSerializer)
  26.     {
  27.         $this->service $service;
  28.         $this->structSerializer $structSerializer;
  29.         $this->groupMemberService $groupMemberService;
  30.     }
  31.     /**
  32.      * @SWG\Get(tags={"Groups"},
  33.      *
  34.      *    @SWG\Response(response=200, description="Details for a group",
  35.      *
  36.      *     @SWG\Schema(ref=@Model(type=App\Entity\UserGroup::class, groups={"grouplist", "groupdetails"}))),
  37.      *
  38.      *    @SWG\Parameter(name="group", in="path", type="integer", description="ID of the group entity")
  39.      * )
  40.      *
  41.      * @Route("/{group}", methods={ "GET"}, requirements={"group": "\d+"})
  42.      */
  43.     public function group(UserGroup $group): JsonResponse
  44.     {
  45.         $options StructOptions::create(StructGroup::SHORT);
  46.         return new JsonResponse($this->structSerializer->toArray($options$group));
  47.     }
  48.     /**
  49.      * @SWG\Get(tags={"Groups"},
  50.      *
  51.      *    @SWG\Response(response=200, description="Details for a group by its url slug",
  52.      *
  53.      *     @SWG\Schema(ref=@Model(type=App\Entity\UserGroup::class, groups={"grouplist", "groupdetails"}))),
  54.      *
  55.      *    @SWG\Parameter(name="slug", in="path", type="string", required=true, description="Slug of the group entity")
  56.      * )
  57.      *
  58.      * @Route("/{slug}", methods={"GET"})
  59.      */
  60.     public function slug(string $slug): JsonResponse
  61.     {
  62.         if (!$group $this->service->findBySlug($slug)) {
  63.             throw $this->createNotFoundException();
  64.         }
  65.         $options StructOptions::create(StructGroup::SHORT);
  66.         return new JsonResponse($this->structSerializer->toArray($options$group));
  67.     }
  68.     /**
  69.      * @SWG\Get(tags={"Groups"},
  70.      *
  71.      *    @SWG\Response(response=200, description="Paginated list of public group entities",
  72.      *
  73.      *     @SWG\Schema(ref=@Model(type=App\Entity\UserGroup::class, groups={"grouplist"}))),
  74.      *
  75.      *    @SWG\Parameter(name="category", in="path", type="integer", required=true, description="Group category, zero for all entities"),
  76.      *    @SWG\Parameter(name="page", in="path", type="integer", required=true, description="Requested page for pagination"),
  77.      *    @SWG\Parameter(name="limit", in="query", type="integer", required=false, default=20, description="Number of items per page for pagination")
  78.      * )
  79.      *
  80.      * @Route("/index/public/{category}/{page}", methods={"GET"}, requirements={"page": "\d+", "category": "\d+"})
  81.      */
  82.     public function publicindex(Request $requestint $categoryint $page 1): JsonResponse
  83.     {
  84.         $limit $request->query->getInt('limit'20);
  85.         $paginator $this->service->getPublicGroupIndex($category$page$limit);
  86.         $options StructOptions::create(StructGroup::SHORT);
  87.         return new JsonResponse([
  88.             'data' => $this->structSerializer->multipleToArray($options$paginator),
  89.             'total' => $paginator->count(),
  90.         ]);
  91.     }
  92.     /**
  93.      * @SWG\Get(tags={"Groups"},
  94.      *
  95.      *    @SWG\Response(response=200, description="Paginated list of top-rated group entities",
  96.      *
  97.      *     @SWG\Schema(ref=@Model(type=App\Entity\UserGroup::class, groups={"grouplist"}))),
  98.      *
  99.      *    @SWG\Parameter(name="category", in="path", type="integer", required=true, description="Group category, zero for all entities"),
  100.      *    @SWG\Parameter(name="page", in="path", type="integer", required=true, description="Requested page for pagination"),
  101.      *    @SWG\Parameter(name="limit", in="query", type="integer", required=false, default=20, description="Number of items per page for pagination")
  102.      * )
  103.      *
  104.      * @Route("/index/top/{category}/{page}", methods={"GET"}, requirements={"page": "\d+", "category": "\d+"})
  105.      */
  106.     public function topindex(Request $requestint $categoryint $page): JsonResponse
  107.     {
  108.         $limit $request->query->getInt('limit'20);
  109.         $paginator $this->service->getTopRatedGroupIndex($category$page$limit);
  110.         $options StructOptions::create(StructGroup::SHORT);
  111.         return new JsonResponse([
  112.             'data' => $this->structSerializer->multipleToArray($options$paginator),
  113.             'total' => $paginator->count(),
  114.         ]);
  115.     }
  116.     /**
  117.      * @SWG\Get(tags={"Groups"},
  118.      *
  119.      *    @SWG\Response(response=200, description="Paginated list of invite-only group entities",
  120.      *
  121.      *     @SWG\Schema(ref=@Model(type=App\Entity\UserGroup::class, groups={"grouplist"}))),
  122.      *
  123.      *    @SWG\Parameter(name="category", in="path", type="integer", required=true, description="Group category, zero for all entities"),
  124.      *    @SWG\Parameter(name="page", in="path", type="integer", required=true, description="Requested page for pagination"),
  125.      *    @SWG\Parameter(name="limit", in="query", type="integer", required=false, default=20, description="Number of items per page for pagination")
  126.      * )
  127.      *
  128.      * @Route("/index/inviteonly/{category}/{page}", methods={"GET"}, requirements={"page": "\d+", "category": "\d+"})
  129.      */
  130.     public function inviteonlyindex(Request $requestint $categoryint $page 1): JsonResponse
  131.     {
  132.         $limit $request->query->getInt('limit'20);
  133.         $paginator $this->service->getInviteOnlyGroupIndex($category$page$limit);
  134.         $options StructOptions::create(StructGroup::SHORT);
  135.         return new JsonResponse([
  136.             'data' => $this->structSerializer->multipleToArray($options$paginator),
  137.             'total' => $paginator->count(),
  138.         ]);
  139.     }
  140.     /**
  141.      * @SWG\Get(tags={"Groups"},
  142.      *
  143.      *    @SWG\Response(response=200, description="List of public group membership entities for given member",
  144.      *
  145.      *     @SWG\Schema(ref=@Model(type=App\Entity\UserGroupMember::class, groups={"membergrouplist", "groupdetails"}))),
  146.      *
  147.      *    @SWG\Parameter(name="member", in="path", type="integer", required=true, description="Get group memberships of a given member")
  148.      * )
  149.      *
  150.      * @Route("/member/{member}", methods={"GET"}, requirements={"member": "\d+"})
  151.      */
  152.     public function publicGroups(Member $member): JsonResponse
  153.     {
  154.         $paginator $this->groupMemberService->getGroupMembershipsForMember($membernull199);
  155.         $options StructOptions::create(StructGroup::SHORT);
  156.         return new JsonResponse([
  157.             'data' => $this->structSerializer->multipleToArray($options$paginator),
  158.             'total' => $paginator->count(),
  159.         ]);
  160.     }
  161. }