mirror of
https://github.com/stan220/chixana.git
synced 2026-09-08 16:28:41 +00:00
Added ability to add chix for friend.
This commit is contained in:
@@ -54,6 +54,24 @@ class ChixController extends AbstractController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/add/{userId}")
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function addFriend(Request $request): Response
|
||||||
|
{
|
||||||
|
$userId = $this->getUserId($request);
|
||||||
|
|
||||||
|
$user = $this->getDoctrine()->getRepository(\App\Entity\User::class)
|
||||||
|
->find($userId);
|
||||||
|
|
||||||
|
$chixId = $this->chixService->add($user);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('chix_app_chix_view', compact('chixId'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/{chixId}/approve", requirements={"chixId"="\d+"})
|
* @Route("/{chixId}/approve", requirements={"chixId"="\d+"})
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
@@ -79,9 +97,20 @@ class ChixController extends AbstractController
|
|||||||
$chixId = (int) $request->get('chixId');
|
$chixId = (int) $request->get('chixId');
|
||||||
|
|
||||||
if ($chixId < 1) {
|
if ($chixId < 1) {
|
||||||
throw new \InvalidArgumentException("Chix not found: $chixId");
|
throw new \InvalidArgumentException("Param `chixId` isn't correct: $chixId");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $chixId;
|
return $chixId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getUserId(Request $request): int
|
||||||
|
{
|
||||||
|
$userId = (int) $request->get('userId');
|
||||||
|
|
||||||
|
if ($userId < 1) {
|
||||||
|
throw new \InvalidArgumentException("Param `userId` isn't correct: $userId");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $userId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user