Service Layer low complexity mobile
1
Dependencies
1
Dependents
1
Entities
0
Integrations

Description

Manages reading and writing the per-user last-used distance so that recurring routes require minimal re-entry. Persists values in local device storage and updates the stored default after each successful submission.

Feature: Mileage Reimbursement Entry

distance-prefill-service

Summaries

The Distance Prefill Service meaningfully reduces the time employees spend submitting repeat mileage claims — a friction point that, if left unaddressed, drives lower adoption of the expense platform and more paper-based workarounds. By remembering the last distance entered for each user and pre-populating the form on the next visit, the service rewards employees who commute regular routes, reducing data entry to a single confirmation tap for the majority of claims. This translates directly into higher submission rates, faster reimbursement cycles, and a demonstrably better employee experience that reinforces platform adoption across the organisation.

Low development complexity with a single dependency on the local device cache layer. The primary delivery consideration is defining the cache key strategy (user-scoped) and the clear-on-logout requirement, both of which must be coordinated with the authentication team to ensure the logout event is reliably intercepted. Testing must cover: first-time users (null return), returning users (correct prefill), cache clearing on logout, and behaviour after a failed submission (should not update cache). The component is a mobile-only concern and has no backend coordination, which simplifies deployment.

It can be developed in parallel with other form components as long as the local-distance-cache interface is agreed upfront.

DistancePrefillService wraps a LocalDistanceCache dependency (which should abstract SharedPreferences or equivalent local storage). getLastUsedDistance(userId) → Future returns null when no entry exists, signalling the UI to render an empty placeholder rather than a zero value. saveLastUsedDistance(userId, distanceKm) is called by MileageClaimService after a confirmed successful persistence — not optimistically. clearCache(userId) must be wired to the app's logout event stream; use a listener in the service constructor or register it in the DI container's disposal chain.

Cache keys should be namespaced (e.g., distance_prefill_{userId}) to prevent cross-user data leakage on shared devices. All three methods return Futures even though the underlying storage may be synchronous, preserving the option to swap in a remote-backed cache later.

Responsibilities

  • Read the cached last-used distance for the current user
  • Write the new distance after a successful claim submission
  • Clear the cached value on user logout
  • Return null when no prior entry exists, letting the field show an empty placeholder

Interfaces

getLastUsedDistance(String userId) → Future<double?>
saveLastUsedDistance(String userId, double distanceKm) → Future<void>
clearCache(String userId) → Future<void>

Relationships

Dependencies (1)

Components this component depends on

Dependents (1)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/distance-prefill 5 endpoints
GET /api/v1/distance-prefill
GET /api/v1/distance-prefill/:userId
POST /api/v1/distance-prefill
PUT /api/v1/distance-prefill/:userId
DELETE /api/v1/distance-prefill/:userId