Skip to content

diogo-alves/library-manager

Repository files navigation

Library Manager REST API

License

Description

A REST API to manage books and authors data. It was based on this challenge by Olist company.

Live preview

This project was deployed on Heroku and is available here.

Prerequisites

Before you start, install Git and Poetry. Optionally, if you want to dockerize this application, install Docker and Docker Compose.

Getting Started

  1. Clone this repository
git clone git@github.com:diogo-alves/library-manager.git
  1. Go to project directory
cd library-manager

Executing the project

Running locally:

  1. Install the requirements
poetry install
  1. Activate virtualenv
poetry shell
  1. Update the database structure
python manage.py migrate
  1. Start the web server
python manage.py runserver

Running with docker:

  1. Start web server and database services
docker-compose up -d
  1. Update the database structure
docker-compose exec web python manage.py migrate

With the web server running access the API at http://localhost:8000/api/

Testing

Running locally:

pytest

Running with docker:

docker-compose exec web pytest

API endpoints

This project implements the OpenAPI Specification (formerly Swagger Specification). The full documentation can be accessed at http://localhost:8000/api/.

Authors

Action HTTP VERB Endpoint
List authors GET api/authors/
Search author by name GET api/authors/?search={name}
Paginate authors list GET api/authors/?page={number}

Books

Action HTTP VERB Endpoint
List books GET api/books/
Filter books by name GET api/books/?name__icontains={name}
Filter books by publication year GET api/books/?publication_year={year}
Filter books by editon GET api/books/?edition={edition}
Filter books by author name GET api/books/?authors__name__icontains={name}
Create a book POST api/books/
Retrieve book GET api/books/{id}/
Update/Replace book PUT api/books/{id}/
Update/Modify book PATCH api/books/{id}/
Delete book DELETE api/books/{id}/

Importing authors

A django management command was created to import a CSV file with authors names. The file must follow the format:

name
Luciano Ramalho
Osvaldo Santana Neto
David Beazley
Chetan Giridhar
Brian K. Jones
J.K Rowling

To import run:

python manage.py import_authors authors.csv
# or
docker-compose exec web python manage.py import_authors authors.csv

Built With

Environment

License

This project is licensed under the terms of the MIT License.