Skip to content

MillerTechnologyPeru/FuelingApp

Repository files navigation

FuelingApp

Modular Swift package for browsing fueling locations — a searchable list and map of locations, and a location detail screen with current fuel prices.

Built on CoreModel for persistence and delivered as a Swift Playground app (no Xcode project).

Modules

Module Description
CoreFueling Domain entities (Location, FuelProduct, FuelOption) declared with the CoreModel @Entity macro, plus search queries and geo primitives.
FuelingAPI REST API implemented as extensions of an HTTPClient protocol (swift-http-types) with an injectable base URL (ServerURL) — no hardcoded hostnames, URLSession is just one conformer.
FuelingModel Store (persistence + network composition root) and @Observable view models for the location list and location detail.
FuelingUI SwiftUI views: LocationsView (list/map toggle), LocationListView, LocationMapView, LocationDetailView.

Store supports two storage backends: CoreData (Store(named:), Darwin only) and SQLite (Store(sqliteDatabase:), cross-platform — used on Android/Linux).

Running the app

Open Fueling.swiftpm in Xcode or Swift Playgrounds and run. It fetches from a real server whose base URL is injected via the FUELING_SERVER_URL environment variable (set it in the Xcode scheme's Arguments tab, or export it before swift run) — nothing is hardcoded, and it defaults to http://localhost:8080 when unset:

let service = APILocationService(server: .fromEnvironment())
let store = try Store(locationService: service)

For an offline demo instead, use the bundled sample data with an in-memory store:

let store = try Store(locationService: .mock, isStoredInMemoryOnly: true)

Or run a real (fake-data) server locally instead of relying on the in-process mock — Scripts/test-server.py serves Scripts/test-data.json (a flat-file "database", edit and reload without restarting the server) over the same /v1/locations//v1/fuelprice shape the real API uses:

python3 Scripts/test-server.py            # http://localhost:8080
FUELING_SERVER_URL=http://localhost:8080 swift run   # or set it in Xcode

Usage

import SwiftUI
import FuelingModel
import FuelingUI

// list / map of locations
LocationsView { locationID in
    // handle selection
}
.environment(store)

// location detail with fuel prices
LocationDetailView(location: locationID)
    .environment(store)

Android

Android/ is a separate Swift package (FuelingAndroid) and Gradle project that exports FuelingModel/CoreFueling to Kotlin over JNI using swift-java (jextract). See Android/README.md for the build/toolchain requirements.

Like the playground app, it fetches from a real server — but through a Kotlin-implemented HTTPClient transport (HttpURLConnection behind a swift-java JNI callback) rather than URLSession, keeping FoundationNetworking and its ICU dependency chain out of the Android build entirely. The base URL is injected from the FUELING_SERVER_URL environment variable at Gradle build time (baked into BuildConfig, since an installed app has no shell environment of its own to read at runtime) — defaulting to http://localhost:8080. Persistence is a local SQLite cache, same as the rest of the package. Point an emulator at Scripts/test-server.py running on the host with -PfuelingServerUrl=http://10.0.2.2:8080 (10.0.2.2 is the emulator's alias for the host's localhost).

Tests

swift test

About

Swift Fueling App

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors