Skip to content

skushagra/zolo-backend

Repository files navigation

Zolo Book Sharing Backend

This repository contains the backend for an application that allows users to share books among themselves, users can add books, borrow a book, return a book and see all available books.

Enviornment Variables

  • DB_USER - To store username of the mysql user (default = "kali")
  • DB_PASS - To store password of the mysql user (default = "kali")
  • DB_HOST - To store hostname of the mysql database (default = "127.0.0.1")
  • DB_PORT - To store port of the mysql database (default = "3306")
  • DB_NAME - To store the database name (default = "zolo")

The database by default does not have any lenders so remember to add a few lenders before proceeding.

API Setup

  1. Install and setup go on your system.

  2. Create a MySQL database in your machine and store database details in the enviornment

  3. The Database has the following design. image

  4. Clone the git repository

git clone https://github.com/skushagra/zolo-backend.git
  1. Get the requirements
go get .

Run

  1. Run the server
go run .

The server will start running on port 9090 by default.

API Documentation

1. GET /

Greets user and verifies that the server is running.

2. GET /api/v1/booky

Returns a list of all the books in the database which are available for sharing.

3. PUT /api/v1/booky

Adds a new book to the database.

Request Payload 
{
	book_name         string
	book_author       string
	available_till    string
	genre             string
	hosted_by         int
	available	  int (set to 1)
}

4. PUT /api/v1/booky/<book_id>/borrow

Borrows a book from the database with the given book id.

Request Payload 
{
    borrower_id  int
    start_time   datetime-string 
    end_time     datetime-string
}

5. POST /api/v1/booky/<book_id>/borrow/<borrow_id>

Returns the details of the borrow request with the given borrow id.

A postman collection with sample API calls has been uploaded on the repo.

About

Bankend for Zolo problem sheet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages