Create org on remote call
This commit is contained in:
parent
829469b1c5
commit
4ac179f7b6
12
docs/API.md
12
docs/API.md
|
|
@ -41,6 +41,7 @@ The route should be as follows:
|
|||
```
|
||||
Keep the same structure for the project tree, create an Api folder in the controller, a V1 folder and then create your controller.
|
||||
Here is a full example of a controller with the create method.
|
||||
On crée une organization si elle n'existe pas
|
||||
```php
|
||||
<?php
|
||||
#[Route('/api/v2/project', name: 'api_project_')]
|
||||
|
|
@ -58,7 +59,12 @@ class ProjectApi extends AbstractController{
|
|||
$data = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$projet = new Projet();
|
||||
|
||||
$entity = $this->entityManager->getRepository(Entity::class)->find($data['entity_id']);
|
||||
$entity = $this->entityManager->getRepository(Entity::class)->findOneBy([ 'ssoId' => $data['orgId']]);
|
||||
// Si l'entité n'existe pas, on la crée
|
||||
if(!$entity){
|
||||
$this->createEntity($data['orgId'], $data['orgName']);
|
||||
$entity = $this->entityManager->getRepository(Entity::class)->findOneBy([ 'ssoId' => $data['orgId']]);
|
||||
}
|
||||
$precision= $data['timestamp'];
|
||||
$validPrecisions = array_map(fn($case) => $case->value, TimestampPrecision::cases());
|
||||
if (!in_array($precision, $validPrecisions, true)) {
|
||||
|
|
@ -68,10 +74,10 @@ class ProjectApi extends AbstractController{
|
|||
try {
|
||||
$timestampPrecision = TimestampPrecision::from($precision);
|
||||
$projet->setTimestampPrecision($timestampPrecision);
|
||||
$projet->setProjet($data['projet']);
|
||||
$projet->setProjet($data['name']);
|
||||
$projet->setEntityId($entity);
|
||||
$projet->setBdd($data['bdd']);
|
||||
$projet->setIsactive($data['isactive']);
|
||||
$projet->setIsactive($data['isActive']);
|
||||
$projet->setLogo($data['logo']);
|
||||
$projet->setDeletionAllowed($data['deletion']);
|
||||
$projet->setSsoId($data['id']); // c'est l'id du projet dans le portail, pas la bdd local
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ class ProjectService
|
|||
'id' => $project->getId(),
|
||||
'name' => $project->getName(),
|
||||
'orgId' => $project->getOrganization()->getId(),
|
||||
'orgName' => $project->getOrganization()->getName(),
|
||||
'bdd' => $project->getBddName(),
|
||||
'isActive' => $project->isActive(),
|
||||
'logo' => $project->getLogo(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue