Stockturn API is a REST JSON API for the Stockturn application which provides products CRUD, bulk upsert via CSV and stock timeline.
Frontend in https://github.com/guizoxxv/stockturn-app
- PHP v8.0.2
- Laravel v8.29.0
- PostgreSQL v13.2
- Docker v20.10.5
- docker-compose v1.27.4
- Composer v2.0.11
- RAML v1.0
- The application uses Laravel Sanctum SPA authentication which requires that the frontend and backend must use the same domain. To run local you may edit your
/etc/hosts
.
127.0.0.1 local.test
127.0.0.1 api.local.test
The backend (this application) is hosted at http://api.local.test:8001
and the frontend at http://local.test:3000
.
If you change the hosts names be sure to update the variables
SESSION_DOMAIN
,SANCTUM_STATEFUL_DOMAINS
andFORTIFY_DOMAIN
in the.env
file.
-
Clone or download this repository to your machine
-
Create two databases in
PostgreSQL
:stockturn
andstockturn_test
stockturn_test
will be used for testing and must be referenced in the.env.testing
fileDATABASE
section.
- Copy the content of
.env.example
to a new file.env
cp .env.example .env
-
Provide your databases information to the
DATABASE
section in the.env
and.env.testing
-
Follow the steps in the
Common
section bellow -
Start the application
php artisan serve
-
Clone or download this repository to your machine
-
Create the containers
docker-compose up -d
The application will run on host port 8001 and the database on port 3001 by default.
- Access the
app
container
docker-compose exec app bash
- Copy the content of
.env.docker
to a new file.env
cp .env.docker .env
- Follow the steps in the
Common
section bellow
- Install the dependencies
composer install
- Generate the application key (used for cookies)
php artisan key:generate
- Run the migrations (create tables)
php artisan migrate
- Generate random data (Optional)
php artisan db:seed
- Generate admin user
php artisan app:create-admin
This command will ask the
name
,password
of the user. You can use the-D
flag to generate a default username:Admin
,email:admin@example.com
,password:secret
.
- Generate random data (Optional)
php artisan db:seed
- Set permissions to write in the storage folder
sudo chmod -R 777 storage
Avoid using 777 permission in production.
- Configure queue listener to process messages
php artisan queue:listen
In production use supervisor to keep the process running in the background and restart on fails.
Navigate to /api/doc
. This documentation was build with RAML. You can import the postman collection and environment variables from etc/postman
with the requests.
The Postman resources include a pre-request script to set the cookie.
Execute the following command in this project root directory to run the tests:
php artisan test