chesslablab / chess-api

REST-like chess API.
https://chesslablab.github.io/chess-api/
MIT License
23 stars 10 forks source link

Implement the POST /api/download_image endpoint #17

Closed programarivm closed 2 years ago

programarivm commented 2 years ago

This endpoint is intended to download a PNG image given a FEN string, and is to be implemented as per the specification below.

Method Endpoint Description
POST /api/download_image Downloads a PNG image.
Parameter Type Description
fen string A FEN string
Response Description
200 (OK) The FEN string is valid.
400 (Bad Request) The FEN string is not valid.

The POST /api/download_image endpoint should be implemented in a new file called src/Controller/DownloadImageController.php.

See:

Keep it up, and happy learning!

valanm22 commented 2 years ago

Shall I work on this?

programarivm commented 2 years ago

@valanm22 welcome to ChesslabLab.

Thank you for joining the community, please make sure to read the Contributing Guidelines.

Keep it up, and happy learning and coding!

valanm22 commented 2 years ago

@programarivm when I perform composer install I get the following message. Am I going in the correct path? Screenshot (20)

programarivm commented 2 years ago

What about doing composer install without executing the Flex recipe?

valanm22 commented 2 years ago

Without the recipe I got this. Screenshot (21)

programarivm commented 2 years ago

It looks okay, this is the project after the install.

chess-api

valanm22 commented 2 years ago

So can I open the project in VS Code? When I do a git status after composer install the config/bundles.php is modified. Should I be concerned?

programarivm commented 2 years ago

At this moment not too sure about the config/bundles.php, it was not modified after doing the following on my laptop.

  1. Clone the repo:
standard@laptop:~/projects$ git clone git@github.com:chesslablab/chess-api.git
Cloning into 'chess-api'...
Enter passphrase for key '/home/standard/.ssh/id_ed25519': 
remote: Enumerating objects: 382, done.
remote: Counting objects: 100% (382/382), done.
remote: Compressing objects: 100% (221/221), done.
remote: Total 382 (delta 159), reused 334 (delta 121), pack-reused 0
Receiving objects: 100% (382/382), 99.60 KiB | 935.00 KiB/s, done.
Resolving deltas: 100% (159/159), done.
  1. Install composer dependencies:
