Coder Social home page Coder Social logo

go-bookstore's Introduction

Bookstore Backend Application

This is a simple backend application for managing a bookstore. It provides basic CRUD (Create, Read, Update, Delete) operations on the Book struct using Go and MySQL.

Features

  • Add a new book
  • Retrieve details of a book
  • Update book information
  • Delete a book from the inventory
  • List all books

Technologies Used

  • Go (Golang)
  • MySQL
  • jinzhu/dialects/mysql for database interactions

Installation

Prerequisites

  • Go 1.16 or later
  • MySQL 5.7 or later

Steps

  1. Clone the repository:

    git clone https://github.com/Darshan016/go-bookstore.git
    cd go-bookstore
  2. Install dependencies:

    go get -u github.com/jinzhu/gorm
    go get -u github.com/jinzhu/gorm/dialects/mysql
  3. Set up MySQL:

    Create a database named bookstore and a user with appropriate privileges. For example:

    CREATE DATABASE bookstore;
    CREATE USER 'bookstore_user'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON bookstore.* TO 'bookstore_user'@'localhost';
    FLUSH PRIVILEGES;
  4. Configure the application:

    Update the main.go file with your MySQL credentials:

    dsn := "bookstore_user:password@tcp(127.0.0.1:3306)/bookstore?charset=utf8&parseTime=True&loc=Local"
  5. Run the application:

    go run main.go

API Endpoints

Create a new book

  • URL: /book/

  • Method: POST

  • Request Body:

    {
      "name": "Book Title",
      "author": "Author Name",
      "publication": "publication"
    }
  • Response:

    {
      "id": 1,
     "name": "Book Title",
      "author": "Author Name",
      "publication": "publication"
    }

Retrieve a book by ID

  • URL: /book/{id}

  • Method: GET

  • Response:

    {
      "id": 1,
    "name": "Book Title",
      "author": "Author Name",
      "publication": "publication"
    }

Update a book

  • URL: /book/{id}

  • Method: PUT

  • Request Body:

    {
    "name": "Book Title",
      "author": "Author Name",
      "publication": "publication"
    }
  • Response:

    {
      "id": 1,
     "name": "Book Title",
      "author": "Author Name",
      "publication": "publication"
    }

Delete a book

  • URL: /book/{id}

  • Method: DELETE

  • Response:

    {
      "message": "Book deleted successfully"
    }

List all books

  • URL: /book/

  • Method: GET

  • Response:

    [
      {
        "id": 1,
        "name": "Book Title",
      "author": "Author Name",
      "publication": "publication"
      },
      {
        "id": 2,
       "name": "Book Title",
      "author": "Author Name",
      "publication": "publication"
      }
    ]

Acknowledgements

  • Gorm for the ORM library
  • MySQL for the database

go-bookstore's People

Contributors

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