Skip to content

Commit

Permalink
Get local forecast from current hour, not before that
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtakac committed Nov 6, 2022
1 parent 58d1f6f commit 2017201
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hr.dtakac.prognoza.data.repository

import hr.dtakac.prognoza.data.Forecast
import hr.dtakac.prognoza.data.ForecastQueries
import hr.dtakac.prognoza.domain.forecast.ForecastSaver
import hr.dtakac.prognoza.domain.forecast.SavedForecastGetter
Expand Down Expand Up @@ -46,7 +47,7 @@ class ForecastRepository(
withContext(ioDispatcher) {
forecastQueries.delete(latitude, longitude)
data.forEach {
forecastQueries.insert(
val dbModel = Forecast(
startTime = it.start,
endTime = it.end,
latitude = latitude,
Expand All @@ -59,6 +60,7 @@ class ForecastRepository(
humidity = it.humidity,
airPressureAtSeaLevel = it.airPressure
)
forecastQueries.insert(dbModel)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions data/src/main/sqldelight/hr/dtakac/prognoza/data/Forecast.sq
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ CREATE TABLE IF NOT EXISTS Forecast (
);

insert:
INSERT OR REPLACE INTO Forecast (startTime, endTime, latitude, longitude, temperature, forecastDescription, precipitation, windSpeed, windFromDirection, humidity, airPressureAtSeaLevel)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
INSERT OR REPLACE INTO Forecast VALUES ?;

delete:
DELETE FROM Forecast
Expand All @@ -33,4 +32,5 @@ WHERE abs(latitude - :latitude) < 0.00001 AND abs(longitude - :longitude) < 0.00
get:
SELECT * FROM Forecast
WHERE abs(latitude - :latitude) < 0.00001 AND abs(longitude - :longitude) < 0.00001
AND DATETIME(startTime) >= DATETIME('now', '-1 hour')
ORDER BY DATETIME(startTime) ASC;

0 comments on commit 2017201

Please sign in to comment.