Skip to content

Implement multi-currency support with timestamps and user activation defaults#6

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-7e88afa2-79f1-4956-b389-f9ad9c47331c
Draft

Implement multi-currency support with timestamps and user activation defaults#6
Copilot wants to merge 2 commits intomainfrom
copilot/fix-7e88afa2-79f1-4956-b389-f9ad9c47331c

Conversation

Copy link
Contributor

Copilot AI commented Aug 27, 2025

This PR implements comprehensive multi-currency exchange rate support for the BCV API, addressing the need to handle multiple currencies beyond USD (euro, yuan, lira, rublo) and adding proper data management features.

Overview

The BCV website provides exchange rates for multiple currencies in separate divs with IDs matching the currency names. This implementation extends the API to scrape and store rates for all supported currencies while maintaining backward compatibility.

Key Changes

Database Schema Updates

  • Rate Model: Renamed dollar field to rate for generic currency support and added currency field to distinguish between different exchange rates
  • Timestamps: Added create_date and update_date fields to both User and Rate models for proper audit tracking
  • User Defaults: Changed User.is_active default from True to False to ensure new users are deactivated by default

Multi-Currency Support

The scraper now supports five currencies that correspond to BCV website div IDs:

  • USD (dolar) - US Dollar
  • EUR (euro) - Euro
  • CNY (yuan) - Chinese Yuan
  • TRY (lira) - Turkish Lira
  • RUB (rublo) - Russian Ruble

API Enhancements

All rate endpoints now accept a currency query parameter:

# Get latest rates for different currencies
GET /rates/?currency=USD  # Default
GET /rates/?currency=EUR
GET /rates/?currency=CNY

# Historical data with currency filtering
GET /rates/history?currency=EUR&start_date=2025-08-01&end_date=2025-08-27

# Currency-specific rate creation
POST /rates/?currency=TRY

Response Format Updates

API responses now include the currency information:

{
  "rate": 40.2,
  "currency": "EUR", 
  "date": "2025-08-27"
}

Technical Implementation

BCV Scraper Enhancement

The scraper function is now generic and accepts currency parameters that map to the corresponding div IDs on the BCV website:

def get_exchange_rate(currency: str = "dolar") -> float:
    # Scrapes specific currency div from BCV website
    div_currency = soup.find(id=currency)

Database Services

Updated all database operations to handle currency-specific queries while maintaining efficient indexing on both date and currency fields.

Backward Compatibility

Existing API calls continue to work as before, defaulting to USD when no currency is specified.

Validation

  • ✅ All currency rates can be scraped from BCV website structure
  • ✅ Database schema migrates cleanly with new fields
  • ✅ API endpoints respond correctly with currency-specific data
  • ✅ User creation defaults to inactive status with proper timestamps
  • ✅ Multi-currency operations work simultaneously without conflicts
![API Documentation](https://github.com/user-attachments/assets/456afa4e-db4c-4276-90ce-7d20ffe68dbe)

The implementation maintains the same efficient architecture while extending functionality to meet the multi-currency requirements specified in the issue.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: rafnixg <10915285+rafnixg@users.noreply.github.com>
Copilot AI changed the title [WIP] Agrega que se pueda obtener otros tipos de cambio, como (euro, yuan, lira, rublo), tiene la mista estructura un div con ID igual a la moneda, cambia el modelo Rate para que integre este cambio (el campo dollar deberia llamarse rate) debe tener la moned... Implement multi-currency support with timestamps and user activation defaults Aug 27, 2025
Copilot AI requested a review from rafnixg August 27, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants