Skip to content

Commit

Permalink
Merge pull request #18 from CartONG/feature/page-projets
Browse files Browse the repository at this point in the history
Feature/page projets
  • Loading branch information
plduthoit authored Oct 14, 2024
2 parents 8aaadab + e9c79c9 commit d88c363
Show file tree
Hide file tree
Showing 112 changed files with 2,066 additions and 677 deletions.
9 changes: 5 additions & 4 deletions symfony/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ sf: ## List all Symfony commands or pass the parameter "c=" to run a given comma
cc: c=c:c ## Clear the cache
cc: sf

reset-database-schema:
@$(SYMFONY) do:s:u -f

recreate-database: restart-db-container drop-database create-database
recreate-database: restart-db-container drop-database create-database configure-database

drop-database:
@$(SYMFONY) do:da:dr -f --if-exists
Expand All @@ -54,9 +51,13 @@ make-entity:
regenerate-entity:
@$(SYMFONY) make:entity --regenerate

enable-postgis:
@$(SYMFONY) dbal:run-sql 'CREATE extension postgis;'

make-run-migration: make-migration run-migration
reset-database: recreate-database run-migration
rerun-database: reset-database run-fixtures
configure-database: enable-postgis
create-short-migration: recreate-database run-migration make-migration rerun-migration

init-jwt-keypair:
Expand Down
1 change: 1 addition & 0 deletions symfony/config/packages/hautelook_alice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ when@dev: &dev
fixtures_path: fixtures

when@test: *dev
when@prod: *dev
1 change: 1 addition & 0 deletions symfony/config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ security:
- { path: ^/auth, roles: PUBLIC_ACCESS }
- { path: ^/api/users, roles: PUBLIC_ACCESS, methods: [POST]}
- { path: ^/api/actors, roles: PUBLIC_ACCESS, methods: [GET] }
- { path: ^/api/projects, roles: PUBLIC_ACCESS, methods: [GET] }
- { path: ^/api/actor_expertises, roles: PUBLIC_ACCESS, methods: [GET] }
- { path: ^/api/thematics, roles: PUBLIC_ACCESS, methods: [GET] }
- { path: ^/api/administrative_scopes, roles: PUBLIC_ACCESS, methods: [GET] }
Expand Down
4 changes: 2 additions & 2 deletions symfony/fixtures/actors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ App\Entity\Actor:
email: <email()>
logo: <imageUrl(200, 200)>
projects: '<numberBetween(1, 8)>x @project_*'
created_at: '<dateTimeBetween("-200 days", "now")>'
updated_at: '<dateTimeBetween($created_at, "now")>'
createdAt: '<dateTimeBetween("-200 days", "now")>'
updatedAt: '<dateTimeBetween($createdAt, "now")>'
7 changes: 7 additions & 0 deletions symfony/fixtures/actorsExpertise.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
App\Entity\ActorExpertise:
actorexpertise_1:
name: Planification urbaine
actorexpertise_2:
name: Elaboration et mise en œuvre de la politique algorithmique de la nation ainsi que de l’aménagement du territoire
actorexpertise_3:
name: Production de l’Information Géospatiale
9 changes: 9 additions & 0 deletions symfony/fixtures/administrativeScopes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
App\Entity\AdministrativeScope:
administrative_scope_1:
name: National
administrative_scope_2:
name: Régional
administrative_scope_3:
name: Départemental
administrative_scope_4:
name: Communal
11 changes: 6 additions & 5 deletions symfony/fixtures/projects.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
App\Entity\Project:
project_{1..100}:
title: <city()> Urban Development
project_{1..500}:
name: <city()> Urban Development
location: <city()>
coords: 'POINT(<longitude()> <latitude()>)'
status: '<randomElement(<(App\Enum\Status::toArray())>)>' # Remplace par les valeurs de ton Enum Status
# 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)>
images: []
partners: []
interventionZone: '<randomElement(<(App\Enum\AdministrativeScopes::toArray())>)>' # Remplace par les valeurs de ton Enum AdministrativeScopes
interventionZone: '<randomElement(<(App\Enum\AdministrativeScope::toArray())>)>'
financialActors: '<numberBetween(1, 5)>x @actor_*'
actor: '@actor_*'
contractingActors: '<numberBetween(1, 5)>x @actor_*'
Expand Down
28 changes: 0 additions & 28 deletions symfony/migrations/Version20241001093511.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241008150316 extends AbstractMigration
final class Version20241011202727 extends AbstractMigration
{
public function getDescription(): string
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public function up(Schema $schema): void
$this->addSql('COMMENT ON COLUMN actor_administrative_scope.actor_id IS \'(DC2Type:uuid)\'');
$this->addSql('CREATE TABLE actor_expertise (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE administrative_scope (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE project (id INT NOT NULL, actor_id UUID NOT NULL, title VARCHAR(255) NOT NULL, location VARCHAR(255) NOT NULL, coords geometry(POINT, 0) NOT NULL, status VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, images JSON DEFAULT NULL, partners JSON DEFAULT NULL, intervention_zone VARCHAR(255) NOT NULL, project_manager_name VARCHAR(255) DEFAULT NULL, project_manager_position VARCHAR(255) DEFAULT NULL, project_manager_email VARCHAR(255) DEFAULT NULL, project_manager_tel VARCHAR(255) DEFAULT NULL, project_manager_photo VARCHAR(255) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, logo VARCHAR(255) DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE project (id INT NOT NULL, actor_id UUID NOT NULL, name VARCHAR(255) NOT NULL, location VARCHAR(255) NOT NULL, coords geometry(POINT, 0) NOT NULL, status VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, images JSON DEFAULT NULL, partners JSON DEFAULT NULL, intervention_zone VARCHAR(255) NOT NULL, project_manager_name VARCHAR(255) DEFAULT NULL, project_manager_position VARCHAR(255) DEFAULT NULL, project_manager_email VARCHAR(255) DEFAULT NULL, project_manager_tel VARCHAR(255) DEFAULT NULL, project_manager_photo VARCHAR(255) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, logo VARCHAR(255) DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_2FB3D0EE10DAF24A ON project (actor_id)');
$this->addSql('COMMENT ON COLUMN project.actor_id IS \'(DC2Type:uuid)\'');
$this->addSql('CREATE TABLE project_thematic (project_id INT NOT NULL, thematic_id INT NOT NULL, PRIMARY KEY(project_id, thematic_id))');
Expand All @@ -57,7 +57,7 @@ public function up(Schema $schema): void
$this->addSql('CREATE INDEX IDX_E73AB79010DAF24A ON contracted_projects_actors (actor_id)');
$this->addSql('COMMENT ON COLUMN contracted_projects_actors.actor_id IS \'(DC2Type:uuid)\'');
$this->addSql('CREATE TABLE thematic (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE "user" (id INT NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, is_validated BOOLEAN NOT NULL, requested_roles JSON DEFAULT NULL, organisation VARCHAR(255) DEFAULT NULL, position VARCHAR(255) DEFAULT NULL, phone VARCHAR(20) DEFAULT NULL, sign_up_message TEXT DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE "user" (id INT NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) DEFAULT NULL, is_validated BOOLEAN NOT NULL, requested_roles JSON DEFAULT NULL, organisation VARCHAR(255) DEFAULT NULL, position VARCHAR(255) DEFAULT NULL, phone VARCHAR(20) DEFAULT NULL, sign_up_message TEXT DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('ALTER TABLE actor ADD CONSTRAINT FK_447556F9B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE actor_actor_expertise ADD CONSTRAINT FK_4A438EAD10DAF24A FOREIGN KEY (actor_id) REFERENCES actor (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE actor_actor_expertise ADD CONSTRAINT FK_4A438EAD916905AC FOREIGN KEY (actor_expertise_id) REFERENCES actor_expertise (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
Expand Down
5 changes: 2 additions & 3 deletions symfony/src/Entity/Actor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use ApiPlatform\Metadata\GetCollection;
use App\Entity\Trait\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use Symfony\Bundle\SecurityBundle\Security;
use App\Services\State\Provider\ActorProvider;
use App\Services\State\Processor\ActorProcessor;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down Expand Up @@ -74,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])]
#[Groups([self::ACTOR_READ_ITEM_COLLECTION, self::ACTOR_READ_ITEM, self::ACTOR_WRITE, Project::PROJECT_READ_ALL])]
private ?string $name = null;

#[ORM\Column(length: 255)]
#[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_ALL])]
private ?string $acronym = null;

#[ORM\ManyToOne(inversedBy: 'actorsCreated')]
Expand Down
56 changes: 41 additions & 15 deletions symfony/src/Entity/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace App\Entity;

use ApiPlatform\Metadata\GetCollection;
use App\Enum\AdministrativeScope;
use App\Enum\Status;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Enum\AdministrativeScopes;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\ProjectRepository;
use App\Entity\Trait\TimestampableEntity;
Expand All @@ -15,30 +16,44 @@
use Symfony\Component\Serializer\Attribute\Groups;

#[ORM\Entity(repositoryClass: ProjectRepository::class)]
#[ApiResource]
#[ApiResource(
paginationEnabled: false,
operations: [
new GetCollection(
normalizationContext: ['groups' => [self::PROJECT_READ_ALL]]
)
]
)]
class Project
{
use TimestampableEntity;

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])]
private ?int $id = null;

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

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

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

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

#[ORM\Column(type: Types::TEXT, nullable: true)]
Expand All @@ -50,13 +65,15 @@ class Project
#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $partners = null;

#[ORM\Column(enumType: AdministrativeScopes::class)]
private ?AdministrativeScopes $interventionZone = null;
#[ORM\Column(enumType: AdministrativeScope::class)]
#[Groups([self::PROJECT_READ_ALL])]
private ?AdministrativeScope $interventionZone = null;

/**
* @var Collection<int, Thematic>
*/
#[ORM\ManyToMany(targetEntity: Thematic::class, inversedBy: 'projects')]
#[Groups([self::PROJECT_READ_ALL])]
private Collection $thematics;

#[ORM\Column(length: 255, nullable: true)]
Expand All @@ -78,13 +95,15 @@ class Project
private ?string $website = null;

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

/**
* @var Collection<int, Actor>
*/
#[ORM\JoinTable(name: 'financed_projects_actors')]
#[ORM\ManyToMany(targetEntity: Actor::class)]
#[Groups([self::PROJECT_READ_ALL])]
private Collection $financialActors;

/**
Expand All @@ -93,10 +112,12 @@ class Project

#[ORM\JoinTable(name: 'contracted_projects_actors')]
#[ORM\ManyToMany(targetEntity: Actor::class)]
#[Groups([self::PROJECT_READ_ALL])]
private Collection $contractingActors;

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

public function __construct()
Expand All @@ -111,14 +132,14 @@ public function getId(): ?int
return $this->id;
}

public function getTitle(): ?string
public function getName(): ?string
{
return $this->title;
return $this->name;
}

public function setTitle(string $title): static
public function setName(string $name): static
{
$this->title = $title;
$this->name = $name;

return $this;
}
Expand All @@ -135,9 +156,14 @@ public function setLocation(string $location): static
return $this;
}

public function getCoords(): ?string
{
return $this->coords;
public function getCoords(): ?array {
if (preg_match('/POINT\(([-\d\.]+) ([-\d\.]+)\)/', $this->coords, $matches)) {
return [
'lat' => (float)$matches[1],
'long' => (float)$matches[2],
];
}
return null;
}

public function setCoords(string $coords): static
Expand Down Expand Up @@ -195,12 +221,12 @@ public function setPartners(?array $partners): static
return $this;
}

public function getInterventionZone(): ?AdministrativeScopes
public function getInterventionZone(): ?AdministrativeScope
{
return $this->interventionZone;
}

public function setInterventionZone(AdministrativeScopes $interventionZone): static
public function setInterventionZone(AdministrativeScope $interventionZone): static
{
$this->interventionZone = $interventionZone;

Expand Down
6 changes: 5 additions & 1 deletion symfony/src/Entity/Thematic.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#[ORM\Entity(repositoryClass: ThematicRepository::class)]
#[UniqueEntity('name')]
#[ApiResource(
paginationEnabled: false,
operations: [
new GetCollection(),
new Post(
Expand All @@ -28,13 +29,16 @@
)]
class Thematic
{
public const THEMATIC_READ = 'thematic:read';

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

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

/**
Expand Down
3 changes: 3 additions & 0 deletions symfony/src/Entity/Trait/TimestampableEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Entity\Trait;

use App\Entity\Project;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Attribute\Groups;

trait TimestampableEntity
{
Expand All @@ -14,6 +16,7 @@ trait TimestampableEntity

#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups([Project::PROJECT_READ_ALL])]
protected ?\DateTimeInterface $updatedAt;

public function getCreatedAt(): ?\DateTimeInterface
Expand Down
14 changes: 14 additions & 0 deletions symfony/src/Enum/AdministrativeScope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace App\Enum;

use App\Enum\Trait\ToArray;

enum AdministrativeScope: string
{
case NATIONAL = 'national';
case REGIONAL = 'regional';
case STATE = 'state';
case CITY = 'city';

use ToArray;
}
Loading

0 comments on commit d88c363

Please sign in to comment.