Coder Social home page Coder Social logo

book_store_api's Introduction

Book Store Golang Project

This is a Golang project for a book store, designed for learning purposes. The project implements basic CRUD (Create, Read, Update, Delete) operations for managing books.

Features

  • Book Management:

    • Add new books to the store.
    • Retrieve a list of all books available in the store.
    • Get detailed information about a specific book by its ID.
    • Delete books from the store.
    • Get detailed information about a specific book by its ISBN.
    • Update existing books with new information or modifications.
  • Author Management:

    • Add new authors to the store.
    • Retrieve a list of all authors.
    • Get detailed information about a specific author by their ID.
    • Delete authors from the store.
    • Update existing author information.
  • User Management:

    • Create new users with unique API keys.
    • Authenticate users with middleware authentication.
    • Manage user permissions and access control.
  • Middleware Authentication:

    • Secure API endpoints using middleware authentication.
    • Authenticate user requests using API keys.
    • Ensure only authorized users have access to sensitive endpoints.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Golang installed on your system
  • PostgreSQL database server installed and running
  • Goose CLI tool installed (for database migrations)
  • SQLC CLI tool installed (for generating database queries)
  • Git installed on your system

Installation

To install and run this project, follow these steps:

  1. Clone the repository:

    git clone https://www.github.com/Hayoun01/book_store_api.git
  2. Navigate to the project directory:

    cd book_store_api
  3. Install project dependencies:

    go mod tidy
  4. Set up the PostgreSQL database:

    • Create a new database named book_store.
    • GO TO
  5. Configure environment variables:

    • Copy the .env.example file to .env.
    • Update the .env file with your PostgreSQL database credentials and app Port.
  6. Run the application:

    go run ./cmd/main/

The application should now be running. Access the API at http://localhost:8080.

Usage

Once the application is running, you can interact with the API endpoints using tools like cURL, Postman, or a web browser:

  • GET /books: Retrieve a list of all books.
  • POST /create_book: Add a new book to the store (authentication required).
  • GET /books/{book_id}: Get details of a specific book by its ID.
  • DELETE /books/{book_id}: Delete a book from the store (authentication required).
  • POST /create_author: Create a new author (authentication required).
  • GET /authors: Retrieve a list of all authors.
  • POST /users: Create a new user (no authentication required).
  • GET /ready: Check if the server is ready (no authentication required).

Project Hierarchy

The project follows the following directory structure:

  • cmd/main: Main entry point of the application.
  • pkg/auth: Contains authentication-related code.
  • pkg/config: Configuration settings for the application.
  • pkg/controllers: Controllers for handling HTTP requests.
  • pkg/db: Database-related code, including migrations, queries, and SQLC generated code.
  • pkg/models: Data models used by the application.
  • pkg/routes: Route definitions for the API endpoints.
  • pkg/utils: Utility functions used throughout the application.

Database Migrations

Database migrations are managed using Goose. Use the following Makefile commands to manage migrations:

# Apply pending migrations.
make migrateup
# Rollback the last migration.
make migratedown

SQLC Queries

SQLC is used to generate type-safe database queries. Use the following Makefile command to generate SQLC queries:

# Generate SQLC queries.
make sqlc 

Contributing

Contributions are welcome! Here's how you can contribute to this project:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix: git checkout -b feature-name.
  3. Make your changes and commit them: git commit -m 'Add new feature'.
  4. Push to your fork: git push origin feature-name.
  5. Create a pull request on the original repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Feel free to customize this template according to your project's specific requirements and structure.

book_store_api's People

Contributors

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