Skip to content

Commit

Permalink
Merge pull request #20 from CartONG/feature/fiche-projet
Browse files Browse the repository at this point in the history
Feature/fiche projet
  • Loading branch information
0live authored Oct 17, 2024
2 parents fd381b7 + 2ee6ccd commit db480bc
Show file tree
Hide file tree
Showing 61 changed files with 1,655 additions and 409 deletions.
2 changes: 1 addition & 1 deletion symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.2",
"lexik/jwt-authentication-bundle": "^3.1",
"gedmo/doctrine-extensions": "^3.16",
"stof/doctrine-extensions-bundle": "^1.7",
"hautelook/alice-bundle": "^2.14",
"jsor/doctrine-postgis": "^2.3",
"nelmio/cors-bundle": "^2.5",
Expand Down
201 changes: 142 additions & 59 deletions symfony/composer.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions symfony/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
Hautelook\AliceBundle\HautelookAliceBundle::class => ['all' => true],
Sentry\SentryBundle\SentryBundle::class => ['prod' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
];
10 changes: 10 additions & 0 deletions symfony/config/packages/stof_doctrine_extensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Read the documentation: https://symfony.com/doc/current/bundles/StofDoctrineExtensionsBundle/index.html
# See the official DoctrineExtensions documentation for more details: https://github.com/doctrine-extensions/DoctrineExtensions/tree/main/doc
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
tree: true
blameable: true
sluggable: true
timestampable: true
9 changes: 5 additions & 4 deletions symfony/fixtures/projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ App\Entity\Project:
# coords: 'POINT(<longitude()> <latitude()>)'
coords: 'POINT(<randomFloat(11, 12.8593962671, 1.72767263428)> <randomFloat(11, 16.0128524106, 8.48881554529)>)'
status: '<randomElement(<(App\Enum\Status::toArray())>)>'
description: <paragraph(2)>
description: <paragraph(8)>
deliverables: <paragraph(8)>
calendar: <paragraph(8)>
images: []
partners: []
interventionZone: '<randomElement(<(App\Enum\AdministrativeScope::toArray())>)>'
Expand All @@ -17,8 +19,7 @@ App\Entity\Project:
projectManagerPosition: <jobTitle()>
projectManagerEmail: <email()>
projectManagerTel: <phoneNumber()>
projectManagerPhoto: <imageUrl(400, 400)>
projectManagerPhoto: 'https://randomuser.me/api/portraits/men/<randomNumber(1, 92)>.jpg'
website: <url()>
logo: <imageUrl(200, 100)>
created_at: '<dateTimeBetween("-200 days", "now")>'
updated_at: '<dateTimeBetween($created_at, "now")>'
createdBy: '@user_*'
50 changes: 50 additions & 0 deletions symfony/migrations/Version20241016124248.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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 Version20241016124248 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('ALTER TABLE project ADD created_by INT DEFAULT NULL');
$this->addSql('ALTER TABLE project ADD updated_by INT DEFAULT NULL');
$this->addSql('ALTER TABLE project ADD deliverables TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE project ADD calendar TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE project ADD slug VARCHAR(128) DEFAULT NULL');
$this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EEDE12AB56 FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE16FE72E1 FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE989D9B62 ON project (slug)');
$this->addSql('CREATE INDEX IDX_2FB3D0EEDE12AB56 ON project (created_by)');
$this->addSql('CREATE INDEX IDX_2FB3D0EE16FE72E1 ON project (updated_by)');
}

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 project DROP CONSTRAINT FK_2FB3D0EEDE12AB56');
$this->addSql('ALTER TABLE project DROP CONSTRAINT FK_2FB3D0EE16FE72E1');
$this->addSql('DROP INDEX UNIQ_2FB3D0EE989D9B62');
$this->addSql('DROP INDEX IDX_2FB3D0EEDE12AB56');
$this->addSql('DROP INDEX IDX_2FB3D0EE16FE72E1');
$this->addSql('ALTER TABLE project DROP created_by');
$this->addSql('ALTER TABLE project DROP updated_by');
$this->addSql('ALTER TABLE project DROP deliverables');
$this->addSql('ALTER TABLE project DROP calendar');
$this->addSql('ALTER TABLE project DROP slug');
}
}
21 changes: 21 additions & 0 deletions symfony/src/Controller/Project/SimilarProjectsAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace App\Controller\Project;

