Skip to content

Commit

Permalink
Merge pull request #9 from xsga/v7.1.0
Browse files Browse the repository at this point in the history
Release V7.1.0
  • Loading branch information
xsga authored Nov 20, 2024
2 parents 187def7 + 25f4bb0 commit 7c006b3
Show file tree
Hide file tree
Showing 90 changed files with 648 additions and 392 deletions.
5 changes: 0 additions & 5 deletions .devcontainer/.devcontainer.json

This file was deleted.

11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"image": "mcr.microsoft.com/devcontainers/php:8.3",
"customizations": {
"vscode": {
"extensions": [
"gruntfuggly.todo-tree",
"vscode-icons-team.vscode-icons"
]
}
}
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ COPY config/etc/php/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Working directory.
WORKDIR /opt/app
WORKDIR /opt/app
71 changes: 67 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Language](https://img.shields.io/github/languages/top/xsga/filmaffinity-api)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.3-8892BF?style=flat)](https://php.net/)
[![Latest version](https://img.shields.io/github/v/release/xsga/filmaffinity-api)](https://github.com/xsga/filmaffinity-api/releases/tag/v7.0.0)
[![Latest version](https://img.shields.io/github/v/release/xsga/filmaffinity-api)](https://github.com/xsga/filmaffinity-api/releases/tag/v7.1.0)
[![License](https://img.shields.io/github/license/xsga/filmaffinity-api)](https://opensource.org/licenses/MIT)

FilmAffinity-API is a public and non offical API wich allow you to get information about films from [FilmAffinity](http://filmaffinity.com "FilmAffinity Home") website. You can search films and get their complet information, including cast, synopsis and cover.
Expand Down Expand Up @@ -74,9 +74,10 @@ The API has the following public methods:

|Method name|HTTP method|API endpoint|Body|
|-----------|-----------|------------|----|
|Simple films search|POST|searches/simple|Y|
|Advanced films search|POST|searches/advanced|Y|
|Get film information|GET|films/:id|URL parameter (:id)|
|Get user token|POST|users/token|[JSON Schema](https://github.com/xsga/filmaffinity-api/blob/master/config/schemas/input/get.token.schema.json)|
|Simple films search|POST|searches/simple|[JSON Schema](https://github.com/xsga/filmaffinity-api/blob/master/config/schemas/input/simple.search.schema.json)|
|Advanced films search|POST|searches/advanced|[JSON Schema](https://github.com/xsga/filmaffinity-api/blob/master/config/schemas/input/advanced.search.schema.json)|
|Get film information|GET|films/:id|-|
|Get genres|GET|genres|-|
|Get countries|GET|countries|-|

Expand Down Expand Up @@ -145,6 +146,59 @@ docker exec -it filmaffinityapi-web-server php .bin/console <COMMAND>
```

### Advanced films search

**EXAMPLE 1:** An example of an advanced search searching only for a text in the title of the film.

**URL**
```
[POST] http://<server_domain_api>/searches/advanced
```

**INPUT**
```json
{
"text": "pulp fiction",
"search_in_title": true,
"search_in_director": false,
"search_in_cast": false,
"search_in_screenplay": false,
"search_in_photography": false,
"search_in_soundtrack": false,
"search_in_producer": false,
"country": "",
"genre": "",
"year_from": 0,
"year_to": 0
}
```

**OUTPUT**
```json
{
"status": "OK",
"statusCode": 200,
"response": {
"total": 1,
"results": [
{
"id": 160882,
"title": "Pulp Fiction",
"year": 1994,
"directors": ["Quentin Taratino"]
},
{
"id": 991349,
"title": "8 Bit Cinema: Pulp Fiction",
"year": 2014,
"directors": ["David Dutton"]
}
]
}
}
```

**EXAMPLE 2:** another example of an advanced search searching for a text in the title of the film and between two years.

**URL**
```
[POST] http://<server_domain_api>/searches/advanced
Expand All @@ -154,6 +208,15 @@ docker exec -it filmaffinityapi-web-server php .bin/console <COMMAND>
```json
{
"text": "pulp fiction",
"search_in_title": true,
"search_in_director": false,
"search_in_cast": false,
"search_in_screenplay": false,
"search_in_photography": false,
"search_in_soundtrack": false,
"search_in_producer": false,
"country": "",
"genre": "",
"year_from": 1992,
"year_to": 2000
}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"require": {
"php": "^8.3",
"slim/slim": "4.*",
"slim/psr7": "^1.6",
"vlucas/phpdotenv": "^5.5",
Expand Down
9 changes: 9 additions & 0 deletions config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ URL_PATH="/app"
#
ERROR_DETAIL=true

# LOG_SQL - Log SQL queries.
#
# Accepted values:
#
# true (log SQL queries)
# false (don't log SQL queries)
#
LOG_SQL=true

# LANGUAGE - FilmAffinity's API language.
#
# Available languages:
Expand Down
38 changes: 32 additions & 6 deletions config/container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Logging\Middleware;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMSetup;
Expand All @@ -14,6 +15,8 @@
use Xsga\FilmAffinityApi\Modules\Errors\Domain\Repositories\ErrorsRepository;
use Xsga\FilmAffinityApi\Modules\Errors\Infrastructure\Mappers\JsonErrorToError;
use Xsga\FilmAffinityApi\Modules\Errors\Infrastructure\Repositories\JsonErrorsRepository;
use Xsga\FilmAffinityApi\Modules\Films\Application\Mappers\CountryToCountryDto;
use Xsga\FilmAffinityApi\Modules\Films\Application\Mappers\GenreToGenreDto;
use Xsga\FilmAffinityApi\Modules\Films\Application\Services\BackupCountriesService;
use Xsga\FilmAffinityApi\Modules\Films\Application\Services\BackupGenresService;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Parsers\AdvancedSearchFormParser;
Expand All @@ -23,7 +26,10 @@
use Xsga\FilmAffinityApi\Modules\Films\Domain\Repositories\FilmsRepository;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Repositories\GenresRepository;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Repositories\SearchRepository;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Services\GetAdvancedSearchResultsService;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Services\GetCountriesService;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Services\GetFilmService;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Services\GetGenresService;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Services\GetSimpleSearchResultsService;
use Xsga\FilmAffinityApi\Modules\Films\Domain\Services\UrlService;
use Xsga\FilmAffinityApi\Modules\Films\Infrastructure\Repositories\FilmAffinityAdvancedSearchRepository;
Expand Down Expand Up @@ -69,6 +75,7 @@
// ENVIRONMENT.
'getLanguage' => $_ENV['LANGUAGE'],
'getErrorDetail' => filter_var($_ENV['ERROR_DETAIL'], FILTER_VALIDATE_BOOLEAN),
'getLogSQL' => filter_var($_ENV['LOG_SQL'], FILTER_VALIDATE_BOOLEAN),
'getUrlPath' => $_ENV['URL_PATH'],
'getJwtSecretKey' => $_ENV['JWT_SECRET_KEY'],
'getJwtLifetime' => (int)$_ENV['JWT_LIFETIME'],
Expand Down Expand Up @@ -109,11 +116,16 @@
$isDevMode = true;
$entityPaths = $container->get('entity.folders');
$proxyPath = $container->get('entities.proxy.folder');
$connection = DriverManager::getConnection($container->get('database.info'));


$config = ORMSetup::createAttributeMetadataConfiguration($entityPaths, $isDevMode, $proxyPath, null);
$config->setAutoGenerateProxyClasses($isDevMode);

if ($container->get('getLogSQL')) {
$config->setMiddlewares([$container->get(Middleware::class)]);
}

$connection = DriverManager::getConnection($container->get('database.info'), $config);

return new EntityManager($connection, $config);
},

Expand All @@ -126,8 +138,17 @@
}
return Logger::getRootLogger();
},
'logger-cli' => function (ContainerInterface $container) {
if (!Logger::isInitialized()) {
Logger::configure($container->get('logger.config.folder') . 'log4php-cli.xml');
}
return Logger::getRootLogger();
},
LoggerInterface::class => function (ContainerInterface $container): LoggerInterface {
$logger = $container->get(Logger::class);
$logger = match (php_sapi_name()) {
'cli' => $container->get('logger-cli'),
default => $container->get(Logger::class)
};
return new LoggerWrapper($logger);
},

Expand All @@ -149,6 +170,7 @@
// USERS MODULE.
// --------------------------------------------------------------------------------------------

// Application mappers.
UserToUserDto::class => DI\create(UserToUserDto::class)->constructor(
DI\get('getDateTimeMask')
),
Expand All @@ -167,13 +189,17 @@

// Application services.
BackupGenresService::class => DI\create(BackupGenresService::class)->constructor(
DI\get(LoggerInterface::class),
DI\get(FilmAffinityGenresRepository::class),
DI\get(GenreToGenreDto::class),
DI\get('getLanguage'),
DI\get('backup.folder')
),

BackupCountriesService::class => DI\create(BackupCountriesService::class)->constructor(
DI\get(LoggerInterface::class),
DI\get(FilmAffinityCountriesRepository::class),
DI\get(CountryToCountryDto::class),
DI\get('getLanguage'),
DI\get('backup.folder')
),
Expand All @@ -197,18 +223,18 @@
DI\get(LoggerInterface::class),
DI\get(UrlService::class),
DI\get(HttpClientService::class),
DI\get(AdvancedSearchFormParser::class)
DI\get(GetGenresService::class)
),
CountriesRepository::class => DI\create(FilmAffinityCountriesRepository::class)->constructor(
DI\get(LoggerInterface::class),
DI\get(UrlService::class),
DI\get(HttpClientService::class),
DI\get(AdvancedSearchFormParser::class)
DI\get(GetCountriesService::class)
),
AdvancedSearchRepository::class => DI\create(FilmAffinityAdvancedSearchRepository::class)->constructor(
DI\get(UrlService::class),
DI\get(HttpClientService::class),
DI\get(AdvancedSearchParser::class)
DI\get(GetAdvancedSearchResultsService::class)
),
SearchRepository::class => DI\create(FilmAffinitySearchRepository::class)->constructor(
DI\get(UrlService::class),
Expand Down
1 change: 1 addition & 0 deletions config/env/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function loadEnvironmentSettings(): void

$settings->required('URL_PATH');
$settings->required('ERROR_DETAIL')->isBoolean();
$settings->required('LOG_SQL')->isBoolean();
$settings->required('LANGUAGE')->allowedValues(['spa', 'en']);
$settings->required('BASE_URL');
$settings->required('SEARCH_URL');
Expand Down
24 changes: 20 additions & 4 deletions config/errors/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@
"code": 2002,
"http": 500,
"description": {
"en": "Genre code not valid",
"spa": "El codigo de género no es válido"
"en": "Genre with code '{1}' not valid",
"spa": "El codigo de género '{1}' no es válido"
}
},
{
"code": 2003,
"http": 500,
"description": {
"en": "Country code not valid",
"spa": "El codigo de país no es válido"
"en": "Country with code '{1}' not valid",
"spa": "El codigo de país '{1}' no es válido"
}
},
{
"code": 2004,
"http": 404,
"description": {
"en": "Page not found",
"spa": "Página no encontrada"
}
},
{
"code": 2005,
"http": 404,
"description": {
"en": "Film with ID '{1}' not found",
"spa": "Film con ID '{1}' no encontrado"
}
},
{
Expand Down
1 change: 1 addition & 0 deletions config/etc/php/xdebug.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[xdebug]
zend_extension=xdebug.so
xdebug.mode=coverage
17 changes: 17 additions & 0 deletions config/logger/log4php-cli.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration xmlns="http://logging.apache.org/log4php/">

<appender name="default" class="LoggerAppenderDailyFile">
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{Y-m-d H:i:s} [%5pid] [%-5level] [%-30class{0}] [%4line] - %msg%n" />
</layout>
<param name="file" value="../Log/log_cli-%s.log" />
<param name="datePattern" value="Ymd" />
</appender>

<root>
<level value="debug" />
<appender_ref ref="default" />
</root>

</configuration>
16 changes: 8 additions & 8 deletions config/schemas/input/advanced.search.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@
"type": "string",
"title": "Text to search"
},
"title": {
"search_in_title": {
"type": "boolean",
"title": "Title flag"
},
"director": {
"search_in_director": {
"type": "boolean",
"title": "Director flag"
},
"cast": {
"search_in_cast": {
"type": "boolean",
"title": "Cast flag"
},
"screenplay": {
"search_in_screenplay": {
"type": "boolean",
"title": "Screenplay flag"
},
"photography": {
"search_in_photography": {
"type": "boolean",
"title": "Photography flag"
},
"soundtrack": {
"search_in_soundtrack": {
"type": "boolean",
"title": "Soundtrack flag"
},
"producer": {
"search_in_producer": {
"type": "boolean",
"title": "Producer flag"
},
Expand All @@ -52,5 +52,5 @@
"title": "Film release year to"
}
},
"required": [ "text" ]
"required": [ "text", "search_in_title", "search_in_director", "search_in_cast", "search_in_screenplay", "search_in_photography", "search_in_soundtrack", "search_in_producer", "country", "genre", "year_from", "year_to"]
}
Loading

0 comments on commit 7c006b3

Please sign in to comment.