MosquitoRepository class

Repository for handling mosquito and disease data operations.

This repository provides a clean abstraction layer over the database service for retrieving mosquito species and disease information. It handles localization by accepting language codes for internationalized content and implements the Repository pattern for better separation of concerns.

Repository Pattern Benefits

  • Abstraction: Hides database implementation details from business logic
  • Testability: Easy to mock for unit testing
  • Consistency: Provides a consistent API for data access
  • Future-Proofing: Can switch data sources without changing business logic

Localization Support

All methods accept a language code parameter to return localized content:

  • English ('en'): Primary language with complete coverage
  • Spanish ('es'): Full translation support for Latin American users
  • Russian ('ru'): Full translation support for Eastern European users

Data Relationships

The repository handles complex relationships between entities:

  • Species ↔ Diseases: Many-to-many relationships via vector transmission
  • Translations: One-to-many relationships for localized content
  • Images: One-to-one relationships for visual assets

Usage Example

final repository = MosquitoRepository(
  databaseService: DatabaseService(),
);

// Get all species in Spanish
final species = await repository.getAllMosquitoSpecies('es');

// Find a specific species
final aedes = await repository.getMosquitoSpeciesByName('Aedes aegypti', 'en');

// Get diseases transmitted by this species
if (aedes != null) {
  final diseases = await repository.getDiseasesByVector(aedes.name, 'en');
  print('${aedes.commonName} can transmit: ${diseases.map((d) => d.name).join(', ')}');
}

Performance Characteristics

  • Caching: Database connections are cached by the service layer
  • Indexing: Queries use database indexes for optimal performance
  • Lazy Loading: Data is loaded only when requested
  • Batch Operations: Multiple related queries are optimized

Error Handling

The repository propagates database errors but provides meaningful context:

  • Not Found: Returns null for missing entities
  • Database Errors: Throws exceptions with descriptive messages
  • Localization Fallbacks: Gracefully handles missing translations

See also:

Constructors

MosquitoRepository({required DatabaseService databaseService})
Creates a new mosquito repository with the required database service.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getAllDiseases(String languageCode) Future<List<Disease>>
Retrieves all diseases from the database.
getAllMosquitoSpecies(String languageCode) Future<List<MosquitoSpecies>>
Retrieves all mosquito species from the database.
getDiseaseById(String id, String languageCode) Future<Disease?>
Retrieves a disease by its unique identifier.
getDiseasesByVector(String speciesName, String languageCode) Future<List<Disease>>
Retrieves diseases that are transmitted by a specific mosquito species.
getMosquitoSpeciesById(String id, String languageCode) Future<MosquitoSpecies?>
Retrieves a mosquito species by its unique identifier.
getMosquitoSpeciesByName(String scientificName, String languageCode) Future<MosquitoSpecies?>
Retrieves a mosquito species by its scientific name.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited