Skip to content

hansparson/card-tracker-be

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💳 RFID Payment & Safety Tracker Backend API

A production-ready RESTful API backend built in Go (Golang) using the Gin Web Framework and GORM (PostgreSQL). This system manages RFID card-based payments, balance accounts, and doubles as an IoT safety tracker for facilities like theme parks, playgrounds, or events.


🚀 Key Features

  • RFID Card Payment Engine: Manages card holder registration, balance status updates, and handles transactions (e.g., balance check, pay, and top-up operations).
  • Safety & GPS Tracker Integration: Features a tracker subsystem (UserTracker) designed to map physical cards/phones to GPS devices, customize emergency alarm blast modes, manage visibility, and save critical emergency medical data (blood type, allergies, illness history).
  • Audit Logging: Detailed logging tables for both transaction histories (HistoryTransactions) and top-up operations (HistoryTopup) to ensure full financial auditing.
  • ORM Auto-Migrations: Integrated GORM auto-migrations to deploy PostgreSQL tables automatically on startup.
  • Environment-Driven Configuration: Separation of code and configuration settings via godotenv.

🧠 Database Schema

The database model is configured via GORM to model real-world account structures:

erDiagram
    User {
        int id PK
        string rfid_card_id UK
        string user_name
        string user_phone UK
        double user_balance
        string user_status
        string user_email
        string user_password
        timestamp balance_update_time
    }
    UserTracker {
        int id PK
        string wallet_number UK
        string first_name
        string sure_name
        string email
        string mobile_number
        timestamp dob
        string nationality
        string NIK
        string gender
        string blood_type
        string illness
        string alergic
        string alarm_blast_mode
        string gps_device
        boolean visibility
        string registry_number
    }
    Admins {
        int id PK
        string admins_id UK
        string user_name
        string user_phone UK
        string user_email
        string password
    }
    HistoryTransactions {
        int id PK
        string rfid_card_id
        string user_name
        string user_phone
        double user_balance
        double transaction_amount
        double balance_before
        string transaction_status
        timestamp transaction_time
        string playground_name
    }
    HistoryTopup {
        int id PK
        string rfid_card_id
        string user_name
        string user_phone
        double user_balance
        double topup_amount
        double balance_before
        timestamp topup_time
        string playground_name
        string waitres_name
    }
Loading

🛣️ API Endpoints

All endpoints accept JSON payloads and return JSON responses.

Category HTTP Method Endpoint Description
User POST /user/add_new_user Register a new user & link RFID card
User POST /user/delete_user Remove user record
Admin POST /admin/new_admin Create a new administrator account
Admin POST /admin/delete_admin Delete an administrator account
Transaction POST /transaction/topup Perform a card balance top-up
Transaction POST /transaction/pay Process a payment at a terminal
Tracker POST /tracker/add_new_user Register user details on the GPS safety tracker

📁 Project Structure

  • main.go - System entry point, loads environment variables, initializes database, and starts the HTTP router.
  • blueprints/ - Defines Gin routing schemas and maps paths to services.
  • services/ - Contains business logic handlers for transactions, user profiles, and trackers.
  • db/ - Manages GORM initialization, connection pools, and GORM database schemas.
  • schema/ - Holds API request and response payload validation structs.
  • logger/ - Custom logging utilities.

⚙️ Setup and Installation

1. Prerequisites

  • Go 1.18 or higher
  • PostgreSQL Database instance

2. Configure Environment Variables

Create a .env file in the root folder with the following variables:

SQLALCHEMY_DATABASE_URI=postgres://username:password@localhost:5432/dbname?sslmode=disable
SERVER_PORT=8080

3. Install Packages

go mod download

4. Run Server

go run main.go

The GORM ORM will auto-create the necessary tables in your PostgreSQL database, and the server will start listening on the configured SERVER_PORT.


🛡️ License

Distributed under the MIT License. See LICENSE for more information.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages