felippegh / stonks-api

Laravel API to retrieve stock prices from stooq.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stonks image

Stonks Challenge - Laravel version

Features

Mandatory

  • ✔️ An endpoint to retrieve the history of queries made to the API service by that user;
  • ✔️ An endpoint to create a new User, storing the email and information to log in later;
  • ✔️ An endpoint to request a stock quote;

Extra

  • ✔️ Add unit tests for the endpoints;
  • ❕ Use RabbitMQ to send the email asynchronously - Instead of RabbitMQ - I've added the database queue from laravel, which allows the emails to be sent asynchronously and a docker container that runs the queue:worker;
  • ❕ Use JWT instead of basic authentication for endpoints; - Instead of JWT, I've used the official Laravel solution called Sanctum.
  • ✔️ Containerize the app.

Extra-extra

  • ✔️ Add 30 seconds cache to api.user.history and api.stock.price endpoints;

Requirements

  • Docker-compose: >= 1.25.0
  • Docker: >= 20.10.12

Setup instructions

Execute the following steps:

  • Clone the project
  • Create .env from .env.example
  • You may add Mailtrap(or other email service) to your .env using the following variables:
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=[Your Mailtrap Username]
MAIL_PASSWORD=[Your Mailtrap Password]
MAIL_ENCRYPTION=tls
  • Run docker-compose up
  • Wait the stonks-api-php-build process finishes

Testing

  • Run docker exec -it stonks-api-php bash
  • Run php artisan test

Using the APP

Once up and running you can make API calls using the following URL: http://localhost:8019/api:

When the application starts, the admin user is inserted in the database by the seeder:

  • Email: admin@admin.com
  • Password: secret

These credentials must be used in the login endpoint to authenticate into the system.

After that, you can proceed using all available endpoints.

The available endpoints can be found here.

About

Laravel API to retrieve stock prices from stooq.

License:MIT License


Languages

Language:PHP 80.9%Language:Blade 15.3%Language:Shell 2.1%Language:Dockerfile 1.1%Language:JavaScript 0.5%