standard@laptop:~/projects$ cd chess-api/
standard@laptop:~/projects/chess-api$ composer install
Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Updating dependencies
Lock file operations: 94 installs, 0 updates, 0 removals
  - Locking amphp/amp (v2.6.1)
  - Locking amphp/byte-stream (v1.8.1)
  - Locking amphp/parallel (v1.4.1)
  - Locking amphp/parser (v1.0.0)
  - Locking amphp/process (v1.1.3)
  - Locking amphp/serialization (v1.0.0)
  - Locking amphp/sync (v1.4.2)
  - Locking chesslablab/php-chess (1.1.89)
  - Locking composer/package-versions-deprecated (1.11.99.4)
  - Locking doctrine/inflector (2.0.4)
  - Locking doctrine/instantiator (1.4.0)
  - Locking friendsofphp/proxy-manager-lts (v1.0.5)
  - Locking friendsofsymfony/rest-bundle (3.2.1)
  - Locking graham-campbell/result-type (v1.0.4)
  - Locking imagine/imagine (1.2.4)
  - Locking laminas/laminas-code (4.5.1)
  - Locking myclabs/deep-copy (1.10.2)
  - Locking nikic/php-parser (v4.13.2)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.1.0)
  - Locking phpdocumentor/reflection-common (2.2.0)
  - Locking phpdocumentor/reflection-docblock (5.3.0)
  - Locking phpdocumentor/type-resolver (1.6.0)
  - Locking phpoption/phpoption (1.8.1)
  - Locking phpspec/prophecy (v1.15.0)
  - Locking phpunit/php-code-coverage (9.2.10)
  - Locking phpunit/php-file-iterator (3.0.6)
  - Locking phpunit/php-invoker (3.1.1)
  - Locking phpunit/php-text-template (2.0.4)
  - Locking phpunit/php-timer (5.0.3)
  - Locking phpunit/phpunit (9.5.13)
  - Locking psr/cache (3.0.0)
  - Locking psr/container (2.0.2)
  - Locking psr/event-dispatcher (1.0.0)
  - Locking psr/log (1.1.4)
  - Locking rubix/ml (1.3.1)
  - Locking rubix/tensor (3.0.1)
  - Locking scienide/okbloomer (1.0.0)
  - Locking sebastian/cli-parser (1.0.1)
  - Locking sebastian/code-unit (1.0.8)
  - Locking sebastian/code-unit-reverse-lookup (2.0.3)
  - Locking sebastian/comparator (4.0.6)
  - Locking sebastian/complexity (2.0.2)
  - Locking sebastian/diff (4.0.4)
  - Locking sebastian/environment (5.1.3)
  - Locking sebastian/exporter (4.0.4)
  - Locking sebastian/global-state (5.0.3)
  - Locking sebastian/lines-of-code (1.0.3)
  - Locking sebastian/object-enumerator (4.0.4)
  - Locking sebastian/object-reflector (2.0.4)
  - Locking sebastian/recursion-context (4.0.4)
  - Locking sebastian/resource-operations (3.0.3)
  - Locking sebastian/type (2.3.4)
  - Locking sebastian/version (3.0.2)
  - Locking splitbrain/php-cli (1.1.8)
  - Locking symfony/cache (v6.0.3)
  - Locking symfony/cache-contracts (v3.0.0)
  - Locking symfony/config (v6.0.3)
  - Locking symfony/console (v6.0.3)
  - Locking symfony/dependency-injection (v6.0.3)
  - Locking symfony/deprecation-contracts (v3.0.0)
  - Locking symfony/dotenv (v6.0.3)
  - Locking symfony/error-handler (v6.0.3)
  - Locking symfony/event-dispatcher (v6.0.3)
  - Locking symfony/event-dispatcher-contracts (v3.0.0)
  - Locking symfony/filesystem (v6.0.3)
  - Locking symfony/finder (v6.0.3)
  - Locking symfony/flex (v2.1.4)
  - Locking symfony/framework-bundle (v6.0.3)
  - Locking symfony/http-foundation (v6.0.3)
  - Locking symfony/http-kernel (v6.0.3)
  - Locking symfony/maker-bundle (v1.36.4)
  - Locking symfony/password-hasher (v6.0.3)
  - Locking symfony/polyfill-intl-grapheme (v1.24.0)
  - Locking symfony/polyfill-intl-normalizer (v1.24.0)
  - Locking symfony/polyfill-mbstring (v1.24.0)
  - Locking symfony/polyfill-php81 (v1.24.0)
  - Locking symfony/proxy-manager-bridge (v6.0.3)
  - Locking symfony/routing (v6.0.3)
  - Locking symfony/runtime (v6.0.3)
  - Locking symfony/security-core (v6.0.3)
  - Locking symfony/service-contracts (v3.0.0)
  - Locking symfony/string (v6.0.3)
  - Locking symfony/var-dumper (v6.0.3)
  - Locking symfony/var-exporter (v6.0.3)
  - Locking symfony/yaml (v6.0.3)
  - Locking theseer/tokenizer (1.2.1)
  - Locking vlucas/phpdotenv (v5.4.1)
  - Locking voku/portable-ascii (1.5.6)
  - Locking voku/portable-utf8 (5.4.51)
  - Locking wamania/php-stemmer (v2.2.0)
  - Locking webmozart/assert (1.10.0)
  - Locking willdurand/jsonp-callback-validator (v1.1.0)
  - Locking willdurand/negotiation (3.0.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 94 installs, 0 updates, 0 removals
  - Downloading composer/package-versions-deprecated (1.11.99.4)
  - Downloading symfony/flex (v2.1.4)
  - Downloading symfony/runtime (v6.0.3)
  - Downloading willdurand/negotiation (3.0.0)
  - Downloading willdurand/jsonp-callback-validator (v1.1.0)
  - Downloading psr/container (2.0.2)
  - Downloading symfony/service-contracts (v3.0.0)
  - Downloading symfony/password-hasher (v6.0.3)
  - Downloading psr/event-dispatcher (1.0.0)
  - Downloading symfony/event-dispatcher-contracts (v3.0.0)
  - Downloading symfony/security-core (v6.0.3)
  - Downloading symfony/routing (v6.0.3)
  - Downloading symfony/http-foundation (v6.0.3)
  - Downloading symfony/event-dispatcher (v6.0.3)
  - Downloading symfony/var-dumper (v6.0.3)
  - Downloading symfony/error-handler (v6.0.3)
  - Downloading symfony/http-kernel (v6.0.3)
  - Downloading symfony/polyfill-php81 (v1.24.0)
  - Downloading symfony/finder (v6.0.3)
  - Downloading symfony/filesystem (v6.0.3)
  - Downloading symfony/dependency-injection (v6.0.3)
  - Downloading symfony/config (v6.0.3)
  - Downloading symfony/var-exporter (v6.0.3)
  - Downloading psr/cache (3.0.0)
  - Downloading symfony/cache-contracts (v3.0.0)
  - Downloading symfony/cache (v6.0.3)
  - Downloading symfony/framework-bundle (v6.0.3)
  - Downloading friendsofsymfony/rest-bundle (3.2.1)
  - Downloading laminas/laminas-code (4.5.1)
  - Downloading symfony/dotenv (v6.0.3)
  - Downloading symfony/string (v6.0.3)
  - Downloading symfony/console (v6.0.3)
  - Downloading doctrine/inflector (2.0.4)
  - Downloading symfony/maker-bundle (v1.36.4)
  - Downloading friendsofphp/proxy-manager-lts (v1.0.5)
  - Downloading symfony/proxy-manager-bridge (v6.0.3)
  - Downloading symfony/yaml (v6.0.3)
  - Installing composer/package-versions-deprecated (1.11.99.4): Extracting archive
  - Installing symfony/flex (v2.1.4): Extracting archive
  - Installing symfony/runtime (v6.0.3): Extracting archive
  - Installing amphp/parser (v1.0.0): Extracting archive
  - Installing amphp/amp (v2.6.1): Extracting archive
  - Installing amphp/byte-stream (v1.8.1): Extracting archive
  - Installing amphp/process (v1.1.3): Extracting archive
  - Installing amphp/serialization (v1.0.0): Extracting archive
  - Installing amphp/sync (v1.4.2): Extracting archive
  - Installing splitbrain/php-cli (1.1.8): Extracting archive
  - Installing voku/portable-ascii (1.5.6): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.24.0): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.24.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.24.0): Extracting archive
  - Installing voku/portable-utf8 (5.4.51): Extracting archive
  - Installing wamania/php-stemmer (v2.2.0): Extracting archive
  - Installing scienide/okbloomer (1.0.0): Extracting archive
  - Installing rubix/tensor (3.0.1): Extracting archive
  - Installing psr/log (1.1.4): Extracting archive
  - Installing amphp/parallel (v1.4.1): Extracting archive
  - Installing rubix/ml (1.3.1): Extracting archive
  - Installing imagine/imagine (1.2.4): Extracting archive
  - Installing chesslablab/php-chess (1.1.89): Extracting archive
  - Installing willdurand/negotiation (3.0.0): Extracting archive
  - Installing willdurand/jsonp-callback-validator (v1.1.0): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing symfony/service-contracts (v3.0.0): Extracting archive
  - Installing symfony/password-hasher (v6.0.3): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
  - Installing symfony/security-core (v6.0.3): Extracting archive
  - Installing symfony/routing (v6.0.3): Extracting archive
  - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
  - Installing symfony/http-foundation (v6.0.3): Extracting archive
  - Installing symfony/event-dispatcher (v6.0.3): Extracting archive
  - Installing symfony/var-dumper (v6.0.3): Extracting archive
  - Installing symfony/error-handler (v6.0.3): Extracting archive
  - Installing symfony/http-kernel (v6.0.3): Extracting archive
  - Installing symfony/polyfill-php81 (v1.24.0): Extracting archive
  - Installing symfony/finder (v6.0.3): Extracting archive
  - Installing symfony/filesystem (v6.0.3): Extracting archive
  - Installing symfony/dependency-injection (v6.0.3): Extracting archive
  - Installing symfony/config (v6.0.3): Extracting archive
  - Installing symfony/var-exporter (v6.0.3): Extracting archive
  - Installing psr/cache (3.0.0): Extracting archive
  - Installing symfony/cache-contracts (v3.0.0): Extracting archive
  - Installing symfony/cache (v6.0.3): Extracting archive
  - Installing symfony/framework-bundle (v6.0.3): Extracting archive
  - Installing friendsofsymfony/rest-bundle (3.2.1): Extracting archive
  - Installing laminas/laminas-code (4.5.1): Extracting archive
  - Installing webmozart/assert (1.10.0): Extracting archive
  - Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
  - Installing phpdocumentor/type-resolver (1.6.0): Extracting archive
  - Installing phpdocumentor/reflection-docblock (5.3.0): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (2.3.4): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.4): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.3): Extracting archive
  - Installing sebastian/exporter (4.0.4): Extracting archive
  - Installing sebastian/environment (5.1.3): Extracting archive
  - Installing sebastian/diff (4.0.4): Extracting archive
  - Installing sebastian/comparator (4.0.6): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing phpunit/php-invoker (3.1.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.6): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing nikic/php-parser (v4.13.2): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/complexity (2.0.2): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.10): Extracting archive
  - Installing doctrine/instantiator (1.4.0): Extracting archive
  - Installing phpspec/prophecy (v1.15.0): Extracting archive
  - Installing phar-io/version (3.1.0): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.10.2): Extracting archive
  - Installing phpunit/phpunit (9.5.13): Extracting archive
  - Installing symfony/dotenv (v6.0.3): Extracting archive
  - Installing symfony/string (v6.0.3): Extracting archive
  - Installing symfony/console (v6.0.3): Extracting archive
  - Installing doctrine/inflector (2.0.4): Extracting archive
  - Installing symfony/maker-bundle (v1.36.4): Extracting archive
  - Installing friendsofphp/proxy-manager-lts (v1.0.5): Extracting archive
  - Installing symfony/proxy-manager-bridge (v6.0.3): Extracting archive
  - Installing symfony/yaml (v6.0.3): Extracting archive
  - Installing phpoption/phpoption (1.8.1): Extracting archive
  - Installing graham-campbell/result-type (v1.0.4): Extracting archive
  - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
Generating optimized autoload files
Class ChessApi\Tests\Integration\DatabaseTest located in ./tests/integration/DatabaseTest.php does not comply with psr-4 autoloading standard. Skipping.
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
73 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Symfony operations: 7 recipes (6e9d1a77a2ff81e82f54350a259e27e4)
  - Configuring symfony/flex (>=1.0): From github.com/symfony/recipes:master
  - Configuring symfony/framework-bundle (>=5.4): From github.com/symfony/recipes:master
  - Configuring symfony/routing (>=6.0): From github.com/symfony/recipes:master
  -  WARNING  friendsofsymfony/rest-bundle (>=2.2): From github.com/symfony/recipes-contrib:master
    The recipe for this package comes from the "contrib" repository, which is open to community contributions.
    Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/friendsofsymfony/rest-bundle/2.2

    Do you want to execute this recipe?
    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n):  
  - Configuring phpunit/phpunit (>=9.3): From github.com/symfony/recipes:master
  - Configuring symfony/console (>=5.3): From github.com/symfony/recipes:master
  - Configuring symfony/maker-bundle (>=1.0): From github.com/symfony/recipes:master
Executing script cache:clear [OK]
Executing script assets:install public [OK]

 What's next? 

Some files have been created and/or updated to configure your new packages.
Please review, edit and commit them: these files are yours.

 symfony/framework-bundle  instructions:

  * Run your application:
    1. Go to the project directory
    2. Create your code repository with the git init command
    3. Download the Symfony CLI at https://symfony.com/download to install a development web server

  * Read the documentation at https://symfony.com/doc
programarivm commented 2 years ago

This is the config/bundles.php file:

<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
];
valanm22 commented 2 years ago

Mine looks the same as yours so, no problem right? And how do I test the methods?

programarivm commented 2 years ago

That's a good question! Let me open a new issue to write some documentation on how to test the REST API methods.

Probably it is a good idea to set up Nginx on your computer in a similar way as in docker/nginx/conf.d/default.conf. Alternatively, if you're using Docker the chess_api_php_fpm and chess_api_nginx containers defined in docker-compose.yml should be started as described next:

$ docker network create chess-data_default
a5a52900974fe8904e19082f44c6f2cc82ae1487427ceefd47779eb0339e8214
standard@laptop:~/projects/chess-api$ docker-compose up --build
Building php_fpm
Sending build context to Docker daemon  93.66MB
Step 1/4 : FROM php:8.0-fpm
8.0-fpm: Pulling from library/php
5eb5b503b376: Pull complete 
8b1ad84cf101: Pull complete 
38c937dadeb7: Pull complete 
6a2f1dc96e59: Pull complete 
cfba4e10e5d6: Pull complete 
55c4c6f240cc: Pull complete 
0cce7a2c8179: Pull complete 
27fe35a0cb4b: Pull complete 
48c02bd9a8a5: Pull complete 
9a26d1e701c4: Pull complete 
Digest: sha256:c12db38ea1e1f45cf80249bb38fdf0fb1dea96e9bc9f16f5c6d053a78887082c
Status: Downloaded newer image for php:8.0-fpm
 ---> 1f353342ac01
Step 2/4 : RUN apt-get update && apt-get install -y     git     libzip-dev     unzip     zip
...

The chesslablab/chess-data project must be up and running along with the chesslablab/chess-api project but if I'm not very much mistaken, the database may not be required in this particular case to implement the POST /api/download_image endpoint.

Anyway, a certificate needs to be installed — otherwise nginx will exit with code 1.

...
chess_api_nginx exited with code 1
chess_api_nginx | /docker-entrypoint.sh: Configuration complete; ready for start up
chess_api_nginx | 2022/01/28 17:28:55 [emerg] 1#1: cannot load certificate "/etc/nginx/ssl/certificate.crt": PEM_read_bio_X509_AUX() failed (SSL: error:0909006C:PEM routines:get_name:no start line:Expecting: TRUSTED CERTIFICATE)
chess_api_nginx | nginx: [emerg] cannot load certificate "/etc/nginx/ssl/certificate.crt": PEM_read_bio_X509_AUX() failed (SSL: error:0909006C:PEM routines:get_name:no start line:Expecting: TRUSTED CERTIFICATE)
chess_api_nginx exited with code 1

If using Docker please make sure to copy the certificate files into the docker/nginx/ssl folder.

For further information:

Keep it up, happy learning and coding.

programarivm commented 2 years ago

Updated the README which now explains how to test the API.

valanm22 commented 2 years ago

Thanks @programarivm