Skip to content

Commit

Permalink
TTK-26716 Add api platform (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurujai authored Nov 29, 2023
1 parent 3eb9e48 commit c0762d3
Show file tree
Hide file tree
Showing 18 changed files with 951 additions and 413 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"type": "project",
"description": "Media Portal",
"require": {
"php": "^7.4 || ^8.2",
"php": "^8.2",
"ext-curl": "*",
"ext-fileinfo": "*",
"ext-gd": "*",
"ext-json": "*",
"ext-mongodb": "*",
"ext-sysvsem": "*",
"ankitpokhrel/tus-php": "^2.0",
"api-platform/core": "^2.7",
"babdev/pagerfanta-bundle": "^2.11",
"doctrine/mongodb-odm-bundle": "^4.5",
"gedmo/doctrine-extensions": "^3.10",
Expand Down
1,194 changes: 784 additions & 410 deletions composer.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Pumukit\PaellaPlayerBundle\PumukitPaellaPlayerBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
];
73 changes: 73 additions & 0 deletions config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
api_platform:
title: 'PuMuKIT API'
description: 'Powerful API'
version: '0.0.0'
show_webby: false
mapping:
paths: [
'%kernel.project_dir%/src/Pumukit/SchemaBundle/Document',
'%kernel.project_dir%/src/Pumukit/EncoderBundle/Document'
]
patch_formats:
json: ['application/merge-patch+json']
swagger:
versions: [3]
doctrine:
enabled: false
doctrine_mongodb_odm:
enabled: true
# Enable ReDoc.
enable_re_doc: true

# Enable the entrypoint.
enable_entrypoint: true

# Enable the docs.
enable_docs: true

# Enable the data collector and the WebProfilerBundle integration.
enable_profiler: true
collection:
# The name of the query parameter to filter nullable results (with the ExistsFilter).
exists_parameter_name: 'exists'

# The default order of results.
order: 'ASC'

# The name of the query parameter to order results (with the OrderFilter).
order_parameter_name: 'order'

pagination:
# To enable or disable pagination for all resource collections by default.
enabled: true

# To allow partial pagination for all resource collections.
# This improves performances by skipping the `COUNT` query.
partial: false

# To allow the client to enable or disable the pagination.
client_enabled: false

# To allow the client to set the number of items per page.
client_items_per_page: false

# To allow the client to enable or disable the partial pagination.
client_partial: false

# The default number of items per page.
items_per_page: 25

# The maximum number of items per page.
maximum_items_per_page: 50

# The default name of the parameter handling the page number.
page_parameter_name: 'page'

# The name of the query parameter to enable or disable pagination.
enabled_parameter_name: 'pagination'

# The name of the query parameter to set the number of items per page.
items_per_page_parameter_name: 'itemsPerPage'

# The name of the query parameter to enable or disable the partial pagination.
partial_parameter_name: 'partial'
4 changes: 4 additions & 0 deletions config/routes/api_platform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
api_platform:
resource: .
type: api_platform
prefix: /api
6 changes: 6 additions & 0 deletions src/Pumukit/EncoderBundle/Document/CpuStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

namespace Pumukit\EncoderBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
* Pumukit\EncoderBundle\Document\CpuStatus.
*
* @MongoDB\Document(repositoryClass="Pumukit\EncoderBundle\Repository\CpuStatusRepository")
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class CpuStatus
{
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/EncoderBundle/Document/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

namespace Pumukit\EncoderBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Validator\Constraints as Assert;

/**
* Pumukit\EncoderBundle\Document\Job.
*
* @MongoDB\Document(repositoryClass="Pumukit\EncoderBundle\Repository\JobRepository")
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class Job
{
Expand Down
3 changes: 1 addition & 2 deletions src/Pumukit/NewAdminBundle/Services/TagCatalogueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ public function addSessionCriteria(Request $request, SessionInterface $session)
if (count($tag) > 0) {
if ('all' === $tag[0]) {
array_shift($tag);
}
if (!empty($tag)) {
} else {
$newCriteria['tags.cod'] = ['$all' => $tag];
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/SchemaBundle/Document/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
* @MongoDB\Document(repositoryClass="Pumukit\SchemaBundle\Repository\AnnotationRepository")
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class Annotation
{
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/SchemaBundle/Document/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @MongoDB\Document(repositoryClass="Pumukit\SchemaBundle\Repository\GroupRepository")
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class Group implements GroupInterface
{
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/SchemaBundle/Document/MultimediaObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Gedmo\Mapping\Annotation as Gedmo;
Expand All @@ -13,6 +14,11 @@
* @MongoDB\Document(repositoryClass="Pumukit\SchemaBundle\Repository\MultimediaObjectRepository")
*
* @MongoDB\Index(name="text_index", keys={"textindex.text"="text", "secondarytextindex.text"="text"}, options={"language_override"="indexlanguage", "default_language"="none", "weights"={"textindex.text"=10, "secondarytextindex.text"=1}})
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class MultimediaObject
{
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/SchemaBundle/Document/PermissionProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* @MongoDB\Document(repositoryClass="Pumukit\SchemaBundle\Repository\PermissionProfileRepository")
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class PermissionProfile
{
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/SchemaBundle/Document/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @MongoDB\Document(repositoryClass="Pumukit\SchemaBundle\Repository\PersonRepository")
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class Person implements PersonInterface
{
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/SchemaBundle/Document/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* @MongoDB\Document(repositoryClass="Pumukit\SchemaBundle\Repository\RoleRepository")
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class Role implements RoleInterface
{
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/SchemaBundle/Document/Series.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use JMS\Serializer\Annotation as Serializer;

/**
* @MongoDB\Document(repositoryClass="Pumukit\SchemaBundle\Repository\SeriesRepository")
*
* @MongoDB\Index(name="text_index", keys={"textindex.text"="text", "secondarytextindex.text"="text"}, options={"language_override"="indexlanguage", "default_language"="none", "weights"={"textindex.text"=10, "secondarytextindex.text"=1}})
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class Series
{
Expand Down
6 changes: 6 additions & 0 deletions src/Pumukit/SchemaBundle/Document/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -12,6 +13,11 @@
* @MongoDB\Document(repositoryClass="Gedmo\Tree\Document\MongoDB\Repository\MaterializedPathRepository")
*
* @Gedmo\Tree(type="materializedPath", activateLocking=false)
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class Tag implements TagInterface
{
Expand Down
12 changes: 12 additions & 0 deletions src/Pumukit/SchemaBundle/Document/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

namespace Pumukit\SchemaBundle\Document;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use MongoDB\BSON\ObjectId;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Ignore;

/**
* @MongoDB\Document(repositoryClass="Pumukit\SchemaBundle\Repository\UserRepository")
*
* @ApiResource(
* collectionOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}},
* itemOperations={"get"={"method"="GET", "access_control"="is_granted('ROLE_ACCESS_API')"}}
* )
*/
class User implements UserInterface
{
Expand Down Expand Up @@ -65,11 +72,13 @@ class User implements UserInterface
/**
* @MongoDB\Field(type="string")
*/
#[Ignore]
protected $salt;

/**
* @MongoDB\Field(type="string")
*/
#[Ignore]
protected $password;

/**
Expand All @@ -80,6 +89,7 @@ class User implements UserInterface
/**
* @MongoDB\Field(type="string")
*/
#[Ignore]
protected $plainPassword;

/**
Expand All @@ -90,11 +100,13 @@ class User implements UserInterface
/**
* @MongoDB\Field(type="string")
*/
#[Ignore]
protected $confirmationToken;

/**
* @MongoDB\Field(type="date")
*/
#[Ignore]
protected $passwordRequestedAt;

/**
Expand Down
14 changes: 14 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
{
"api-platform/core": {
"version": "2.7",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "2.5",
"ref": "b86557ce5677fa855b1b2608f4a4bc4a8fed8be7"
},
"files": [
"config/packages/api_platform.yaml",
"config/routes/api_platform.yaml",
"src/Entity/.gitignore"
]
},
"babdev/pagerfanta-bundle": {
"version": "v2.11.0"
},
Expand Down

0 comments on commit c0762d3

Please sign in to comment.