Skip to content

Order CRUD Api : Built using SOLID Principles, Gin and Redis

Notifications You must be signed in to change notification settings

Prayag2003/crud-api-go-gin-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CRUD API with Redis Persistence

This project implements a CRUD API for managing orders with persistence in Redis. It is built using Go programming language and Gin framework.

Project Structure

  • Application: Contains the main application logic including routing and server setup.
  • Handler: Handles HTTP requests and interacts with the repository.
  • Model: Defines the data structures used in the application.
  • Repository: Implements the data access layer using Redis as the storage backend.

SOLID Principles

  • Single Responsibility Principle (SRP): Each component in the project has a single responsibility. For example, the Handler package handles HTTP request handling, while the Repository package deals with data access.
  • Open/Closed Principle (OCP): The application is designed to be open for extension but closed for modification. Adding new features or modifying existing ones can be done by extending the application without changing the core logic.
  • Liskov Substitution Principle (LSP): Interfaces are used to define contracts between components, allowing different implementations to be used interchangeably.
  • Interface Segregation Principle (ISP): Interfaces are kept small and focused on specific use cases, ensuring that clients only depend on the methods they use.
  • Dependency Inversion Principle (DIP): Components depend on abstractions rather than concrete implementations, allowing for easier testing and flexibility in swapping out dependencies.

Usage

Prerequisites

  • Go installed on your system
  • Redis server running locally or accessible over the network

Installation

  1. Clone the repository:
    git clone https://github.com/Prayag2003/crud-api-golang.git
    cd crud-api-golang
  2. Install dependencies:
    go mod tidy
  3. Run the application:
    go run main.go

Documentation

Application

The App struct serves as the heart of the application, responsible for orchestrating various components such as setting up routes and initializing the HTTP server.

Responsibilities

  • Route Setup: Configures the routing logic to handle different HTTP requests and map them to corresponding handler functions.
  • HTTP Server Initialization: Initializes the HTTP server with specified configurations such as network address and handler.

Handler

Handlers play a crucial role in processing HTTP requests, handling input data, executing business logic, and generating appropriate responses. They serve as intermediaries between the incoming HTTP requests and the underlying application logic.

Responsibilities

  • Request Handling: Receives HTTP requests and delegates them to appropriate functions or methods for processing.
  • Input Parsing: Extracts data from incoming requests, validates it, and transforms it into a format suitable for further processing.
  • Business Logic Execution: Executes the necessary business logic to fulfill the request, which may include CRUD operations on orders.
  • Response Generation: Constructs and sends HTTP responses back to the client, containing relevant data or error messages.

Model

The Order and Item structs define the data model used within the application. They represent the entities involved in the order management system and encapsulate their attributes and behaviors.

Order

  • Attributes: Includes fields such as OrderID, CustomerID, Items, CreatedAt, ShippedAt, and CompletedAt.
  • Purpose: Represents an order placed by a customer, containing details such as order items, customer ID, and timestamps for creation, shipping, and completion.

Item

  • Attributes: Consists of fields like ItemID, Quantity, and Price.
  • Purpose: Represents an individual item within an order, specifying its unique identifier, quantity, and price.

Repository

The RedisRepo struct implements the repository interface, offering a set of methods to interact with the Redis database for performing CRUD operations on orders.

Responsibilities

  • Data Access: Provides methods to insert, retrieve, update, and delete order data from the Redis database.
  • Error Handling: Handles errors related to data access operations, ensuring graceful degradation and recovery from unexpected scenarios.
  • Transaction Management: Manages transactions when interacting with the Redis database to maintain data integrity and consistency.

Conclusion

This CRUD API serves as a demonstration of building a robust web service using Go and Redis. By adhering to SOLID principles, it ensures maintainability, extensibility, and testability, making it suitable for various real-world applications and scenarios.

About

Order CRUD Api : Built using SOLID Principles, Gin and Redis

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages