Snacks App API, is a demo of a simple application for buy snacks, using laravel 5.5
- Fractal transformers
- Gates and policies
- Laravel Passport for authentication
- Laravel client views for generating tokens with Vue.js
- Laravel cors implementation
- Laravel pagination
- Use of mailtrap.io for verify email accounts
- HATEOAS
- etc.
Snacks App requires:
- Clone the repository
- Install the dependencies.
$ cd snack
$ composer install
$ npm install
- Compile vue.js resources
$ npm run dev
- Run the db.sql script to create the database with demo records.
- Generate Passport keys
$ php artisan passport:keys
Dillinger is currently extended with the following plugins. Instructions on how to use them in your own application are linked below.
Method | Action | Endpoint | Role |
---|---|---|---|
GET | List all users (Allows pagination, filter, search, etc.) | http://snacks.dev/users | Admin |
POST | Create an user (Requires set up an email service credentials in env file) | http://snacks.dev/users | Admin/User |
GET | Display an specific user | http://snacks.dev/users/1 | Admin / User (Only his own account) |
PUT/PATCH | Update an user account | http://snacks.dev/users/ | Admin / User (Only his own account) |
DELETE | Delete a user account | http://snacks.dev/users/1 | Admin |
Method | Action | Endpoint | Role |
---|---|---|---|
GET | List all products (Allows pagination, filter, search, etc.) | http://snacks.dev/products | Admin/User |
POST | Create a product (It requires to set initial price and stock) | http://snacks.dev/producs | Admin |
GET | Display an specific product | http://snacks.dev/products/1 | Admin / User |
POST | Liking a product | http://snacks.dev/products/1/like | Admin / User |
PUT/PATCH | Update an product (Optional parameters: price and stock) | http://snacks.dev/products/ | Admin |
POST | Update price | http://snacks.dev/products/1/price | Admin |
DELETE | Delete a product | http://snacks.dev/products/1 | Admin |
POST | Update stock | http://snacks.dev/products/1/stock | Admin |
Method | Action | Endpoint | Role |
---|---|---|---|
GET | List all transactions (Allows pagination, filter, seacrh, etc.) | http://snacks.dev/transactions | Admin |
POST | Create a transaction (Buy a product) | http://snacks.dev/transactions | Admin |
GET | Display an specific transaction | http://snacks.dev/transactions/1 | Admin / User (Only if the user is the buyer) |
-
Open the database and query the users table:
1.1 All passwords are "secret"
1.2 Only the first user has admin role
For the demo, We will use the following credentials
Admin user: email:[email protected] password: secret
Regular user: email:[email protected] password: secret
-
Login and generate a token for each user in the "My token" menu View Demo
-
List all users (Allows pagination, filter, search, etc.) View basic demo
1.1 Custom pagination number To use a custom pagination number just include per_page attribute in the url (Default: 5 , Min: 2)
View custom pagination number demo
1.2 Sort_by and Sort_desc In order to sort the results, use the attribute sort_by equal to the name of the field; by default the sort would be by asc. Use sort_desc attribute to do a sort descendent type View sorting the results demo
1.3 Search/Filter In order to search an attribute, just add the name of the field equal to the search (By default the search would be the equal type). In order to do a search using the "Like" query; add the "filter_like" attribute to the url View search/filter demo
1.4 Putting all together Mixing all the options View Putting all together demo
-
Create a user (Requires set up an email service credentials in env file) View create user demo
-
Display an specific user Only admins and the user owner of the account View display user demo
-
Update an user account Only admins and the user owner of the account View update user demo
-
Delete an user Only admins and the user owner of the account View delete user demo
-
List all products Get the list of products (The resource is using cache...) View get products
-
Create a product: It requires to set an initial price and stok View create products demo
-
Display a product View show product demo
-
Liking a product if the same user hit likes and he already did hit the like then that would unlike the product View liking product demo
-
Update a product Updating a product also allows update price and stock(both would have a log table for the past values) View updating product demo
-
Update a price View updating product´s price
-
Update stock View updating a product´s stock
-
Delete a product View deleting a product
- List all transactions View list all transactions demo
- Create a transaction (Buy a snack) View Buy a product demo
- Display an specific transaction View an specific transaction demo
- Write a more realistic inventory database model with other entities like suppliers, products transfer, etc
- Allow users to buy more than one product at the same time
- Generate an invoice to send automatically by email