Git Product home page Git Product logo

little-lemon-back-end's Introduction

Little Lemon Booking Website

Back-End Project Description

This website showcased the back-end of implementing a booking application on the Little Lemon Website. This is a Django application for managing a restaurant's menu and bookings, which includes basic functionalities such as creating and viewing menu items, as well as handling reservations.

Django: Web framework for backend development.
Django REST Framework: API development framework built on top of Django.
Pipenv: Virtual environment management tool.
Djoser: Django REST Framework extension for user authentication.

Installation

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

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'",
        },
    },
}

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=your_username
PASSWORD=your_password

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>'}

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

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.036s

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

little-lemon-back-end's People

Contributors

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