Thanks to visit codestin.com
Credit goes to github.com

Skip to content

raman20/crazy-coupon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crazy Coupon - Medicine Ordering Platform Coupon System

A production-ready backend system for managing coupons in a medicine ordering platform, built with Go.

Features

  • Admin Coupon Creation & Management
  • Coupon Validation
  • Concurrent Request Handling
  • Caching with Redis
  • PostgreSQL Database
  • OpenAPI Documentation
  • Docker Support

Tech Stack

  • Go 1.21+
  • Gin Web Framework
  • PostgreSQL
  • Redis
  • GORM
  • Docker
  • Swagger/OpenAPI

Prerequisites

  • Go 1.21 or higher
  • Docker and Docker Compose
  • PostgreSQL
  • Redis

Setup Instructions

  1. Clone the repository:

    git clone https://github.com/raman20/crazy-coupon.git
    cd crazy-coupon
  2. Copy the environment file and update variables:

    cp .env.example .env
  3. Install dependencies:

    go mod download
  4. Run with Docker:

    docker compose up --build

    Or run locally:

    go run cmd/main.go

Environment Variables

Variable Description Default
DB_HOST Database host localhost
DB_PORT Database port 5432
DB_USER Database user postgres
DB_PASSWORD Database password postgres
DB_NAME Database name crazy_coupon
DB_SSL_MODE Database SSL mode disable
REDIS_HOST Redis host redis
REDIS_PORT Redis port 6379
SERVER_PORT Application port 8080

API Documentation

Once the server is running, access the Swagger documentation at:

http://localhost:8080/swagger/index.html

API Endpoints

Method Endpoint Description
GET /api/v1/coupons/applicable Get applicable coupons for a cart
POST /api/v1/coupons/validate Validate and apply a coupon
POST /api/v1/coupons Create a new coupon (admin)

Architecture Overview

Core Components

  1. Models: Defines the data structures for coupons and related entities
  2. Repository: Handles database operations
  3. Service: Implements business logic
  4. Handler: Manages HTTP requests and responses
  5. Middleware: Handles cross-cutting concerns

Concurrency & Caching

  • Uses Redis for caching frequently accessed coupons
  • Implements mutex locks for concurrent coupon validations
  • Database-level safety with PostgreSQL transactions

Development

Running Tests

go test ./...

Code Generation

swag init -g cmd/main.go

Contributing

Contributions are welcome! Please open issues or submit pull requests for improvements or bug fixes.

Support

For support, open an issue on GitHub or contact the maintainer at [email protected].

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published