-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from elefan-grenoble/feature/reappro
Feature/reappro
- Loading branch information
Showing
8 changed files
with
342 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
sensio_framework_extra: | ||
request: { converters: true } | ||
router: | ||
annotations: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Article; | ||
use App\Entity\Supplying; | ||
use FOS\RestBundle\Context\Context; | ||
use FOS\RestBundle\Controller\AbstractFOSRestController; | ||
use FOS\RestBundle\Controller\Annotations as Rest; | ||
use Nelmio\ApiDocBundle\Annotation\Model; | ||
use phpDocumentor\Reflection\Types\Integer; | ||
use Swagger\Annotations as SWG; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
use Symfony\Component\HttpFoundation\Request; | ||
/** | ||
* @Rest\Route("/supplying") | ||
*/ | ||
class SupplyingController extends AbstractFOSRestController | ||
{ | ||
/** | ||
* @Rest\Get("") | ||
* @Rest\View(statusCode = 200) | ||
* | ||
* @SWG\Response( | ||
* response=200, | ||
* description="Returns the supplying list from kaso database", | ||
* @SWG\Schema( | ||
* type="array", | ||
* @SWG\Items(ref=@Model(type=Supplying::class)) | ||
* ) | ||
* ) | ||
* | ||
* @SWG\Tag(name="supplying") | ||
*/ | ||
public function getSupplying() | ||
{ | ||
$em = $this->getDoctrine(); | ||
$supplyings = $em->getRepository(Supplying::class)->getOngoing(); | ||
return $this->view($supplyings)->setContext($this->getContext()); | ||
} | ||
|
||
/** | ||
* @Rest\Post("") | ||
* @Rest\QueryParam(name="articleCode") | ||
* @Rest\QueryParam(name="quantity") | ||
* @Rest\View(statusCode = 201) | ||
* | ||
* @SWG\Response( | ||
* response=201, | ||
* description="Returns the supplying created", | ||
* @SWG\Schema( | ||
* type="array", | ||
* @SWG\Items(ref=@Model(type=Supplying::class)) | ||
* ) | ||
* ) | ||
* | ||
* @SWG\Tag(name="supplying") | ||
*/ | ||
public function createSupplying($articleCode, $quantity) | ||
{ | ||
$em = $this->getDoctrine()->getEntityManager(); | ||
$article = $em->getRepository(Article::class)->findOneByCode($articleCode); | ||
|
||
$supplying = new Supplying(); | ||
$supplying->setArticle($article); | ||
$supplying->setCreationDate(new \DateTime()); | ||
$supplying->setQuantity($quantity); | ||
$supplying->setOutOfStock(false); | ||
|
||
$em->persist($supplying); | ||
$em->flush(); | ||
|
||
return $this->view( | ||
$supplying, | ||
Response::HTTP_CREATED | ||
); | ||
} | ||
|
||
/** | ||
* @Rest\Put("/{id}") | ||
* @Rest\View(statusCode = 204) | ||
* | ||
* @ParamConverter("updates", converter="fos_rest.request_body") | ||
* | ||
* @SWG\Response( | ||
* response=204, | ||
* description="Supplying updated", | ||
* @SWG\Schema( | ||
* type="array", | ||
* @SWG\Items(ref=@Model(type=Supplying::class)) | ||
* ) | ||
* ) | ||
* | ||
* @SWG\Tag(name="supplying") | ||
*/ | ||
public function updateSupplying(int $id, Supplying $updates) | ||
{ | ||
$em = $this->getDoctrine()->getEntityManager(); | ||
$supplying = $em->getRepository(Supplying::class)->findOneById($id); | ||
|
||
$supplying->setQuantity($updates->getQuantity()); | ||
$supplying->setOutOfStock($updates->getOutOfStock()); | ||
$supplying->setSupplyDate($updates->getSupplyDate()); | ||
|
||
$em->flush(); | ||
|
||
return $this->view( | ||
null, | ||
Response::HTTP_NO_CONTENT | ||
); | ||
} | ||
|
||
private function getContext() | ||
{ | ||
$context = new Context(); | ||
$context->setGroups(['Default']); | ||
if ($this->isGranted(['ROLE_USER'])) { | ||
$context->addGroup('privilegied'); | ||
} | ||
return $context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use JMS\Serializer\Annotation as Serializer; | ||
use phpDocumentor\Reflection\Types\Boolean; | ||
|
||
/** | ||
* Supplying | ||
* | ||
* @ORM\Table(name="SUPPLYING") | ||
* @ORM\Entity(repositoryClass="App\Repository\SupplyingRepository") | ||
*/ | ||
class Supplying | ||
{ | ||
|
||
/** | ||
* @var int | ||
* | ||
* @ORM\Column(name="id", type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* Article | ||
* @var Article | ||
* @ORM\ManyToOne(targetEntity="App\Entity\Article") | ||
* @ORM\JoinColumn(name="article_code", referencedColumnName="code", nullable=false) | ||
* @Serializer\MaxDepth(depth=2) | ||
*/ | ||
private $article; | ||
|
||
/** | ||
* Quantité à réapprovisionner | ||
* @var int|null | ||
* | ||
* @ORM\Column(name="quantity", type="integer", nullable=true) | ||
*/ | ||
private $quantity; | ||
|
||
/** | ||
* Date de création | ||
* @var \DateTime|null | ||
* | ||
* @ORM\Column(name="creation_date", type="datetime", nullable=false) | ||
*/ | ||
private $creationDate; | ||
|
||
/** | ||
* Date de réapprovisionnement | ||
* @var \DateTime|null | ||
* | ||
* @ORM\Column(name="supply_date", type="datetime", nullable=true) | ||
*/ | ||
private $supplyDate; | ||
|
||
/** | ||
* En rupture de stock (non trouvé) | ||
* | ||
* @var boolean | ||
* @ORM\Column(name="out_of_stock", type="boolean", nullable=false) | ||
*/ | ||
private $outOfStock; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return Article | ||
*/ | ||
public function getArticle(): Article | ||
{ | ||
return $this->article; | ||
} | ||
|
||
/** | ||
* @param Article $article | ||
*/ | ||
public function setArticle(Article $article): void | ||
{ | ||
$this->article = $article; | ||
} | ||
|
||
/** | ||
* @return int|null | ||
*/ | ||
public function getQuantity(): ?int | ||
{ | ||
return $this->quantity; | ||
} | ||
|
||
/** | ||
* @param int|null $quantity | ||
*/ | ||
public function setQuantity(?int $quantity): void | ||
{ | ||
$this->quantity = $quantity; | ||
} | ||
|
||
/** | ||
* @return \DateTime|null | ||
*/ | ||
public function getCreationDate(): ?\DateTime | ||
{ | ||
return $this->creationDate; | ||
} | ||
|
||
/** | ||
* @param \DateTime|null $creationDate | ||
*/ | ||
public function setCreationDate(?\DateTime $creationDate): void | ||
{ | ||
$this->creationDate = $creationDate; | ||
} | ||
|
||
/** | ||
* @return \DateTime|null | ||
*/ | ||
public function getSupplyDate(): ?\DateTime | ||
{ | ||
return $this->supplyDate; | ||
} | ||
|
||
/** | ||
* @param \DateTime|null $supplyDate | ||
*/ | ||
public function setSupplyDate(?\DateTime $supplyDate): void | ||
{ | ||
$this->supplyDate = $supplyDate; | ||
} | ||
|
||
/** | ||
* @return Boolean | ||
*/ | ||
public function getOutOfStock(): bool | ||
{ | ||
return $this->outOfStock; | ||
} | ||
|
||
/** | ||
* @param Boolean $outOfStock | ||
*/ | ||
public function setOutOfStock(bool $outOfStock): void | ||
{ | ||
$this->outOfStock = $outOfStock; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20190815150022 extends AbstractMigration | ||
{ | ||
public function getDescription() : string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema) : void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('CREATE TABLE SUPPLYING (id INT AUTO_INCREMENT NOT NULL, article_code BIGINT NOT NULL, quantity INT DEFAULT NULL, creation_date DATETIME NOT NULL, supply_date DATETIME DEFAULT NULL, out_of_stock TINYINT(1) NOT NULL, INDEX IDX_4D448068C757B799 (article_code), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE SUPPLYING ADD CONSTRAINT FK_4D448068C757B799 FOREIGN KEY (article_code) REFERENCES ARTICLE (code)'); | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('DROP TABLE SUPPLYING'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
|
||
class SupplyingRepository extends EntityRepository | ||
{ | ||
|
||
public function getOngoing() | ||
{ | ||
return $this->createQueryBuilder('s') | ||
->where('s.supplyDate is null') | ||
->orderBy('s.id', 'ASC') | ||
->getQuery() | ||
->getResult() | ||
; | ||
} | ||
} |
Oops, something went wrong.