Skip to content

projectwonki/checkproof-restapi

Repository files navigation

About Project

This is the simple REST API project using Laravel Framework which allow user to create new user and get the list of users through API. The authentication using Laravel sanctum

Main Features

Create User

  • Insert new record
  • send emails:
    • to the new user confirming their account creation
    • to the system administrator notifying them of the new user
    • return a response of newly created user (excludin password)

Get Users

  • Retrieve a paginated list of active users (Exclude the password field in the response)
  • Filter results using the search parameter (matches name or email)
  • Sort results based on sortBy. Default sorting: created_at.
  • show the total number of orders for each user using orders_count attribute
  • show to authorization of currently logged-in user on edit the user using can_edit attribute

Additional Features

User Login

  • authenticate user using Login API
  • provide token for authenticated user to access the API

User Logout

  • delete user token to make user become not authenticated
  • invalidate tokens to prevents unauthorized user to use the token

Update User

  • implement validation to check if the auth user has privilege to edit the user or not
  • this API to show how the privilege of role works

Roles

Administrator

  • privilege: can edit any user

Manager

  • privilege: can only edit users with the role user

User:

  • privilege: can only edit themselves

Setup Instructions

Follow these steps to run the project locally:

  1. Clone the repository
git clone https://github.com/projectwonki/checkproof-restapi
cd checkproof-restapi
  1. Download Dependencies
composer install
  1. Configure the environment

Create a .env file based on the example:

cp .env.example .env

Update your .env file with your database and mail settings:

APP_URL=http://localhost:8000
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password
  1. Generate application key
php artisan key:generate
  1. Run migrations
php artisan migrate
php artisan db:seed
  1. Serve the application
php artisan serve

The application should now be available at http://localhost:8000.

API List

  1. Login
Response:
{
   ...
   "access_token": {token}
   ...
}
  1. Get Users
  2. Create User
  3. Update User
  4. Logout
Request Headers (required for 2-5):
{
   Accept: application/json
   Content-Type: application/json
   Authorization: {access_token} // this from login response
   ...
}

Credentials of Initial User for Testing

  1. Administrator
email: admin@test.com
password: root123
  1. Manager
email: manager@test.com
password: root123
  1. User
email: user1@test.com
password: root123

Postman Collection

I already included postman collection for testing purpose

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages