/**
  * @ApiDoc(
  *     resource=true
  * )
  *
  * Builder that creates a relational graph between users
  *
  * @param integer $targetId
  * @param integer $userId
  *
  * @return SimpleUserOverview[]
  *
  * @Get(
  *     "/protected/follow/{targetId}/relational-graph.{_format}",
  *     name="sen_follower.own_graph",
  *     requirements={"targetId":"\d+"}
  * )
  * @Get(
  *     "/follow/{userId}/{targetId}/relational-graph.{_format}",
  *     name="sen_follower.relational_graph",
  *     requirements={"targetId":"\d+", "userId":"\d+"}
  * )
  *
  * @View
  */
 public function indexAction($targetId, $userId = null)
 {
     $target = $this->resolveUser($targetId);
     $user = $this->resolveUser($userId);
     return array_map(function (User $user) {
         return SimpleUserOverview::fromAggregateRootDetails($user);
     }, $user->findRelationBetweenUsers($target));
 }
 /**
  * @ApiDoc(
  *     resource=true,
  *     description="Builds follower advices for a specific user",
  *     statusCodes={
  *         200="List sent successfully"
  *     }
  * )
  *
  * Advices followers for a specific user
  *
  * Note: the reload route is just used if a user has followed one of the adviced users to add a new one to the
  * advice list
  *
  * @param integer $amount
  *
  * @return \Sententiaregum\User\Domain\User
  *
  * @Get(
  *     "/protected/follow/advices.{_format}",
  *     name="sen_follower.advice_list",
  *     defaults={"amount":5},
  *     requirements={"amount":"\d+"}
  * )
  * @Get(
  *     "/protected/follow/reload-advices.{_format}",
  *     name="sen_follower.reload_list",
  *     defaults={"amount":1},
  *     requirements={"amount":"\d+"}
  * )
  *
  * @View
  */
 public function indexAction($amount)
 {
     $user = $this->resolveUser();
     /** @var \Sententiaregum\User\Application\FollowerService $followerService */
     $followerService = $this->get('sen.user.service.follower');
     return array_map(function (User $user) {
         return SimpleUserOverview::fromAggregateRootDetails($user);
     }, $followerService->adviceFollowersByUser($user, $amount));
 }
 public function testFillFromUser()
 {
     $credentials = new Credentials('Ma27', 'test-password');
     $profile = new UserDetails('*****@*****.**', new \DateTime(), new \DateTime());
     $user = new User($credentials, $profile);
     $simpleUser = SimpleUserOverview::fromAggregateRootDetails($user);
     $this->assertSame($simpleUser->getUsername(), 'Ma27');
     $this->assertSame($simpleUser->getLocale(), 'en');
     $this->assertSame($simpleUser->getEmail(), '*****@*****.**');
 }
 /**
  * @ApiDoc(
  *     resource=true,
  *     description="Returns the data of the current user",
  *     statusCodes={200="The user was loaded successfully"},
  *     requirements={
  *        {
  *             "name"="_format",
  *             "description"="The data format of the result",
  *             "requirement"="\w+",
  *             "dataType"="string"
  *         }
  *     }
  * )
  *
  * Returns the data of the current user
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * @Get("/protected/user.{_format}", name="sen_user.find_current")
  * @View()
  * @Security("has_role('ROLE_USER')")
  */
 public function getCurrentUserAction()
 {
     return SimpleUserOverview::fromAggregateRootDetails($this->getCurrentUser());
 }
 /**
  * @ApiDoc(
  *     resource=true,
  *     description="Loads all followers of a user",
  *     statusCodes={404="User not found", 200="List successfully sent"},
  *     requirements={
  *         {
  *             "name"="_format",
  *             "description"="The data format to return",
  *             "requirement"="\w+",
  *             "dataType"="string"
  *         },
  *         {
  *             "name"="userId",
  *             "description"="The user that follows the other user",
  *             "requirement"="\d+",
  *             "dataType"="integer"
  *         }
  *     }
  * )
  *
  * @param integer $userId
  *
  * @return User[]
  *
  * @Get("/protected/followers.{_format}", name="sen_follower.own_following")
  * @Get("/user/{userId}/followers.{_format}", name="sen_follower.following")
  *
  * @View
  */
 public function getFollowersByUserAction($userId = null)
 {
     /** @var \Sententiaregum\User\Domain\Contract\UserRepositoryInterface $repository */
     $repository = $this->get('sen.user.repository');
     return array_map(function (User $user) {
         return SimpleUserOverview::fromAggregateRootDetails($user);
     }, $repository->findFollowersByUser($this->resolveUser($userId)));
 }