mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ add comment anonymous, move route params to custom_url instead of id
This commit is contained in:
parent
a005aa0f97
commit
5a463695c3
16
README.md
16
README.md
@ -174,14 +174,22 @@ DATABASE_URL=mysql://database_user:db_user_password@127.0.0.1:3306/database_name
|
||||
this file is not versionned and should stay like this.
|
||||
|
||||
## cronjob to delete expired polls
|
||||
add this line in your crontab to run the clearance of expired polls everyday at 0h00.
|
||||
```
|
||||
0 0 * * * wget http://MYWEBSITE/api/v1/poll/clean-polls
|
||||
```
|
||||
you can open your crontabl in command line with :
|
||||
```
|
||||
crontab -e
|
||||
```
|
||||
|
||||
add this line in your crontab to run the clearance of expired polls everyday at 0h00.
|
||||
```
|
||||
0 0 * * * wget http://MYWEBSITE/api/v1/poll/clean-polls
|
||||
```
|
||||
Cronjob to send mails from the swiftmailer spool.
|
||||
```
|
||||
* * * * * php /var/www/html/date-poll-api/bin/console swiftmailer:spool:send
|
||||
```
|
||||
you can disable the spooling, check the docs.
|
||||
|
||||
|
||||
# About
|
||||
|
||||
made by B. Lemoine, aka Tykayn, for the framadate funky front end project, a polling libre software.
|
||||
|
@ -35,7 +35,7 @@ class PollController extends AbstractController {
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/new", name="poll_new", methods={"POST"})
|
||||
* @Route("/new", name="poll_new_old", methods={"POST"})
|
||||
*/
|
||||
public function new( Request $request ): Response {
|
||||
$poll = new Poll();
|
||||
|
@ -9,7 +9,6 @@ use App\Entity\Poll;
|
||||
use DateTime;
|
||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\SerializerBuilder;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
@ -20,22 +19,24 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
/**
|
||||
* Class DefaultController
|
||||
* @package App\Controller
|
||||
* @Route("/api/v1/comment",name="api_")
|
||||
* @Route("/api/v1/comment",
|
||||
* name="api_comment_")
|
||||
*/
|
||||
class CommentController extends EmailsController {
|
||||
class CommentController extends EmailsController
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get(
|
||||
* path = "/poll/{id}",
|
||||
* name = "get_poll_comment",
|
||||
* requirements = {"id"="\d+"}
|
||||
* path = "/poll/{customUrl}",
|
||||
* name = "get_poll_comment"
|
||||
* )
|
||||
*/
|
||||
public
|
||||
function getPollCommentsAction(
|
||||
SerializerInterface $serializer,
|
||||
Poll $poll
|
||||
) {
|
||||
)
|
||||
{
|
||||
$jsonResponse = $serializer->serialize([
|
||||
'message' => 'here are your comments of the poll',
|
||||
'data' => $poll->getComments(),
|
||||
@ -52,17 +53,71 @@ class CommentController extends EmailsController {
|
||||
|
||||
/**
|
||||
* add a comment on a poll
|
||||
* @Post(
|
||||
* path = "/poll/{id}",
|
||||
* name = "new_comment",
|
||||
* requirements = {"content"="\w+", "id"="\d+"}
|
||||
* @Route(
|
||||
* "/poll/{customUrl}",
|
||||
* "_new_comment",
|
||||
* methods={"POST"}
|
||||
* )
|
||||
*/
|
||||
public
|
||||
function newCommentAction(
|
||||
Poll $poll,
|
||||
Request $request
|
||||
) {
|
||||
)
|
||||
{
|
||||
|
||||
$data = json_decode($request->getContent(), true);
|
||||
// return $this->json(['pseudo' => $data["pseudo"]], 404);
|
||||
|
||||
if (!$poll) {
|
||||
return $this->json(['message' => 'poll not found'], 404);
|
||||
}
|
||||
|
||||
$comment = new Comment();
|
||||
$owner = new Owner();
|
||||
$owner
|
||||
->setPseudo($data["pseudo"])
|
||||
->setEmail('anonymous@example.com');
|
||||
|
||||
$comment->setOwner($owner)
|
||||
->setPseudo($data["pseudo"])
|
||||
->setText($data["text"])
|
||||
->setCreatedAt(new DateTime())
|
||||
->setPoll($poll);
|
||||
$owner
|
||||
->addComment($comment);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($owner);
|
||||
$em->persist($comment);
|
||||
$em->flush();
|
||||
|
||||
if ($poll->getMailOnComment()) {
|
||||
$this->sendCommentNotificationAction($owner, $comment);
|
||||
}
|
||||
|
||||
|
||||
return $this->json( $comment->display(),
|
||||
|
||||
|
||||
201);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* add a comment on a poll
|
||||
* @Route(
|
||||
* "/poll/{customUrl}/by-owner",
|
||||
* "_new_comment_by_owner",
|
||||
* methods={"POST"}
|
||||
* )
|
||||
*/
|
||||
public
|
||||
function newCommentByOwnerAction(
|
||||
Poll $poll,
|
||||
Request $request
|
||||
)
|
||||
{
|
||||
if (!$poll) {
|
||||
return $this->json(['message' => 'poll not found'], 404);
|
||||
}
|
||||
@ -82,7 +137,7 @@ class CommentController extends EmailsController {
|
||||
// manage existing or new Owner
|
||||
if (!$foundOwner) {
|
||||
$foundOwner = new Owner();
|
||||
$foundOwner->setPseudo( $data[ 'email' ] )
|
||||
$foundOwner->setPseudo($data['pseudo'])
|
||||
->setEmail($data['email'])
|
||||
->setModifierToken(uniqid('', true));
|
||||
}
|
||||
@ -146,9 +201,8 @@ class CommentController extends EmailsController {
|
||||
/**
|
||||
* Erase all comments of a poll
|
||||
* @Delete(
|
||||
* path = "/poll/{id}",
|
||||
* name = "poll_comments_delete",
|
||||
* requirements = {"accessToken"="\w+", "id"="\d+"}
|
||||
* path = "/poll/{customUrl}",
|
||||
* name = "poll_comments_delete"
|
||||
* )
|
||||
*
|
||||
* @param Poll $poll
|
||||
@ -160,7 +214,8 @@ class CommentController extends EmailsController {
|
||||
function deletePollCommentsAction(
|
||||
Poll $poll,
|
||||
$accessToken
|
||||
) {
|
||||
)
|
||||
{
|
||||
if ($accessToken == $poll->getAdminKey()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$length = count($poll->getComments());
|
||||
|
@ -295,7 +295,7 @@ class PollController extends EmailsController
|
||||
/**
|
||||
* @Route(
|
||||
* "/",
|
||||
* "_new_poll",
|
||||
* "_new_poll_v1",
|
||||
* methods={"POST"}
|
||||
* )
|
||||
* @param Request $request
|
||||
|
Loading…
Reference in New Issue
Block a user