Skip to content

mariano55555/snacks

Repository files navigation

Snack APP API

Snacks App API, is a demo of a simple application for buy snacks, using laravel 5.5

Features!

  • 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.

Installation

Snacks App requires:

  1. Clone the repository
  2. Install the dependencies.
$ cd snack
$ composer install
$ npm install
  1. Compile vue.js resources
$ npm run dev
  1. Run the db.sql script to create the database with demo records.
  2. Generate Passport keys
$ php artisan passport:keys

ENDPOINTS

Dillinger is currently extended with the following plugins. Instructions on how to use them in your own application are linked below.

Users

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

Products

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

Invoices (Transactions)

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)

Examples

* Generate a token
  1. 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

  2. Login and generate a token for each user in the "My token" menu View Demo

* Users Endpoints
  1. 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

  2. Create a user (Requires set up an email service credentials in env file) View create user demo

  3. Display an specific user Only admins and the user owner of the account View display user demo

  4. Update an user account Only admins and the user owner of the account View update user demo

  5. Delete an user Only admins and the user owner of the account View delete user demo

* Products Endpoints
  1. List all products Get the list of products (The resource is using cache...) View get products

  2. Create a product: It requires to set an initial price and stok View create products demo

  3. Display a product View show product demo

  4. 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

  5. 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

  6. Update a price View updating product´s price

  7. Update stock View updating a product´s stock

  8. Delete a product View deleting a product

* Transactions Endpoints
  1. List all transactions View list all transactions demo
  2. Create a transaction (Buy a snack) View Buy a product demo
  3. Display an specific transaction View an specific transaction demo

Todos

  • 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

About

Laravel Restfull Service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published