Giter Club home page Giter Club logo

elibrary's Introduction

Library Management System API using Django and django-rest-framework

#Initial Setup:

Create virtual environment=> python -m venv env

Install django => pip install django

Start a new django Project=> django-admin startproject elibrary

Set Up a postgres Database => pip install psycopg2-binary

Change settings.py files to include postgres database :

DATABASES = {

'default': {
	
    'ENGINE': 'django.db.backends.postgresql',
			
    'NAME': 'yourdbname',
			
    'USER': 'yourdbuser',
			
    'PASSWORD': 'yourpassword',
			
    'HOST': 'localhost',
			
    'PORT': '',
			
}

}

Start a new app named api=> python manage.py startapp api

Install django-rest-framework-> pip install django-rest-framework

Add to installed apps

INSTALLED_APPS = [

...

'yourappname',

'rest_framework'

]

The initial setup is now complete

#API Documentation

  1. Create User

EndPoint => POST /create_user

Request Body Example =>

{

"name": "John Doe",

"email": "[email protected]",

"membershipDate": "2022-01-01"

} Responses =>

201 Created , {"message" : "User Created Succesfully" }

400 Bad Request , {"message" : "Please Provide all the required fields" }

500 Internal Server Error , {"message": "Something went wrong"}

  1. Get All Users

EndPoint => GET /all_users

Responses =>

200 OK ,

{

"users": [

{

  "id": 1,

  "name": "John Doe",

  "email": "[email protected]",

  "membershipDate": "2022-01-01"

},

{

  "id": 2,

  "name": "Jane Smith",

  "email": "[email protected]",

  "membershipDate": "2022-02-01"

}

] }

404 Not Found =>

{"message" : "No users found"}

  1. Get User by ID

Endpoint POST /get_user

Request Body

{ "userid": 1 } Responses

200 OK =>

{

"user": {

"id": 1,

"name": "John Doe",

"email": "[email protected]",

"membershipDate": "2022-01-01"

}

}

404 Not Found =>

{

"message": "No user found"

}

400 Bad Request =>

{

"message": "Please provide the userid"

}

Book APIs

  1. Add a New Book

Endpoint => POST /add_book

Request Body

{

"title": "Sample Book",

"userid": 1,

"isbn": "1234567890",

"publishedDate": "2022-03-01",

"genre": "Fiction"

} Responses

201 Created =>

{

"message": "Book added successfully"

}

400 Bad Request =>

{

"message": "Please provide all the required fields"

} 500 Internal Server Error =>

{

"message": "Something went wrong"

} 5. Get All Books

Endpoint => GET /all_books

Responses

200 OK =>

{

"books": [

{

  "id": 1,

  "title": "Sample Book",

  "borrower": {

    "id": 1,

    "name": "John Doe",

    "email": "[email protected]",

    "membershipDate": "2022-01-01"

  },

  "isbn": "1234567890",

  "publishedDate": "2022-03-01",

  "genre": "Fiction"

}

]

}

404 Not Found =>

{

"message": "No books found"

}

  1. Get Book by ID

Endpoint => POST /get_book

Request Body

{

"bookID": 1

}

Responses

200 OK =>

{

"book": {

"id": 1,

"title": "Sample Book",

"borrower": {

  "id": 1,

  "name": "John Doe",

  "email": "[email protected]",

  "membershipDate": "2022-01-01"

},

"isbn": "1234567890",

"publishedDate": "2022-03-01",

"genre": "Fiction"

}

}

404 Not Found =>

{

"message": "No book found"

}

400 Bad Request =>

{

"message": "Please provide the bookid"

}

  1. Update Book Details

Endpoint => POST /update_book

Request Body

{

"id": 1,

"numberOfPages": 200,

"publisher": "Sample Publisher",

"language": "English"

}

Responses

200 OK =>

{

"message": "Book details updated successfully"

}

400 Bad Request =>

{

"message": "Please provide the bookid"

}

500 Internal Server Error =>

{

"message": "Something went wrong"

}

Borrowed Books APIs

  1. Borrow a Book

Endpoint => POST /borrow_book

Request Body=>

{

"userid": 1,

"bookid": 1,

"borrowedDate": "2023-01-01",

"returnDate": "2023-02-01"

}

Responses

201 Created =>

{

"message": "Book borrowed successfully"

}

400 Bad Request =>

{

"message": "Please provide all the required fields"

}

404 Not Found =>

{

"message": "No user or book found"

}

500 Internal Server Error =>

{

"message": "Something went wrong"

}

  1. List Borrowed Books

Endpoint => GET /borrowed_books

Responses

200 OK =>

{

"borrowedBooks": [

{

  "id": 1,

  "book": {

    "title": "Sample Book",

    "borrower": {

      "id": 1,

      "name": "John Doe",

      "email": "[email protected]",

      "membershipDate": "2022-01-01"

    },

    "isbn": "1234567890",

    "publishedDate": "2022-03-01",

    "genre": "Fiction"

  },

  "borrower": {

    "id": 1,

    "name": "John Doe",

    "email": "[email protected]",

    "membershipDate": "2022-01-01"

  }

}

]

}

elibrary's People

Contributors

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