use App\Entity\Project;
use App\Repository\ProjectRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Attribute\AsController;

#[AsController]
class SimilarProjectsAction extends AbstractController
{
public function __construct(
private ProjectRepository $projectRepository,
) {}

public function __invoke(Project $project): array
{
$similarProjects = $this->projectRepository->findTwoSimilarProjectsByThematics($project);
return $similarProjects;
}
}
10 changes: 5 additions & 5 deletions symfony/src/Entity/Actor.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class Actor
private ?Uuid $id = null;

#[ORM\Column(length: 255)]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION, self::ACTOR_READ_ITEM, self::ACTOR_WRITE, Project::PROJECT_READ_ALL])]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION, self::ACTOR_READ_ITEM, self::ACTOR_WRITE, Project::PROJECT_READ_ALL, Project::PROJECT_READ])]
private ?string $name = null;

#[ORM\Column(length: 255)]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION, self::ACTOR_READ_ITEM, self::ACTOR_WRITE, Project::PROJECT_READ_ALL])]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION, self::ACTOR_READ_ITEM, self::ACTOR_WRITE, Project::PROJECT_READ_ALL, Project::PROJECT_READ])]
private ?string $acronym = null;

#[ORM\ManyToOne(inversedBy: 'actorsCreated')]
Expand All @@ -90,7 +90,7 @@ class Actor
private ?bool $isValidated = false;

#[ORM\Column(enumType: ActorCategory::class)]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION, self::ACTOR_READ_ITEM, self::ACTOR_WRITE])]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION, self::ACTOR_READ_ITEM, self::ACTOR_WRITE, Project::PROJECT_READ])]
private ?ActorCategory $category = null;

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ class Actor
private Collection $projects;

#[ORM\Column(length: 255, nullable: true)]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION,self::ACTOR_READ_ITEM, self::ACTOR_WRITE])]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION,self::ACTOR_READ_ITEM, self::ACTOR_WRITE, Project::PROJECT_READ])]
private ?string $logo = null;

/**
Expand Down Expand Up @@ -189,7 +189,7 @@ public function getAcronym(): ?string

public function setAcronym(string $acronym): static
{
$this->acronym = $acronym;
$this->acronym = strtoupper($acronym);

return $this;
}
Expand Down
78 changes: 69 additions & 9 deletions symfony/src/Entity/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,91 @@

namespace App\Entity;

use ApiPlatform\Doctrine\Common\Filter\SearchFilterInterface;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\GetCollection;
use App\Enum\AdministrativeScope;
use App\Enum\Status;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\QueryParameter;
use App\Controller\Project\SimilarProjectsAction;
use App\Repository\ProjectRepository;
use App\Entity\Trait\SluggableEntity;
use App\Entity\Trait\TimestampableEntity;
use App\Entity\Trait\BlameableEntity;
use Doctrine\Common\Collections\Collection;
use Jsor\Doctrine\PostGIS\Types\PostGISType;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Attribute\Groups;

#[ORM\Entity(repositoryClass: ProjectRepository::class)]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['slug' => SearchFilterInterface::STRATEGY_EXACT])]
#[ApiResource(
paginationEnabled: false,
operations: [
new GetCollection(
uriTemplate: '/projects/all',
normalizationContext: ['groups' => [self::PROJECT_READ_ALL]]
)
),
new GetCollection(
normalizationContext: ['groups' => [self::PROJECT_READ]],
parameters: [
'slug' => new QueryParameter()
]
),
new GetCollection(
uriTemplate: '/projects/{id}/similar',
controller: SimilarProjectsAction::class,
normalizationContext: ['groups' => [self::PROJECT_READ_ALL]]
),
]
)]
class Project
{
use TimestampableEntity;
use BlameableEntity;
use SluggableEntity;

public const PROJECT_READ = 'project:read';
public const PROJECT_READ_ALL = 'project:read:all';

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups([self::PROJECT_READ_ALL])]
#[Groups([self::PROJECT_READ, self::PROJECT_READ_ALL])]
private ?int $id = null;

#[ORM\Column(length: 255)]
#[Groups([self::PROJECT_READ_ALL, Actor::ACTOR_READ_ITEM])]
#[Groups([self::PROJECT_READ, self::PROJECT_READ_ALL, Actor::ACTOR_READ_ITEM])]
private ?string $name = null;

#[ORM\Column(length: 255)]
#[Groups([self::PROJECT_READ_ALL])]
#[Groups([self::PROJECT_READ, self::PROJECT_READ_ALL])]
private ?string $location = null;

#[ORM\Column(
type: PostGISType::GEOMETRY,
options: ['geometry_type' => 'POINT'],
)]
#[Groups([self::PROJECT_READ_ALL])]
#[Groups([self::PROJECT_READ, self::PROJECT_READ_ALL])]
private ?string $coords = null;

#[ORM\Column(enumType: Status::class)]
#[Groups([self::PROJECT_READ_ALL])]
#[Groups([self::PROJECT_READ, self::PROJECT_READ_ALL])]
private ?Status $status = null;

#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups([self::PROJECT_READ])]
private ?string $description = null;

#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $images = null;

#[ORM\Column(type: Types::JSON, nullable: true)]
#[Groups([self::PROJECT_READ])]
private ?array $partners = null;

#[ORM\Column(enumType: AdministrativeScope::class)]
Expand All @@ -73,29 +97,33 @@ class Project
* @var Collection<int, Thematic>
*/
#[ORM\ManyToMany(targetEntity: Thematic::class, inversedBy: 'projects')]
#[Groups([self::PROJECT_READ_ALL])]
#[Groups([self::PROJECT_READ, self::PROJECT_READ_ALL])]
private Collection $thematics;

