Addind API endpoint for savedExport

This commit is contained in:
Lucas Silva 2023-04-25 13:43:55 +02:00
parent bef1d6b4a3
commit 60c9e037a6
4 changed files with 95 additions and 7 deletions

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
class SavedExportApiController extends ApiController
{
}

View File

@ -19,6 +19,7 @@ use Chill\MainBundle\Controller\LanguageController;
use Chill\MainBundle\Controller\LocationController;
use Chill\MainBundle\Controller\LocationTypeController;
use Chill\MainBundle\Controller\RegroupmentController;
use Chill\MainBundle\Controller\SavedExportApiController;
use Chill\MainBundle\Controller\UserController;
use Chill\MainBundle\Controller\UserJobApiController;
use Chill\MainBundle\Controller\UserJobController;
@ -51,6 +52,7 @@ use Chill\MainBundle\Entity\Language;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\LocationType;
use Chill\MainBundle\Entity\Regroupment;
use Chill\MainBundle\Entity\SavedExport;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Form\CivilityType;
@ -230,7 +232,7 @@ class ChillMainExtension extends Extension implements
$twigConfig = [
'globals' => [
'installation' => [
'name' => $config['installation_name'], ],
'name' => $config['installation_name'],],
'available_languages' => $config['available_languages'],
'add_address' => $config['add_address'],
],
@ -328,11 +330,12 @@ class ChillMainExtension extends Extension implements
* Load parameter for configuration and set parameters for api.
*/
protected function configureCruds(
ContainerBuilder $container,
array $crudConfig,
array $apiConfig,
ContainerBuilder $container,
array $crudConfig,
array $apiConfig,
Loader\YamlFileLoader $loader
): void {
): void
{
if (count($crudConfig) === 0) {
return;
}
@ -746,8 +749,29 @@ class ChillMainExtension extends Extension implements
],
],
],
],
[
'class' => SavedExport::class,
'controller' => SavedExportApiController::class,
'name' => 'saved_export',
'base_path' => '/api/1.0/main/saved-export',
'base_role' => 'ROLE_USER',
'actions' => [
'_index' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
],
],
'_entity' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
],
],
],
]
],
]
]);
}
}

View File

@ -19,6 +19,7 @@ use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity
@ -33,6 +34,7 @@ class SavedExport implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Assert\NotBlank
* @Groups({"read"})
*/
private string $description = '';
@ -45,22 +47,26 @@ class SavedExport implements TrackCreationInterface, TrackUpdateInterface
* @ORM\Id
* @ORM\Column(name="id", type="uuid", unique="true")
* @ORM\GeneratedValue(strategy="NONE")
* @Groups({"read"})
*/
private UuidInterface $id;
/**
* @ORM\Column(type="json", nullable=false, options={"default": "[]"})
* @Groups({"read"})
*/
private array $options = [];
/**
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Assert\NotBlank
* @Groups({"read"})
*/
private string $title = '';
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @Groups({"read"})
*/
private User $user;

View File

@ -10,6 +10,22 @@ servers:
components:
schemas:
SavedExport:
type: object
properties:
id:
type: integer
user_id:
type: integer
description:
type: string
exportalias:
type: string
options:
type: string #TODO -> je pense que c'est object
title:
type: string
User:
type: object
properties:
@ -791,7 +807,7 @@ paths:
/1.0/main/civility.json:
get:
tags:
- civility
- civility
summary: Return all civility types
responses:
200:
@ -843,3 +859,27 @@ paths:
403:
description: "Unauthorized"
/1.0/main/saved-export/{id}.json:
get:
tags:
- export
summary: Return a specific saved export who is saved by an existing user.
parameters:
- name: id
in: path
required: true
description: The saved export id
schema:
type: string
format: string
responses:
200:
description: "ok"
content:
application/json:
schema:
type: string
items:
$ref: '#/components/schemas/SavedExport'
403:
description: "Unauthorized"