TravelCoin

🌐 CloudProject – Currency Conversion API

A Flask-based backend using MongoDB, session authentication, and live currency conversion with persistence of conversion history.


πŸš€ Features

πŸ” Authentication

πŸ’± Currency Conversion

πŸ“„ Conversion History

πŸ“¦ Database (MongoDB Atlas)

Collections created automatically:


πŸ“ Project Structure

CloudProject/
│── app.py
│── fx_api.py
│── db.properties
│── README.md
│── requirements.txt

βš™οΈ Installation

1️⃣ Create Python Environment

python3 -m venv venv
source venv/bin/activate

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Install SSL Certificates (MacOS ONLY)

/Applications/Python\ 3.12/Install\ Certificates.command

πŸ”§ Configuration (db.properties)

Example db.properties:

[DB]
prefix = mongodb+srv://
user = myUser
pwd = MyPassword123
dbUrl = cluster0.abcd1.mongodb.net
dbName = cloudProjectDB
params = ?retryWrites=true&w=majority&appName=CloudProject

▢️ Running the Server

python3 app.py

Server runs at:

http://127.0.0.1:5001

πŸ“Œ API Documentation


🟒 1. Signup

POST /signup

Request Body

{
  "username": "john",
  "password": "123456"
}

Response

{
  "message": "User created",
  "user_id": "uuid"
}

🟒 2. Login

POST /login

Request Body

{
  "username": "john",
  "password": "123456"
}

Response

{
  "message": "Login successful",
  "session_id": "xxxxxxxx-xxxx"
}

🟒 3. Convert Currency

POST /convert

Headers

session_id: your-session-id

Body

{
  "base_country": "United States",
  "target_country": "Japan",
  "amount": 100
}

Response

{
  "record_id": "uuid",
  "base": "USD",
  "target": "JPY",
  "rate": 150.45,
  "converted_amount": 15045,
  "date": "2025-11-18"
}

🟒 4. Get Conversion History

GET /records

Headers

session_id: your-session-id

Response

[
  {
    "record_id": "uuid",
    "base": "USD",
    "target": "JPY",
    "amount": 100,
    "converted_amount": 15045,
    "rate": 150.45,
    "date": "2025-11-18"
  }
]

⚠️ Error Responses

Missing session:

{"error": "Session expired or invalid"}

Missing fields:

{"error": "Missing base_country or target_country"}

Frankfurter API down:

{"error": "Currency API unavailable"}

πŸ§ͺ Testing with Postman

1. Signup

POST β†’ http://127.0.0.1:5001/signup

2. Login

POST β†’ http://127.0.0.1:5001/login Copy the session_id

3. Convert

POST β†’ http://127.0.0.1:5001/convert Header:

session_id: {YOUR_SESSION}

4. Records

GET β†’ http://127.0.0.1:5001/records Header:

session_id: {YOUR_SESSION}