mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
📖 some doc and start to create a vote
This commit is contained in:
parent
5d74fb9780
commit
6dd7b46e7a
41
README.md
41
README.md
@ -1,38 +1,51 @@
|
|||||||
#Funky Framadate API
|
#Funky Framadate API
|
||||||
Experimental REST backend in symfony 4 for Funky framadate.
|
Experimental REST backend in symfony 4 for Funky framadate frontend.
|
||||||
|
https://framagit.org/framasoft/framadate/funky-framadate-front
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
***
|
***
|
||||||
# Dev
|
# Development
|
||||||
install dependencies with Composer
|
install dependencies with Composer
|
||||||
|
|
||||||
launch local server with
|
|
||||||
|
there are examples of request to make it all work.
|
||||||
|
## Getting started
|
||||||
|
### install the vendors
|
||||||
|
```bash
|
||||||
|
composer install
|
||||||
|
```
|
||||||
|
### initiate the database
|
||||||
|
```bash
|
||||||
|
php bin/console doctrine:schema:create
|
||||||
|
```
|
||||||
|
### launch local server with
|
||||||
```bash
|
```bash
|
||||||
php bin/console server:run
|
php bin/console server:run
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# Production
|
# Production
|
||||||
set a virtual host on your server, configure CORS access to have the API to work.
|
set a virtual host on your server, configure CORS access to have the API to work.
|
||||||
configure database access in a .env.local file , replace variables
|
configure database access in a .env.local file , replace variables
|
||||||
DATABASE_URL=mysql://database_user:db_user_password@127.0.0.1:3306/database_name
|
DATABASE_URL=mysql://database_user:db_user_password@127.0.0.1:3306/database_name
|
||||||
this file is not versionned
|
this file is not versionned
|
||||||
|
|
||||||
initiate the database
|
|
||||||
```bash
|
|
||||||
php bin/console doctrine:schema:create
|
|
||||||
```
|
|
||||||
## cronjob to delete expired polls
|
## cronjob to delete expired polls
|
||||||
add this line in your crontab to run the clearance of expired polls everyday at 0h00.
|
add this line in your crontab to run the clearance of expired polls everyday at 0h00.
|
||||||
```
|
```
|
||||||
0 0 * * * wget http://MYWEBSITE/api/v1/clean-polls
|
0 0 * * * wget http://MYWEBSITE/api/v1/clean-polls
|
||||||
```
|
```
|
||||||
you can open your crontabl in command line with
|
you can open your crontabl in command line with :
|
||||||
|
```
|
||||||
crontab -e
|
crontab -e
|
||||||
|
```
|
||||||
# About
|
# About
|
||||||
|
|
||||||
made by B. Lemoine, aka Tykayn, for the framadate funky front end project, a polling libre software.
|
made by B. Lemoine, aka Tykayn, for the framadate funky front end project, a polling libre software.
|
||||||
## contacts
|
## contacts
|
||||||
contact@cipherbliss.com
|
* contact@cipherbliss.com
|
||||||
https://mastodon.cipherbliss.com/@tykayn
|
* https://mastodon.cipherbliss.com/@tykayn
|
||||||
https://keybase.io/tykayn
|
* https://keybase.io/tykayn
|
||||||
https://twitter.com/tykayn
|
* https://twitter.com/tykayn
|
||||||
https://cipherbliss.com
|
* https://cipherbliss.com
|
||||||
|
26
examples.md
Normal file
26
examples.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# API example
|
||||||
|
after having setup your project and database, and having a local server running you can rest these commands
|
||||||
|
```
|
||||||
|
POST
|
||||||
|
http://127.0.0.1:8000/api/v1/poll/98/vote
|
||||||
|
Content-Type:"pplication/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"pseudo": "Mario Bros",
|
||||||
|
"email": "MarioBros@tktest.com",
|
||||||
|
"votes": [{
|
||||||
|
"choice_id": 287,
|
||||||
|
"value": "yes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"choice_id": 288,
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"choice_id": 289,
|
||||||
|
"value": "maybe"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
```
|
@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
/**
|
/**
|
||||||
* Class DefaultController
|
* Class DefaultController
|
||||||
* @package App\Controller
|
* @package App\Controller
|
||||||
* @Route("/api/v1",name="api_")
|
* @Route("/api/v1/",name="api_")
|
||||||
*/
|
*/
|
||||||
class DefaultController extends AbstractController {
|
class DefaultController extends AbstractController {
|
||||||
/**
|
/**
|
||||||
@ -260,9 +260,9 @@ class DefaultController extends AbstractController {
|
|||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function newVoteStackAction( Poll $poll, Request $request ) {
|
public function newVoteStackAction( Poll $poll, Request $request ) {
|
||||||
// if ( ! $poll ) {
|
if ( ! $poll ) {
|
||||||
// return $this->json( [ 'message' => 'poll not found' ], 404 );
|
return $this->json( [ 'message' => 'poll not found' ], 404 );
|
||||||
// }
|
}
|
||||||
// $data = $request->getContent();
|
// $data = $request->getContent();
|
||||||
//
|
//
|
||||||
// $serializer = SerializerBuilder::create()->build();
|
// $serializer = SerializerBuilder::create()->build();
|
||||||
|
@ -28,10 +28,10 @@ class AppPollFixtures extends Fixture {
|
|||||||
->setModifierToken( uniqid() );
|
->setModifierToken( uniqid() );
|
||||||
|
|
||||||
$poll = new Poll();
|
$poll = new Poll();
|
||||||
$poll->setTitle( 'citron ou orange' );
|
$poll->setTitle( 'citron ou orange' )
|
||||||
$poll->setDescription( 'votre sorbert préféré' );
|
->setDescription( 'votre sorbert préféré' )
|
||||||
$poll->setAdminKey( uniqid() );
|
->setAdminKey( uniqid() )
|
||||||
$poll->setModificationPolicy( 'nobody' );
|
->setModificationPolicy( 'nobody' );
|
||||||
$poll->setMailOnVote( true );
|
$poll->setMailOnVote( true );
|
||||||
$poll->setOwner( $owner );
|
$poll->setOwner( $owner );
|
||||||
$owner->addPoll( $poll );
|
$owner->addPoll( $poll );
|
||||||
@ -58,13 +58,13 @@ class AppPollFixtures extends Fixture {
|
|||||||
$voteA
|
$voteA
|
||||||
->setPoll( $poll )
|
->setPoll( $poll )
|
||||||
->setStackOfVotes( $stack1 )
|
->setStackOfVotes( $stack1 )
|
||||||
->setValue( [ "yes" ] )
|
->setValue( "yes" )
|
||||||
->setChoice( $choiceA );
|
->setChoice( $choiceA );
|
||||||
$voteB = new Vote();
|
$voteB = new Vote();
|
||||||
$voteB
|
$voteB
|
||||||
->setPoll( $poll )
|
->setPoll( $poll )
|
||||||
->setStackOfVotes( $stack1 )
|
->setStackOfVotes( $stack1 )
|
||||||
->setValue( [ "yes" ] )
|
->setValue( "yes" )
|
||||||
->setChoice( $choiceB );
|
->setChoice( $choiceB );
|
||||||
|
|
||||||
$stack1->setPseudo( 'chuck norris' );
|
$stack1->setPseudo( 'chuck norris' );
|
||||||
@ -84,7 +84,7 @@ class AppPollFixtures extends Fixture {
|
|||||||
$voteA
|
$voteA
|
||||||
->setPoll( $poll )
|
->setPoll( $poll )
|
||||||
->setStackOfVotes( $stack2 )
|
->setStackOfVotes( $stack2 )
|
||||||
->setValue( [ "maybe" ] )
|
->setValue( "maybe" )
|
||||||
->setChoice( $choiceA );
|
->setChoice( $choiceA );
|
||||||
|
|
||||||
$manager->persist( $stack2 );
|
$manager->persist( $stack2 );
|
||||||
@ -201,6 +201,54 @@ class AppPollFixtures extends Fixture {
|
|||||||
|
|
||||||
$manager->persist( $poll );
|
$manager->persist( $poll );
|
||||||
|
|
||||||
|
$stack = new StackOfVotes();
|
||||||
|
$stack->setPseudo( 'Wulfila' );
|
||||||
|
$stack
|
||||||
|
->setPoll( $poll )
|
||||||
|
->setOwner( $voter );
|
||||||
|
|
||||||
|
$vote = new Vote();
|
||||||
|
$vote
|
||||||
|
->setPoll( $poll )
|
||||||
|
->setStackOfVotes( $stack )
|
||||||
|
->setValue( "yes" )
|
||||||
|
->setChoice( $poll->getChoices()[ 2 ] );
|
||||||
|
$vote = new Vote();
|
||||||
|
$vote
|
||||||
|
->setPoll( $poll )
|
||||||
|
->setStackOfVotes( $stack )
|
||||||
|
->setValue( "maybe" )
|
||||||
|
->setChoice( $poll->getChoices()[ 1 ] );
|
||||||
|
|
||||||
|
$manager->persist( $stack );
|
||||||
|
|
||||||
|
$stack = new StackOfVotes();
|
||||||
|
$stack->setPseudo( 'Tykayn' );
|
||||||
|
$stack
|
||||||
|
->setPoll( $poll )
|
||||||
|
->setOwner( $voter );
|
||||||
|
$vote = new Vote();
|
||||||
|
$vote
|
||||||
|
->setPoll( $poll )
|
||||||
|
->setStackOfVotes( $stack )
|
||||||
|
->setValue( "yes" )
|
||||||
|
->setChoice( $poll->getChoices()[ 1 ] );
|
||||||
|
$vote = new Vote();
|
||||||
|
$vote
|
||||||
|
->setPoll( $poll )
|
||||||
|
->setStackOfVotes( $stack )
|
||||||
|
->setValue( "yes" )
|
||||||
|
->setChoice( $poll->getChoices()[ 2 ] );
|
||||||
|
$vote = new Vote();
|
||||||
|
$vote
|
||||||
|
->setPoll( $poll )
|
||||||
|
->setStackOfVotes( $stack )
|
||||||
|
->setValue( "no" )
|
||||||
|
->setChoice( $poll->getChoices()[ 2 ] );
|
||||||
|
|
||||||
|
$manager->persist( $stack );
|
||||||
|
|
||||||
|
|
||||||
$manager->persist( $commenterMan );
|
$manager->persist( $commenterMan );
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
@ -24,13 +24,13 @@ class Choice {
|
|||||||
* @ORM\Column(type="string", length=255, nullable=true)
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
* @Serializer\Type("string")
|
* @Serializer\Type("string")
|
||||||
*/
|
*/
|
||||||
private $name;
|
public $name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime", nullable=true)
|
* @ORM\Column(type="datetime", nullable=true)
|
||||||
* @Serializer\Type("datetime")
|
* @Serializer\Type("datetime")
|
||||||
*/
|
*/
|
||||||
private $dateTime;
|
public $dateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="choices")
|
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="choices")
|
||||||
@ -41,13 +41,13 @@ class Choice {
|
|||||||
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="choice")
|
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="choice")
|
||||||
* @Serializer\Type("App\Entity\StackOfVotes")
|
* @Serializer\Type("App\Entity\StackOfVotes")
|
||||||
*/
|
*/
|
||||||
private $stackOfVotes;
|
public $stackOfVotes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice")
|
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice")
|
||||||
* @Serializer\Type("App\Entity\Vote")
|
* @Serializer\Type("App\Entity\Vote")
|
||||||
*/
|
*/
|
||||||
private $votes;
|
public $votes;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->poll = new ArrayCollection();
|
$this->poll = new ArrayCollection();
|
||||||
|
@ -138,7 +138,7 @@ class Poll {
|
|||||||
* number of days from now for default expiracy date
|
* number of days from now for default expiracy date
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $defaultExpiracyDaysFromNow = 60;
|
public $defaultExpiracyDaysFromNow = 60;
|
||||||
|
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
@ -13,10 +13,10 @@ class Vote {
|
|||||||
/**
|
/**
|
||||||
* for a text kind of choice: could be "yes" "no" "maybe" and emptu.
|
* for a text kind of choice: could be "yes" "no" "maybe" and emptu.
|
||||||
* for a date kind, the choice linked is equivalent to the value selected
|
* for a date kind, the choice linked is equivalent to the value selected
|
||||||
* @ORM\Column(type="array", length=255, nullable=true)
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
* @Serializer\Type("array")
|
* @Serializer\Type("string")
|
||||||
*/
|
*/
|
||||||
public $value = [];
|
public $value;
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
||||||
* @Serializer\Type("datetime")
|
* @Serializer\Type("datetime")
|
||||||
@ -83,7 +83,7 @@ class Vote {
|
|||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValue( ?array $value ): self {
|
public function setValue( ?string $value ): self {
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
Loading…
Reference in New Issue
Block a user