Skip to content

OlivierFL/FlochOlivier_7_24042021

Repository files navigation

BileMo Rest API

Maintainability Quality Gate Status Maintainability Rating

Project

Project 7 - Rest API built with Symfony Framework.

Requirements

Mandatory :

Optional :

  • Make to use the Makefile and custom commands
  • Docker and Docker-compose for MySQL database and PhpMyAdmin containers

Unit Tests :

  • PHPUnit

Installation

  1. To get this project on your local machine, simply clone this repository :

    git clone [email protected]:OlivierFL/FlochOlivier_7_24042021.git
  2. Install the dependencies :

  • composer install
  1. Environment configuration :

    To configure local dev environment, create a .env.local file at the root of the project.

    To configure database connection, override the DATABASE_URL env variable with your database credentials and database name, for example :

    DATABASE_URL="mysql://root:[email protected]:3306/bilemo?serverVersion=5.7"

    If you're using the MySQL Docker container, the config is :

    DATABASE_URL="mysql://root:[email protected]:3306/bilemo"

    In the .env file, 2 variables are available, to configure the default number of products and users for pagination, and the directory for images uploads (default directory is /public/uploads at the root of the project) :

    LIMIT=10
    UPLOADS_DIRECTORY=/public/uploads
  2. After configuring the database connection, run bin/console doctrine:database:create to create the database, then bin/console doctrine:schema:create to create database tables.

  3. Then run bin/console doctrine:fixtures:load to load the example data into the database. If you're using Docker, PhpMyAdmin is available on localhost:8080 (user : root, password : admin).

  4. Generate the SSL keys needed to handle the JWT authentication : bin/console lexik:jwt:generate-keypair.

  5. Start the Symfony server with symfony server:start.

The base url for the API is : localhost:8000/api.

Usage

List of useful commands to use the project :

  • symfony server:start to start the Symfony server
  • symfony server:stop to stop the Symfony server

Commands to use with Docker and Make (commands are available in Makefile at the root of the project) :

  • make up to start Docker stack (MySQL and PhpMyAdmin) and Symfony server
  • make install to run installation process automatically (manual environment configuration is needed before running this command)
  • make tests to run PHPUnit tests
  • make down to stop Docker stack (MySQL and PhpMyAdmin) and Symfony server

Sample data

In order to have a fully functional API, the fixtures contains :

  • 2 Company that can access the API :

    • a Company with Company username, and Company1234 password.

    • another Company with Company Test username, and 1234Company password.

  • A default list of Products (50 items). Each Product is related to a Brand (10 items).

  • A default list of Users (10 items). Each User is related to one of the two Company.

API Documentation

The documentation for the API is accessible at : localhost:8000/api/doc.

UML diagrams

The UML diagrams are available in /doc/uml directory at the root of the project.

Third party libraries

Packages and bundles used in this project :

Docker (optional)

This project uses Docker for MySQL database and PhpMyAdmin.

The stack is composed of 2 containers :

  • mysql
  • phpMyAdmin

The configuration is available in the docker-compose.yaml.

Tests

PhpUnit is used to run the tests.

In a terminal, at the root of the project, run vendor/bin/phpunit or make tests.

Code quality

Links to code quality tools used for this project:

Codeclimate : https://codeclimate.com/github/OlivierFL/FlochOlivier_7_24042021

SonarCloud : https://sonarcloud.io/dashboard?id=OlivierFL_FlochOlivier_7_24042021