From 0d010a158f1cf1703b4e227419c71773bb8b830d Mon Sep 17 00:00:00 2001 From: "a.shamavov" <a.shamavov@iqdev.digital> Date: Thu, 2 May 2024 12:53:14 +0500 Subject: [PATCH] =?UTF-8?q?STA-965=20|=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=81=D1=85=D0=B5=D0=BC=D1=83=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migrations/Version20240423071100.php | 103 -------------------------- migrations/Version20240423071601.php | 40 ---------- src/Entity/Address.php | 51 ------------- src/Entity/Email.php | 51 ------------- src/Entity/File.php | 102 +++++++++++++++++++++++++ src/Entity/{Phone.php => Gallery.php} | 31 ++++---- src/Entity/Kitchen.php | 8 +- src/Entity/News.php | 20 ++++- src/Entity/NewsCategory.php | 27 ------- src/Entity/NewsComment.php | 12 +-- src/Entity/NewsType.php | 8 +- src/Entity/Restaurant.php | 94 ++++++++++++++--------- src/Entity/RestaurantType.php | 8 +- src/Entity/Seo.php | 65 ++++++++++++++++ src/Entity/Settlement.php | 24 +----- src/Entity/Tags.php | 24 +++++- src/Entity/User.php | 19 +---- src/Repository/AddressRepository.php | 48 ------------ src/Repository/EmailRepository.php | 48 ------------ src/Repository/FileRepository.php | 48 ++++++++++++ src/Repository/GalleryRepository.php | 48 ++++++++++++ src/Repository/PhoneRepository.php | 48 ------------ src/Repository/SeoRepository.php | 48 ++++++++++++ tests/RestaurantControllerTest.php | 63 ++++++++++++++++ 24 files changed, 514 insertions(+), 524 deletions(-) delete mode 100644 migrations/Version20240423071100.php delete mode 100644 migrations/Version20240423071601.php delete mode 100644 src/Entity/Address.php delete mode 100644 src/Entity/Email.php create mode 100644 src/Entity/File.php rename src/Entity/{Phone.php => Gallery.php} (58%) create mode 100644 src/Entity/Seo.php delete mode 100644 src/Repository/AddressRepository.php delete mode 100644 src/Repository/EmailRepository.php create mode 100644 src/Repository/FileRepository.php create mode 100644 src/Repository/GalleryRepository.php delete mode 100644 src/Repository/PhoneRepository.php create mode 100644 src/Repository/SeoRepository.php create mode 100644 tests/RestaurantControllerTest.php diff --git a/migrations/Version20240423071100.php b/migrations/Version20240423071100.php deleted file mode 100644 index f16e9f8..0000000 --- a/migrations/Version20240423071100.php +++ /dev/null @@ -1,103 +0,0 @@ -<?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 Version20240423071100 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->addSql('CREATE SEQUENCE address_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE email_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE news_comment_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE news_type_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE phone_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE restaurant_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE tags_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE address (id INT NOT NULL, restaurant_id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_D4E6F81B1E7706E ON address (restaurant_id)'); - $this->addSql('CREATE TABLE email (id INT NOT NULL, restaurant_id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_E7927C74B1E7706E ON email (restaurant_id)'); - $this->addSql('CREATE TABLE news (id UUID NOT NULL, type_id INT NOT NULL, code VARCHAR(255) NOT NULL, active BOOLEAN NOT NULL, create_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, update_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, sort INT NOT NULL, preview_image VARCHAR(255) NOT NULL, detail_image VARCHAR(255) NOT NULL, preview_text TEXT NOT NULL, detail_text TEXT NOT NULL, main_page_render BOOLEAN NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_1DD39950C54C8C93 ON news (type_id)'); - $this->addSql('COMMENT ON COLUMN news.id IS \'(DC2Type:uuid)\''); - $this->addSql('CREATE TABLE news_comment (id INT NOT NULL, news_id_id UUID NOT NULL, moderator_id_id INT NOT NULL, user_id_id INT NOT NULL, moderated BOOLEAN NOT NULL, user_name VARCHAR(255) NOT NULL, text VARCHAR(255) NOT NULL, create_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, update_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_C3904E8A5FB1909 ON news_comment (news_id_id)'); - $this->addSql('CREATE INDEX IDX_C3904E8ACEB712DF ON news_comment (moderator_id_id)'); - $this->addSql('CREATE INDEX IDX_C3904E8A9D86650F ON news_comment (user_id_id)'); - $this->addSql('COMMENT ON COLUMN news_comment.news_id_id IS \'(DC2Type:uuid)\''); - $this->addSql('CREATE TABLE news_type (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE phone (id INT NOT NULL, restaurant_id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_444F97DDB1E7706E ON phone (restaurant_id)'); - $this->addSql('CREATE TABLE restaurant (id INT NOT NULL, type_id_id INT NOT NULL, settlement_id_id INT NOT NULL, uuid UUID NOT NULL, name VARCHAR(255) NOT NULL, code VARCHAR(255) NOT NULL, active BOOLEAN NOT NULL, sort INT NOT NULL, create_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, update_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, coordinates TEXT NOT NULL, description TEXT NOT NULL, check_price VARCHAR(255) NOT NULL, check_info TEXT NOT NULL, site VARCHAR(255) NOT NULL, preview_image VARCHAR(255) NOT NULL, detail_image VARCHAR(255) NOT NULL, how_to_find TEXT NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_EB95123FD17F50A6 ON restaurant (uuid)'); - $this->addSql('CREATE INDEX IDX_EB95123F714819A0 ON restaurant (type_id_id)'); - $this->addSql('CREATE INDEX IDX_EB95123F45EC589B ON restaurant (settlement_id_id)'); - $this->addSql('COMMENT ON COLUMN restaurant.uuid IS \'(DC2Type:uuid)\''); - $this->addSql('COMMENT ON COLUMN restaurant.coordinates IS \'(DC2Type:array)\''); - $this->addSql('CREATE TABLE tags (id INT NOT NULL, restaurant_id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_6FBC9426B1E7706E ON tags (restaurant_id)'); - $this->addSql('ALTER TABLE address ADD CONSTRAINT FK_D4E6F81B1E7706E FOREIGN KEY (restaurant_id) REFERENCES restaurant (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE email ADD CONSTRAINT FK_E7927C74B1E7706E FOREIGN KEY (restaurant_id) REFERENCES restaurant (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE news ADD CONSTRAINT FK_1DD39950C54C8C93 FOREIGN KEY (type_id) REFERENCES news_type (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE news_comment ADD CONSTRAINT FK_C3904E8A5FB1909 FOREIGN KEY (news_id_id) REFERENCES news (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE news_comment ADD CONSTRAINT FK_C3904E8ACEB712DF FOREIGN KEY (moderator_id_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE news_comment ADD CONSTRAINT FK_C3904E8A9D86650F FOREIGN KEY (user_id_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE phone ADD CONSTRAINT FK_444F97DDB1E7706E FOREIGN KEY (restaurant_id) REFERENCES restaurant (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE restaurant ADD CONSTRAINT FK_EB95123F714819A0 FOREIGN KEY (type_id_id) REFERENCES restaurant_type (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE restaurant ADD CONSTRAINT FK_EB95123F45EC589B FOREIGN KEY (settlement_id_id) REFERENCES settlement (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE tags ADD CONSTRAINT FK_6FBC9426B1E7706E FOREIGN KEY (restaurant_id) REFERENCES restaurant (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE kitchen ADD restaurant_id INT NOT NULL'); - $this->addSql('ALTER TABLE kitchen ADD CONSTRAINT FK_EAA3CE34B1E7706E FOREIGN KEY (restaurant_id) REFERENCES restaurant (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_EAA3CE34B1E7706E ON kitchen (restaurant_id)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649D17F50A6 ON "user" (uuid)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE kitchen DROP CONSTRAINT FK_EAA3CE34B1E7706E'); - $this->addSql('DROP SEQUENCE address_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE email_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE news_comment_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE news_type_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE phone_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE restaurant_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE tags_id_seq CASCADE'); - $this->addSql('ALTER TABLE address DROP CONSTRAINT FK_D4E6F81B1E7706E'); - $this->addSql('ALTER TABLE email DROP CONSTRAINT FK_E7927C74B1E7706E'); - $this->addSql('ALTER TABLE news DROP CONSTRAINT FK_1DD39950C54C8C93'); - $this->addSql('ALTER TABLE news_comment DROP CONSTRAINT FK_C3904E8A5FB1909'); - $this->addSql('ALTER TABLE news_comment DROP CONSTRAINT FK_C3904E8ACEB712DF'); - $this->addSql('ALTER TABLE news_comment DROP CONSTRAINT FK_C3904E8A9D86650F'); - $this->addSql('ALTER TABLE phone DROP CONSTRAINT FK_444F97DDB1E7706E'); - $this->addSql('ALTER TABLE restaurant DROP CONSTRAINT FK_EB95123F714819A0'); - $this->addSql('ALTER TABLE restaurant DROP CONSTRAINT FK_EB95123F45EC589B'); - $this->addSql('ALTER TABLE tags DROP CONSTRAINT FK_6FBC9426B1E7706E'); - $this->addSql('DROP TABLE address'); - $this->addSql('DROP TABLE email'); - $this->addSql('DROP TABLE news'); - $this->addSql('DROP TABLE news_comment'); - $this->addSql('DROP TABLE news_type'); - $this->addSql('DROP TABLE phone'); - $this->addSql('DROP TABLE restaurant'); - $this->addSql('DROP TABLE tags'); - $this->addSql('DROP INDEX UNIQ_8D93D649D17F50A6'); - $this->addSql('DROP INDEX IDX_EAA3CE34B1E7706E'); - $this->addSql('ALTER TABLE kitchen DROP restaurant_id'); - } -} diff --git a/migrations/Version20240423071601.php b/migrations/Version20240423071601.php deleted file mode 100644 index c8b2ca7..0000000 --- a/migrations/Version20240423071601.php +++ /dev/null @@ -1,40 +0,0 @@ -<?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 Version20240423071601 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->addSql('CREATE TABLE news_news_category (news_id UUID NOT NULL, news_category_id UUID NOT NULL, PRIMARY KEY(news_id, news_category_id))'); - $this->addSql('CREATE INDEX IDX_1A91D6D6B5A459A0 ON news_news_category (news_id)'); - $this->addSql('CREATE INDEX IDX_1A91D6D63B732BAD ON news_news_category (news_category_id)'); - $this->addSql('COMMENT ON COLUMN news_news_category.news_id IS \'(DC2Type:uuid)\''); - $this->addSql('COMMENT ON COLUMN news_news_category.news_category_id IS \'(DC2Type:uuid)\''); - $this->addSql('ALTER TABLE news_news_category ADD CONSTRAINT FK_1A91D6D6B5A459A0 FOREIGN KEY (news_id) REFERENCES news (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE news_news_category ADD CONSTRAINT FK_1A91D6D63B732BAD FOREIGN KEY (news_category_id) REFERENCES news_category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE news_news_category DROP CONSTRAINT FK_1A91D6D6B5A459A0'); - $this->addSql('ALTER TABLE news_news_category DROP CONSTRAINT FK_1A91D6D63B732BAD'); - $this->addSql('DROP TABLE news_news_category'); - } -} diff --git a/src/Entity/Address.php b/src/Entity/Address.php deleted file mode 100644 index 6fa2e40..0000000 --- a/src/Entity/Address.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php - -namespace App\Entity; - -use App\Repository\AddressRepository; -use Doctrine\ORM\Mapping as ORM; - -#[ORM\Entity(repositoryClass: AddressRepository::class)] -class Address -{ - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; - - #[ORM\Column(length: 255)] - private ?string $name = null; - - #[ORM\ManyToOne(inversedBy: 'address')] - #[ORM\JoinColumn(nullable: false)] - private ?Restaurant $restaurant = null; - - public function getId(): ?int - { - return $this->id; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(string $name): static - { - $this->name = $name; - - return $this; - } - - public function getRestaurant(): ?Restaurant - { - return $this->restaurant; - } - - public function setRestaurant(?Restaurant $restaurant): static - { - $this->restaurant = $restaurant; - - return $this; - } -} diff --git a/src/Entity/Email.php b/src/Entity/Email.php deleted file mode 100644 index ba955db..0000000 --- a/src/Entity/Email.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php - -namespace App\Entity; - -use App\Repository\EmailRepository; -use Doctrine\ORM\Mapping as ORM; - -#[ORM\Entity(repositoryClass: EmailRepository::class)] -class Email -{ - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; - - #[ORM\Column(length: 255)] - private ?string $name = null; - - #[ORM\ManyToOne(inversedBy: 'email')] - #[ORM\JoinColumn(nullable: false)] - private ?Restaurant $restaurant = null; - - public function getId(): ?int - { - return $this->id; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(string $name): static - { - $this->name = $name; - - return $this; - } - - public function getRestaurant(): ?Restaurant - { - return $this->restaurant; - } - - public function setRestaurant(?Restaurant $restaurant): static - { - $this->restaurant = $restaurant; - - return $this; - } -} diff --git a/src/Entity/File.php b/src/Entity/File.php new file mode 100644 index 0000000..39432fc --- /dev/null +++ b/src/Entity/File.php @@ -0,0 +1,102 @@ +<?php + +namespace App\Entity; + +use App\Repository\FileRepository; +use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Uid\Uuid; + +#[ORM\Entity(repositoryClass: FileRepository::class)] +class File +{ + #[ORM\Id] + #[ORM\Column(type: 'uuid', unique: true)] + private ?Uuid $id = null; + + #[ORM\Column(length: 255)] + private ?string $name = null; + + #[ORM\Column(length: 255)] + private ?string $description = null; + + #[ORM\Column] + private ?int $size = null; + + #[ORM\Column(length: 255)] + private ?string $type = null; + + #[ORM\Column(length: 255)] + private ?string $url = null; + + public function getId(): ?Uuid + { + return $this->id; + } + + public function setId(Uuid $id): static + { + $this->id = $id; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(string $description): static + { + $this->description = $description; + + return $this; + } + + public function getSize(): ?int + { + return $this->size; + } + + public function setSize(int $size): static + { + $this->size = $size; + + return $this; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(string $type): static + { + $this->type = $type; + + return $this; + } + + public function getUrl(): ?string + { + return $this->url; + } + + public function setUrl(string $url): static + { + $this->url = $url; + + return $this; + } +} diff --git a/src/Entity/Phone.php b/src/Entity/Gallery.php similarity index 58% rename from src/Entity/Phone.php rename to src/Entity/Gallery.php index 00c028f..1edce96 100644 --- a/src/Entity/Phone.php +++ b/src/Entity/Gallery.php @@ -2,49 +2,50 @@ namespace App\Entity; -use App\Repository\PhoneRepository; +use App\Repository\GalleryRepository; use Doctrine\ORM\Mapping as ORM; -#[ORM\Entity(repositoryClass: PhoneRepository::class)] -class Phone +#[ORM\Entity(repositoryClass: GalleryRepository::class)] +class Gallery { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; - #[ORM\Column(length: 255)] - private ?string $name = null; - - #[ORM\ManyToOne(inversedBy: 'phone')] + #[ORM\ManyToOne(inversedBy: 'galleries')] #[ORM\JoinColumn(nullable: false)] private ?Restaurant $restaurant = null; + #[ORM\OneToOne(cascade: ['persist', 'remove'])] + #[ORM\JoinColumn(nullable: false)] + private ?File $file = null; + public function getId(): ?int { return $this->id; } - public function getName(): ?string + public function getRestaurant(): ?Restaurant { - return $this->name; + return $this->restaurant; } - public function setName(string $name): static + public function setRestaurant(?Restaurant $restaurant): static { - $this->name = $name; + $this->restaurant = $restaurant; return $this; } - public function getRestaurant(): ?Restaurant + public function getFile(): ?File { - return $this->restaurant; + return $this->file; } - public function setRestaurant(?Restaurant $restaurant): static + public function setFile(File $file): static { - $this->restaurant = $restaurant; + $this->file = $file; return $this; } diff --git a/src/Entity/Kitchen.php b/src/Entity/Kitchen.php index 2d08475..0315324 100644 --- a/src/Entity/Kitchen.php +++ b/src/Entity/Kitchen.php @@ -4,14 +4,14 @@ namespace App\Entity; use App\Repository\KitchenRepository; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Uid\Uuid; #[ORM\Entity(repositoryClass: KitchenRepository::class)] class Kitchen { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; + #[ORM\Column(type: 'uuid', unique: true)] + private ?Uuid $id = null; #[ORM\Column(length: 255)] private ?string $name = null; @@ -20,7 +20,7 @@ class Kitchen #[ORM\JoinColumn(nullable: false)] private ?Restaurant $restaurant = null; - public function getId(): ?int + public function getId(): ?Uuid { return $this->id; } diff --git a/src/Entity/News.php b/src/Entity/News.php index a4de9af..2f61753 100644 --- a/src/Entity/News.php +++ b/src/Entity/News.php @@ -22,10 +22,10 @@ class News #[ORM\Column] private ?bool $active = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeInterface $createAt = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeInterface $updateAt = null; #[ORM\Column] @@ -56,6 +56,10 @@ class News #[ORM\ManyToMany(targetEntity: NewsCategory::class)] private Collection $newsCategories; + #[ORM\ManyToOne] + #[ORM\JoinColumn(nullable: false)] + private ?Seo $seo = null; + public function __construct() { $this->newsCategories = new ArrayCollection(); @@ -221,4 +225,16 @@ class News return $this; } + + public function getSeo(): ?Seo + { + return $this->seo; + } + + public function setSeo(?Seo $seo): static + { + $this->seo = $seo; + + return $this; + } } diff --git a/src/Entity/NewsCategory.php b/src/Entity/NewsCategory.php index 974a99c..1322e29 100644 --- a/src/Entity/NewsCategory.php +++ b/src/Entity/NewsCategory.php @@ -49,31 +49,4 @@ class NewsCategory return $this; } - - /** - * @return Collection<int, News> - */ - public function getNews(): Collection - { - return $this->news; - } - - public function addNews(News $news): static - { - if (!$this->news->contains($news)) { - $this->news->add($news); - $news->addNewsCategory($this); - } - - return $this; - } - - public function removeNews(News $news): static - { - if ($this->news->removeElement($news)) { - $news->removeNewsCategory($this); - } - - return $this; - } } diff --git a/src/Entity/NewsComment.php b/src/Entity/NewsComment.php index 44f0e48..683c324 100644 --- a/src/Entity/NewsComment.php +++ b/src/Entity/NewsComment.php @@ -5,14 +5,14 @@ namespace App\Entity; use App\Repository\NewsCommentRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Uid\Uuid; #[ORM\Entity(repositoryClass: NewsCommentRepository::class)] class NewsComment { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; + #[ORM\Column(type: 'uuid', unique: true)] + private ?Uuid $id = null; #[ORM\OneToOne(cascade: ['persist', 'remove'])] #[ORM\JoinColumn(nullable: false)] @@ -35,13 +35,13 @@ class NewsComment #[ORM\Column(length: 255)] private ?string $text = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeInterface $createAt = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeImmutable $updateAt = null; - public function getId(): ?int + public function getId(): ?Uuid { return $this->id; } diff --git a/src/Entity/NewsType.php b/src/Entity/NewsType.php index 409ac09..27b05d3 100644 --- a/src/Entity/NewsType.php +++ b/src/Entity/NewsType.php @@ -6,14 +6,14 @@ use App\Repository\NewsTypeRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Uid\Uuid; #[ORM\Entity(repositoryClass: NewsTypeRepository::class)] class NewsType { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; + #[ORM\Column(type: 'uuid', unique: true)] + private ?Uuid $id = null; #[ORM\Column(length: 255)] private ?string $name = null; @@ -29,7 +29,7 @@ class NewsType $this->news = new ArrayCollection(); } - public function getId(): ?int + public function getId(): ?Uuid { return $this->id; } diff --git a/src/Entity/Restaurant.php b/src/Entity/Restaurant.php index 02fd3b1..304e779 100644 --- a/src/Entity/Restaurant.php +++ b/src/Entity/Restaurant.php @@ -13,12 +13,8 @@ use Symfony\Component\Uid\Uuid; class Restaurant { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; - #[ORM\Column(type: 'uuid', unique: true)] - private ?Uuid $uuid = null; + private ?Uuid $id = null; #[ORM\Column(length: 255)] private ?string $name = null; @@ -32,13 +28,13 @@ class Restaurant #[ORM\Column] private ?int $sort = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeInterface $createAt = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeInterface $updateAt = null; - #[ORM\Column(type: Types::ARRAY)] + #[ORM\Column(type: 'simple_array')] private array $coordinates = []; #[ORM\ManyToOne(inversedBy: 'restaurants')] @@ -64,22 +60,13 @@ class Restaurant #[ORM\OneToMany(targetEntity: Kitchen::class, mappedBy: 'restaurant')] private Collection $kitchen; - /** - * @var Collection<int, Phone> - */ - #[ORM\OneToMany(targetEntity: Phone::class, mappedBy: 'restaurant')] + #[ORM\Column(type: Types::JSON)] private Collection $phone; - /** - * @var Collection<int, Email> - */ - #[ORM\OneToMany(targetEntity: Email::class, mappedBy: 'restaurant')] + #[ORM\Column(type: Types::JSON)] private Collection $email; - /** - * @var Collection<int, Address> - */ - #[ORM\OneToMany(targetEntity: Address::class, mappedBy: 'restaurant')] + #[ORM\Column(type: Types::JSON)] private Collection $address; /** @@ -100,6 +87,16 @@ class Restaurant #[ORM\Column(type: Types::TEXT)] private ?string $howToFind = null; + /** + * @var Collection<int, Gallery> + */ + #[ORM\OneToMany(targetEntity: Gallery::class, mappedBy: 'restaurant')] + private Collection $galleries; + + #[ORM\ManyToOne] + #[ORM\JoinColumn(nullable: false)] + private ?Seo $seo = null; + public function __construct() { $this->kitchen = new ArrayCollection(); @@ -107,25 +104,14 @@ class Restaurant $this->email = new ArrayCollection(); $this->address = new ArrayCollection(); $this->tags = new ArrayCollection(); + $this->galleries = new ArrayCollection(); } - public function getId(): ?int + public function getId(): ?Uuid { return $this->id; } - public function getUuid(): ?Uuid - { - return $this->uuid; - } - - public function setUuid(Uuid $uuid): static - { - $this->uuid = $uuid; - - return $this; - } - public function getName(): ?string { return $this->name; @@ -467,4 +453,46 @@ class Restaurant return $this; } + + /** + * @return Collection<int, Gallery> + */ + public function getGalleries(): Collection + { + return $this->galleries; + } + + public function addGallery(Gallery $gallery): static + { + if (!$this->galleries->contains($gallery)) { + $this->galleries->add($gallery); + $gallery->setRestaurant($this); + } + + return $this; + } + + public function removeGallery(Gallery $gallery): static + { + if ($this->galleries->removeElement($gallery)) { + // set the owning side to null (unless already changed) + if ($gallery->getRestaurant() === $this) { + $gallery->setRestaurant(null); + } + } + + return $this; + } + + public function getSeo(): ?Seo + { + return $this->seo; + } + + public function setSeo(?Seo $seo): static + { + $this->seo = $seo; + + return $this; + } } diff --git a/src/Entity/RestaurantType.php b/src/Entity/RestaurantType.php index 2698a85..eb59ef7 100644 --- a/src/Entity/RestaurantType.php +++ b/src/Entity/RestaurantType.php @@ -6,14 +6,14 @@ use App\Repository\RestaurantTypeRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Uid\Uuid; #[ORM\Entity(repositoryClass: RestaurantTypeRepository::class)] class RestaurantType { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; + #[ORM\Column(type: 'uuid', unique: true)] + private ?Uuid $id = null; #[ORM\Column(length: 255)] private ?string $name = null; @@ -32,7 +32,7 @@ class RestaurantType $this->restaurants = new ArrayCollection(); } - public function getId(): ?int + public function getId(): ?Uuid { return $this->id; } diff --git a/src/Entity/Seo.php b/src/Entity/Seo.php new file mode 100644 index 0000000..8d4328f --- /dev/null +++ b/src/Entity/Seo.php @@ -0,0 +1,65 @@ +<?php + +namespace App\Entity; + +use App\Repository\SeoRepository; +use Doctrine\ORM\Mapping as ORM; + +#[ORM\Entity(repositoryClass: SeoRepository::class)] +class Seo +{ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column] + private ?int $id = null; + + #[ORM\Column(length: 255)] + private ?string $title = null; + + #[ORM\Column(length: 255)] + private ?string $description = null; + + #[ORM\Column(length: 255)] + private ?string $keywords = null; + + public function getId(): ?int + { + return $this->id; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): static + { + $this->title = $title; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(string $description): static + { + $this->description = $description; + + return $this; + } + + public function getKeywords(): ?string + { + return $this->keywords; + } + + public function setKeywords(string $keywords): static + { + $this->keywords = $keywords; + + return $this; + } +} diff --git a/src/Entity/Settlement.php b/src/Entity/Settlement.php index 9f983df..94d8e4d 100644 --- a/src/Entity/Settlement.php +++ b/src/Entity/Settlement.php @@ -13,12 +13,8 @@ use Symfony\Component\Uid\Uuid; class Settlement { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; - #[ORM\Column(type: 'uuid', unique: true)] - private ?Uuid $uuid = null; + private ?Uuid $id = null; #[ORM\Column(length: 255)] private ?string $name = null; @@ -29,10 +25,10 @@ class Settlement #[ORM\Column(type: Types::ARRAY)] private array $coordinates = []; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeInterface $createAt = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeInterface $updateAt = null; /** @@ -46,23 +42,11 @@ class Settlement $this->restaurants = new ArrayCollection(); } - public function getId(): ?int + public function getId(): ?Uuid { return $this->id; } - public function getUuid(): ?Uuid - { - return $this->uuid; - } - - public function setUuid(Uuid $uuid): static - { - $this->uuid = $uuid; - - return $this; - } - public function getName(): ?string { return $this->name; diff --git a/src/Entity/Tags.php b/src/Entity/Tags.php index 34514ad..a52ff23 100644 --- a/src/Entity/Tags.php +++ b/src/Entity/Tags.php @@ -3,15 +3,16 @@ namespace App\Entity; use App\Repository\TagsRepository; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Uid\Uuid; #[ORM\Entity(repositoryClass: TagsRepository::class)] class Tags { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; + #[ORM\Column(type: 'uuid', unique: true)] + private ?Uuid $id = null; #[ORM\Column(length: 255)] private ?string $name = null; @@ -20,7 +21,10 @@ class Tags #[ORM\JoinColumn(nullable: false)] private ?Restaurant $restaurant = null; - public function getId(): ?int + #[ORM\Column(type: 'simple_array')] + private array $list = []; + + public function getId(): ?Uuid { return $this->id; } @@ -48,4 +52,16 @@ class Tags return $this; } + + public function getList(): array + { + return $this->list; + } + + public function setList(array $list): static + { + $this->list = $list; + + return $this; + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 7f1d85e..208382f 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -13,9 +13,8 @@ use Symfony\Component\Uid\Uuid; class User { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; + #[ORM\Column(type: 'uuid', unique: true)] + private ?Uuid $id = null; #[ORM\Column(type: 'uuid', unique: true)] private ?Uuid $uuid = null; @@ -34,23 +33,11 @@ class User $this->newsComments = new ArrayCollection(); } - public function getId(): ?int + public function getId(): ?Uuid { return $this->id; } - public function getUuid(): ?Uuid - { - return $this->uuid; - } - - public function setUuid(Uuid $uuid): static - { - $this->uuid = $uuid; - - return $this; - } - public function getName(): ?string { return $this->name; diff --git a/src/Repository/AddressRepository.php b/src/Repository/AddressRepository.php deleted file mode 100644 index e87117f..0000000 --- a/src/Repository/AddressRepository.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -namespace App\Repository; - -use App\Entity\Address; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; - -/** - * @extends ServiceEntityRepository<Address> - * - * @method Address|null find($id, $lockMode = null, $lockVersion = null) - * @method Address|null findOneBy(array $criteria, array $orderBy = null) - * @method Address[] findAll() - * @method Address[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class AddressRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Address::class); - } - -// /** -// * @return Address[] Returns an array of Address objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('a') -// ->andWhere('a.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('a.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } - -// public function findOneBySomeField($value): ?Address -// { -// return $this->createQueryBuilder('a') -// ->andWhere('a.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } -} diff --git a/src/Repository/EmailRepository.php b/src/Repository/EmailRepository.php deleted file mode 100644 index f22b0ee..0000000 --- a/src/Repository/EmailRepository.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -namespace App\Repository; - -use App\Entity\Email; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; - -/** - * @extends ServiceEntityRepository<Email> - * - * @method Email|null find($id, $lockMode = null, $lockVersion = null) - * @method Email|null findOneBy(array $criteria, array $orderBy = null) - * @method Email[] findAll() - * @method Email[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class EmailRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Email::class); - } - -// /** -// * @return Email[] Returns an array of Email objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('e') -// ->andWhere('e.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('e.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } - -// public function findOneBySomeField($value): ?Email -// { -// return $this->createQueryBuilder('e') -// ->andWhere('e.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } -} diff --git a/src/Repository/FileRepository.php b/src/Repository/FileRepository.php new file mode 100644 index 0000000..4d5449a --- /dev/null +++ b/src/Repository/FileRepository.php @@ -0,0 +1,48 @@ +<?php + +namespace App\Repository; + +use App\Entity\File; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; + +/** + * @extends ServiceEntityRepository<File> + * + * @method File|null find($id, $lockMode = null, $lockVersion = null) + * @method File|null findOneBy(array $criteria, array $orderBy = null) + * @method File[] findAll() + * @method File[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class FileRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, File::class); + } + +// /** +// * @return File[] Returns an array of File objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('f') +// ->andWhere('f.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('f.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?File +// { +// return $this->createQueryBuilder('f') +// ->andWhere('f.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/src/Repository/GalleryRepository.php b/src/Repository/GalleryRepository.php new file mode 100644 index 0000000..d15e89a --- /dev/null +++ b/src/Repository/GalleryRepository.php @@ -0,0 +1,48 @@ +<?php + +namespace App\Repository; + +use App\Entity\Gallery; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; + +/** + * @extends ServiceEntityRepository<Gallery> + * + * @method Gallery|null find($id, $lockMode = null, $lockVersion = null) + * @method Gallery|null findOneBy(array $criteria, array $orderBy = null) + * @method Gallery[] findAll() + * @method Gallery[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class GalleryRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Gallery::class); + } + +// /** +// * @return Gallery[] Returns an array of Gallery objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('g') +// ->andWhere('g.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('g.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Gallery +// { +// return $this->createQueryBuilder('g') +// ->andWhere('g.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/src/Repository/PhoneRepository.php b/src/Repository/PhoneRepository.php deleted file mode 100644 index de389d6..0000000 --- a/src/Repository/PhoneRepository.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -namespace App\Repository; - -use App\Entity\Phone; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; - -/** - * @extends ServiceEntityRepository<Phone> - * - * @method Phone|null find($id, $lockMode = null, $lockVersion = null) - * @method Phone|null findOneBy(array $criteria, array $orderBy = null) - * @method Phone[] findAll() - * @method Phone[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class PhoneRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Phone::class); - } - -// /** -// * @return Phone[] Returns an array of Phone objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('p') -// ->andWhere('p.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('p.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } - -// public function findOneBySomeField($value): ?Phone -// { -// return $this->createQueryBuilder('p') -// ->andWhere('p.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } -} diff --git a/src/Repository/SeoRepository.php b/src/Repository/SeoRepository.php new file mode 100644 index 0000000..09b0990 --- /dev/null +++ b/src/Repository/SeoRepository.php @@ -0,0 +1,48 @@ +<?php + +namespace App\Repository; + +use App\Entity\Seo; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; + +/** + * @extends ServiceEntityRepository<Seo> + * + * @method Seo|null find($id, $lockMode = null, $lockVersion = null) + * @method Seo|null findOneBy(array $criteria, array $orderBy = null) + * @method Seo[] findAll() + * @method Seo[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class SeoRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Seo::class); + } + +// /** +// * @return Seo[] Returns an array of Seo objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('s') +// ->andWhere('s.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('s.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Seo +// { +// return $this->createQueryBuilder('s') +// ->andWhere('s.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/tests/RestaurantControllerTest.php b/tests/RestaurantControllerTest.php new file mode 100644 index 0000000..c976e59 --- /dev/null +++ b/tests/RestaurantControllerTest.php @@ -0,0 +1,63 @@ +<?php + +declare(strict_types=1); + +namespace App\Tests; + +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +class RestaurantControllerTest extends WebTestCase +{ + public function testRestaurants(): void + { + $client = static::createClient(); + $content = $client->request('GET', '/api/v1/restaurants?page=1&limit=12'); + $actual = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR); + $expect = '{ + "pagination": { + "currentPage": 1, + "pages": 1, + "pageSize": 12 + }, + "list": [ + { + "id": 1, + "name": "РеÑторан «Ðрктика»", + "code": "restoran-arktika", + "type": { + "id": 1, + "name": "РеÑторан", + "code": "restoran" + }, + "check": "bla bla", + "image": { + "id": 1, + "name": "name", + "description": "description", + "size": 10, + "type": "jpg", + "url": "/upload/preview.png" + }, + "detailLink": "https://visityamal.ru/" + } + ], + "filterVariants": { + "type": [ + { + "id": 1, + "name": "РеÑторан", + "code": "restoran" + } + ], + "kitchen": [ + { + "id": 1, + "name": "ÐзиатÑкаÑ" + } + ] + } +}'; + self::assertResponseIsSuccessful(); + self::assertJsonStringEqualsJsonString($expect, $actual); + } +} -- GitLab