From 095dad7b4dfdb45e27a91a33c22de8ed81e8de2f Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 26 Oct 2020 17:16:29 +0100 Subject: [PATCH] chore: create base entities --- migrations/Version20201026161459.php | 45 ++++++++ src/Entity/APIKey.php | 59 +++++++++++ src/Entity/Consumer.php | 119 ++++++++++++++++++++++ src/Entity/Resource.php | 60 +++++++++++ src/Entity/ResourceType.php | 100 ++++++++++++++++++ src/Entity/Rule.php | 95 +++++++++++++++++ src/Repository/APIKeyRepository.php | 50 +++++++++ src/Repository/ConsumerRepository.php | 50 +++++++++ src/Repository/ResourceRepository.php | 50 +++++++++ src/Repository/ResourceTypeRepository.php | 50 +++++++++ src/Repository/RuleRepository.php | 50 +++++++++ 11 files changed, 728 insertions(+) create mode 100644 migrations/Version20201026161459.php create mode 100644 src/Entity/APIKey.php create mode 100644 src/Entity/Consumer.php create mode 100644 src/Entity/Resource.php create mode 100644 src/Entity/ResourceType.php create mode 100644 src/Entity/Rule.php create mode 100644 src/Repository/APIKeyRepository.php create mode 100644 src/Repository/ConsumerRepository.php create mode 100644 src/Repository/ResourceRepository.php create mode 100644 src/Repository/ResourceTypeRepository.php create mode 100644 src/Repository/RuleRepository.php diff --git a/migrations/Version20201026161459.php b/migrations/Version20201026161459.php new file mode 100644 index 0000000..88477a7 --- /dev/null +++ b/migrations/Version20201026161459.php @@ -0,0 +1,45 @@ +addSql('CREATE TABLE apikey (id INT AUTO_INCREMENT NOT NULL, consumer_id INT NOT NULL, token VARCHAR(255) NOT NULL, INDEX IDX_B84757A137FDBD6D (consumer_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE consumer (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE resource (id INT AUTO_INCREMENT NOT NULL, type_id INT NOT NULL, owner_id INT NOT NULL, INDEX IDX_BC91F416C54C8C93 (type_id), INDEX IDX_BC91F4167E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE resource_type (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, validation_schema LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE rule (id INT AUTO_INCREMENT NOT NULL, predicate VARCHAR(255) DEFAULT NULL, action VARCHAR(255) NOT NULL, name VARCHAR(255) DEFAULT NULL, type SMALLINT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE apikey ADD CONSTRAINT FK_B84757A137FDBD6D FOREIGN KEY (consumer_id) REFERENCES consumer (id)'); + $this->addSql('ALTER TABLE resource ADD CONSTRAINT FK_BC91F416C54C8C93 FOREIGN KEY (type_id) REFERENCES resource_type (id)'); + $this->addSql('ALTER TABLE resource ADD CONSTRAINT FK_BC91F4167E3C61F9 FOREIGN KEY (owner_id) REFERENCES consumer (id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE apikey DROP FOREIGN KEY FK_B84757A137FDBD6D'); + $this->addSql('ALTER TABLE resource DROP FOREIGN KEY FK_BC91F4167E3C61F9'); + $this->addSql('ALTER TABLE resource DROP FOREIGN KEY FK_BC91F416C54C8C93'); + $this->addSql('DROP TABLE apikey'); + $this->addSql('DROP TABLE consumer'); + $this->addSql('DROP TABLE resource'); + $this->addSql('DROP TABLE resource_type'); + $this->addSql('DROP TABLE rule'); + } +} diff --git a/src/Entity/APIKey.php b/src/Entity/APIKey.php new file mode 100644 index 0000000..9614db5 --- /dev/null +++ b/src/Entity/APIKey.php @@ -0,0 +1,59 @@ +id; + } + + public function getToken(): ?string + { + return $this->token; + } + + public function setToken(string $token): self + { + $this->token = $token; + + return $this; + } + + public function getConsumer(): ?Consumer + { + return $this->consumer; + } + + public function setConsumer(?Consumer $consumer): self + { + $this->consumer = $consumer; + + return $this; + } +} diff --git a/src/Entity/Consumer.php b/src/Entity/Consumer.php new file mode 100644 index 0000000..ed73b25 --- /dev/null +++ b/src/Entity/Consumer.php @@ -0,0 +1,119 @@ +apiKeys = new ArrayCollection(); + $this->resources = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + /** + * @return Collection|APIKey[] + */ + public function getApiKeys(): Collection + { + return $this->apiKeys; + } + + public function addApiKey(APIKey $apiKey): self + { + if (!$this->apiKeys->contains($apiKey)) { + $this->apiKeys[] = $apiKey; + $apiKey->setConsumer($this); + } + + return $this; + } + + public function removeApiKey(APIKey $apiKey): self + { + if ($this->apiKeys->removeElement($apiKey)) { + // set the owning side to null (unless already changed) + if ($apiKey->getConsumer() === $this) { + $apiKey->setConsumer(null); + } + } + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } + + /** + * @return Collection|Resource[] + */ + public function getResources(): Collection + { + return $this->resources; + } + + public function addResource(Resource $resource): self + { + if (!$this->resources->contains($resource)) { + $this->resources[] = $resource; + $resource->setOwner($this); + } + + return $this; + } + + public function removeResource(Resource $resource): self + { + if ($this->resources->removeElement($resource)) { + // set the owning side to null (unless already changed) + if ($resource->getOwner() === $this) { + $resource->setOwner(null); + } + } + + return $this; + } +} diff --git a/src/Entity/Resource.php b/src/Entity/Resource.php new file mode 100644 index 0000000..9de10cc --- /dev/null +++ b/src/Entity/Resource.php @@ -0,0 +1,60 @@ +id; + } + + public function getType(): ?ResourceType + { + return $this->type; + } + + public function setType(?ResourceType $type): self + { + $this->type = $type; + + return $this; + } + + public function getOwner(): ?Consumer + { + return $this->owner; + } + + public function setOwner(?Consumer $owner): self + { + $this->owner = $owner; + + return $this; + } +} diff --git a/src/Entity/ResourceType.php b/src/Entity/ResourceType.php new file mode 100644 index 0000000..243f6b6 --- /dev/null +++ b/src/Entity/ResourceType.php @@ -0,0 +1,100 @@ +Resources = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } + + public function getValidationSchema(): ?array + { + return $this->validationSchema; + } + + public function setValidationSchema(?array $validationSchema): self + { + $this->validationSchema = $validationSchema; + + return $this; + } + + /** + * @return Collection|Resource[] + */ + public function getResources(): Collection + { + return $this->Resources; + } + + public function addResource(Resource $resource): self + { + if (!$this->Resources->contains($resource)) { + $this->Resources[] = $resource; + $resource->setType($this); + } + + return $this; + } + + public function removeResource(Resource $resource): self + { + if ($this->Resources->removeElement($resource)) { + // set the owning side to null (unless already changed) + if ($resource->getType() === $this) { + $resource->setType(null); + } + } + + return $this; + } +} diff --git a/src/Entity/Rule.php b/src/Entity/Rule.php new file mode 100644 index 0000000..d5a4032 --- /dev/null +++ b/src/Entity/Rule.php @@ -0,0 +1,95 @@ +id; + } + + public function getPredicate(): ?string + { + return $this->predicate; + } + + public function setPredicate(?string $predicate): self + { + $this->predicate = $predicate; + + return $this; + } + + public function getAction(): ?string + { + return $this->action; + } + + public function setAction(string $action): self + { + $this->action = $action; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(?string $name): self + { + $this->name = $name; + + return $this; + } + + public function getType(): ?int + { + return $this->type; + } + + public function setType(int $type): self + { + $this->type = $type; + + return $this; + } +} diff --git a/src/Repository/APIKeyRepository.php b/src/Repository/APIKeyRepository.php new file mode 100644 index 0000000..5b38277 --- /dev/null +++ b/src/Repository/APIKeyRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('a.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?APIKey + { + return $this->createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Repository/ConsumerRepository.php b/src/Repository/ConsumerRepository.php new file mode 100644 index 0000000..a95bf2f --- /dev/null +++ b/src/Repository/ConsumerRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('c') + ->andWhere('c.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('c.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Consumer + { + return $this->createQueryBuilder('c') + ->andWhere('c.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Repository/ResourceRepository.php b/src/Repository/ResourceRepository.php new file mode 100644 index 0000000..0f915f1 --- /dev/null +++ b/src/Repository/ResourceRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('r') + ->andWhere('r.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('r.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Resource + { + return $this->createQueryBuilder('r') + ->andWhere('r.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Repository/ResourceTypeRepository.php b/src/Repository/ResourceTypeRepository.php new file mode 100644 index 0000000..aa718ce --- /dev/null +++ b/src/Repository/ResourceTypeRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('r') + ->andWhere('r.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('r.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?ResourceType + { + return $this->createQueryBuilder('r') + ->andWhere('r.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Repository/RuleRepository.php b/src/Repository/RuleRepository.php new file mode 100644 index 0000000..fabe8cb --- /dev/null +++ b/src/Repository/RuleRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('r') + ->andWhere('r.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('r.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Rule + { + return $this->createQueryBuilder('r') + ->andWhere('r.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +}