A RESTful API service for managing vouchers, customer points, and redemptions built with Go.
- Brand management
- Voucher creation and management
- Customer points tracking
- Voucher redemption system
- MySQL database integration
- Go 1.21 or higher
- MySQL 5.7 or higher (XAMPP or standalone)
- Make sure you have the following environment variables set up in your
.envfile:DB_HOST=localhost DB_PORT=3306 DB_USER=root DB_PASSWORD= DB_NAME=voucher_db
-
Clone the repository
git clone https://github.com/yourusername/voucher-api.git cd voucher-api -
Install dependencies
go mod download
-
Set up the database
- Create a new MySQL database named
voucher_db - Import the schema using
schema.sql
- Create a new MySQL database named
-
Create and configure
.envfilecp .env.example .env # Edit .env with your database credentials -
Run the application
go run main.go
GET /api/brands- List all brandsPOST /api/brands- Create a new brandGET /api/brands/{id}- Get brand detailsPUT /api/brands/{id}- Update brandDELETE /api/brands/{id}- Delete brand
GET /api/vouchers- List all vouchersPOST /api/vouchers- Create a new voucherGET /api/vouchers/{id}- Get voucher detailsPUT /api/vouchers/{id}- Update voucherDELETE /api/vouchers/{id}- Delete voucherGET /api/vouchers/brand/{id}- Get vouchers by brand
GET /api/customers- List all customersPOST /api/customers- Create a new customerGET /api/customers/{id}- Get customer detailsPUT /api/customers/{id}- Update customerDELETE /api/customers/{id}- Delete customer
POST /api/redemptions- Create a new redemptionGET /api/redemptions/{id}- Get redemption detailsGET /api/customers/{id}/redemptions- Get customer's redemptions
- Go to db4free.net
- Create a new account and database
- Note down your database credentials
- Update
config.production.yamlwith your db4free.net credentials
- Create an account on Render
- Create a new Web Service
- Connect your GitHub repository
- Configure the build settings:
- Build Command:
go build -o main . - Start Command:
./main
- Build Command:
- Add environment variables from your
config.production.yaml
-
Build the Docker image:
docker build -t voucher-api . -
Run the container:
docker run -p 8080:8080 voucher-api
The application uses the following tables:
brands- Store brand informationvouchers- Store voucher detailscustomers- Store customer information and points balanceredemptions- Store redemption transactionsredemption_items- Store individual items in a redemption
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.