#[ORM\Column(length: 255, nullable: true)]
#[Groups([self::PROJECT_READ])]
private ?string $projectManagerName = null;

#[ORM\Column(length: 255, nullable: true)]
#[Groups([self::PROJECT_READ])]
private ?string $projectManagerPosition = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $projectManagerEmail = null;

#[ORM\Column(length: 255, nullable: true)]
#[Groups([self::PROJECT_READ])]
private ?string $projectManagerTel = null;

#[ORM\Column(length: 255, nullable: true)]
#[Groups([self::PROJECT_READ])]
private ?string $projectManagerPhoto = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $website = null;

#[ORM\Column(length: 255, nullable: true)]
#[Groups([self::PROJECT_READ_ALL])]
#[Groups([self::PROJECT_READ, self::PROJECT_READ_ALL])]
private ?string $logo = null;

/**
Expand All @@ -117,9 +145,17 @@ class Project

#[ORM\ManyToOne(inversedBy: 'projects')]
#[ORM\JoinColumn(nullable: false)]
#[Groups([self::PROJECT_READ_ALL])]
#[Groups([self::PROJECT_READ, self::PROJECT_READ_ALL])]
private ?Actor $actor = null;

#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups([self::PROJECT_READ])]
private ?string $deliverables = null;

#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups([self::PROJECT_READ])]
private ?string $calendar = null;

public function __construct()
{
$this->thematics = new ArrayCollection();
Expand Down Expand Up @@ -400,4 +436,28 @@ public function setActor(?Actor $actor): static

return $this;
}

public function getDeliverables(): ?string
{
return $this->deliverables;
}

public function setDeliverables(?string $deliverables): static
{
$this->deliverables = $deliverables;

return $this;
}

public function getCalendar(): ?string
{
return $this->calendar;
}

public function setCalendar(?string $calendar): static
{
$this->calendar = $calendar;

return $this;
}
}
4 changes: 2 additions & 2 deletions symfony/src/Entity/Thematic.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class Thematic
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups([self::THEMATIC_READ, Project::PROJECT_READ_ALL])]
#[Groups([self::THEMATIC_READ, Project::PROJECT_READ, Project::PROJECT_READ_ALL])]
private ?int $id = null;

#[ORM\Column(length: 255)]
#[Groups([self::THEMATIC_READ, Actor::ACTOR_READ_ITEM, Project::PROJECT_READ_ALL])]
#[Groups([self::THEMATIC_READ, Actor::ACTOR_READ_ITEM, Project::PROJECT_READ, Project::PROJECT_READ_ALL])]
private ?string $name = null;

/**
Expand Down
Loading

0 comments on commit db480bc

Please sign in to comment.