GithubHelp home page GithubHelp logo

littlelemon's Introduction

Description

This is the final assignment for the Bakend Developer Capstone Course of the Meta Backend Developer Professional Certificate on Coursera.

Project Structure

The project is composed of two apps, api and restaurant. The api app serves API endpoints of the project, while the restaurant app serves its frontend. The config (the project folder) directory holds the major settings of the project

Installation

install the dependencies

pipenv install

Activate the virtual environment

pipenv shell

Setup

The default database settings are

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'littlelemon',
        'HOST': 'localhost',
        'PORT': '3306',
        'USER': 'admin',
        'PASSWORD': '',
        'OPTIONS': {
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
        },
    },
}

๐Ÿ’ก Change those settings according to your local setup.

Apply the migrations

python manage.py migrate

Environment Variables

For authenticated API requests in the view of the restaurant app, a username and password must be provided. Follow the instructions bellow

Inside the restaurant app folder, create a file called .env and place the code inside it

USERNAME=yout_username
PASSWORD=your_password
๐Ÿ’ก replace "your_username" and "your_password" with a valid username and password respectively ๐Ÿ’ก Be aware that `django-environ` must be installed for this to work. Such dependency should be installed by running `pipenv install`

API Endpoints

The api app has a total of 4 endpoints. Additionally, Djoser and SimpleJWT endpoints are available.

Each endpoint requires a SimpleJWT Token for authorization. Pass the token in the header of the request such as

{'Authorization': 'JWT <token>'}

In Insomnia, add the token as follows

Untitled

Endpoints for api app

http:127.0.0.1:8000/api/menu-items
http:127.0.0.1:8000/api/menu-items/{menu-itemId}
http:127.0.0.1:8000/api/bookings
http:127.0.0.1:8000/api/bookings/{bookingId}

http:127.0.0.1:8000/api/menu-items

Method Action TOKEN AUTH STATUS CODE
GET Retrieves all menu items Yes 200
POST Creates a menu item Yes 201

http:127.0.0.1:8000/api/menu-items/{menu-itemId}

Method Action TOKEN AUTH STATUS CODE
GET Retrieves the menu item details Yes 200
PUT Update the menu item Yes 200
PATCH Partially update the menu item Yes 200
DELETE Delete the menu item Yes 200

http:127.0.0.1:8000/api/bookings

Method Action TOKEN AUTH STATUS CODE
GET Retrieves all bookings Yes 200
POST Creates a booking Yes 201

http:127.0.0.1:8000/api/bookings/{bookingId}

Method Action TOKEN AUTH STATUS CODE
GET Retrieves the booking details Yes 200
PUT Update the booking Yes 200
PATCH Partially update the booking Yes 200
DELETE Delete the booking Yes 200

Endpoints for djoser app

http://127.0.0.1:8000/auth/users/
http://127.0.0.1:8000/auth/users/me/
http://127.0.0.1:8000/auth/users/confirm/
http://127.0.0.1:8000/auth/users/resend_activation/
http://127.0.0.1:8000/auth/users/set_password/
http://127.0.0.1:8000/auth/users/reset_password/
http://127.0.0.1:8000/auth/users/reset_password_confirm/
http://127.0.0.1:8000/auth/users/set_username/
http://127.0.0.1:8000/auth/users/reset_username/
http://127.0.0.1:8000/auth/users/reset_username_confirm/

http://127.0.0.1:8000/auth/users/

Method Action STATUS CODE TOKEN AUTH
GET Retrieves all users 200 No
POST Creates a user 201 No

๐Ÿ’ก Please refer to the Djoser documentation for further usage on these endpoints.

Endpoints for simplejwt app

http:127.0.0.1:8000/api/token/login/
http:127.0.0.1:8000/api/token/refresh/

http://127.0.0.1:8000/api/token/login/

Method Action TOKEN AUTH STATUS CODE
POST Generates access token and refresh token Yes 201

http://127.0.0.1:8000/api/token/refresh/

Method Action TOKEN AUTH STATUS CODE
POST Generates a new access token Yes 201

Testing

There are a total of 12 tests to ensure that each API endpoint and each of its allowed HTTP methods work properly.

Run the tests

python manage.py test

It should output something similar to this

Found 12 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
............
----------------------------------------------------------------------
Ran 12 tests in 6.024s

OK
Destroying test database for alias 'default'...

๐Ÿ’ก These tests intrinsically test the `restaurant` models by creating entries on its database through the Django ORM.

littlelemon's People

Contributors

victorpreston avatar mahmoudelali avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.