Consolidate prediction functionality by merging /api/prediction endpoint into /api/stations response. Move prediction logic from PredictionController into StationController, returning prediction data alongside station results. Replace usePrediction composable with unified useStations that returns {stations, meta, prediction}. Remove PredictionRequest, related tests, and unused Vue components (FuelFinderTest, MapTest, RecommendationTest, StationListTest). Add PredictionFull component and UpsellBanner. Extend NationalFuelPredictionService to include weekly_summary (7-day series, yesterday/today averages, cheapest/priciest days) and oil signal from price_predictions table. Update Home.vue to consume prediction from stations response. Add Plan::resolveCadenceForUser helper and configure Cashier to use custom Subscription model.
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import { ref } from 'vue'
|
|
import api from '../axios.js'
|
|
|
|
export function useStations() {
|
|
const stations = ref([])
|
|
const meta = ref(null)
|
|
const prediction = ref(null)
|
|
const loading = ref(false)
|
|
const error = ref(null)
|
|
|
|
async function search({ postcode, lat, lng, fuelType = 'e10', radius = 10, sort = 'price' }) {
|
|
loading.value = true
|
|
error.value = null
|
|
stations.value = []
|
|
meta.value = null
|
|
prediction.value = null
|
|
|
|
const params = { fuel_type: fuelType, radius, sort }
|
|
|
|
if (postcode) {
|
|
params.postcode = postcode
|
|
} else if (lat && lng) {
|
|
params.lat = lat
|
|
params.lng = lng
|
|
}
|
|
|
|
try {
|
|
const response = await api.get('/stations', { params })
|
|
stations.value = response.data.data
|
|
meta.value = response.data.meta
|
|
prediction.value = response.data.prediction ?? null
|
|
} catch (err) {
|
|
error.value = err.response?.data?.errors
|
|
?? { general: ['Unable to load stations. Please try again.'] }
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function reset() {
|
|
stations.value = []
|
|
meta.value = null
|
|
prediction.value = null
|
|
error.value = null
|
|
loading.value = false
|
|
}
|
|
|
|
return { stations, meta, prediction, loading, error, search, reset }
|
|
}
|