diff --git a/cache.go b/cache.go index 5428393..4638bfc 100644 --- a/cache.go +++ b/cache.go @@ -30,7 +30,8 @@ func (cache *CacheDatabase) initCache() error { division TEXT NOT NULL, city TEXT NOT NULL, place TEXT NOT NULL, - url TEXT NOT NULL + url TEXT NOT NULL, + json JSON NOT NULL );` _, err := cache.DB.Exec(createTableSql) @@ -40,8 +41,8 @@ func (cache *CacheDatabase) initCache() error { } func (cache *CacheDatabase) InsertLocation(url string, location GeoLocationMetadata) error { - stmt, err := cache.DB.Prepare("INSERT INTO locations(geohash, latitude, longitude, country, division, city, place, url) VALUES(?, ?, ?, ?, ?, ?, ?, ?)") - _, err = stmt.Exec(location.Geohash, location.Latitude, location.Longitude, location.Country, location.Division, location.City, location.Place, url) + stmt, err := cache.DB.Prepare("INSERT INTO locations(geohash, latitude, longitude, country, division, city, place, url, json) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)") + _, err = stmt.Exec(location.Geohash, location.Latitude, location.Longitude, location.Country, location.Division, location.City, location.Place, url, location.Json) return err } @@ -55,8 +56,9 @@ func (cache *CacheDatabase) GetLocation(geohash string) (*GeoLocationMetadata, e var rowCity string var rowPlace string var rowUrl string + var rowJson string - if err := cache.DB.QueryRow("SELECT * FROM locations WHERE geohash = ?", geohash).Scan(&rowGeohash, &rowLatitude, &rowLongitude, &rowCountry, &rowDivision, &rowCity, &rowPlace, &rowUrl); err != nil { + if err := cache.DB.QueryRow("SELECT * FROM locations WHERE geohash = ?", geohash).Scan(&rowGeohash, &rowLatitude, &rowLongitude, &rowCountry, &rowDivision, &rowCity, &rowPlace, &rowUrl, &rowJson); err != nil { return nil, err } @@ -69,6 +71,7 @@ func (cache *CacheDatabase) GetLocation(geohash string) (*GeoLocationMetadata, e Division: rowDivision, City: rowCity, Place: rowPlace, + Json: rowJson, } return location, nil diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index fd69e79..e53d171 100644 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -22,6 +22,7 @@ export namespace main { division: string; city: string; place: string; + json: string; static createFrom(source: any = {}) { return new GeoLocationMetadata(source); @@ -36,6 +37,7 @@ export namespace main { this.division = source["division"]; this.city = source["city"]; this.place = source["place"]; + this.json = source["json"]; } } export class ImageMetadata { diff --git a/path_parser.go b/path_parser.go index 0f69fa7..c49c4ac 100644 --- a/path_parser.go +++ b/path_parser.go @@ -44,6 +44,7 @@ type GeoLocationMetadata struct { Division string `json:"division"` City string `json:"city"` Place string `json:"place"` + Json string `json:"json"` } type PlaceholderMap map[string]string @@ -275,15 +276,24 @@ func RelocateFiles(a *App) { func DoLocationLookup(latitude float64, longitude float64, hash string, cache *CacheDatabase) *GeoLocationMetadata { type LocationResponseStruct struct { + PlaceId int `json:"place_id"` + License string `json:"licence"` + OsmType string `json:"osm_type"` + OsmId int `json:"osm_id"` Latitude string `json:"lat"` Longitude string `json:"lon"` Name string `json:"name"` Category string `json:"category"` Type string `json:"type"` AddressType string `json:"addresstype"` + DisplayName string `json:"display_name"` + PlaceRank int `json:"place_rank"` + Importance float64 Address struct { + Amenity string `json:"amenity"` Leisure string `json:"leisure"` Road string `json:"road"` + Residential string `json:"residential"` Village string `json:"village"` Suburb string `json:"suburb"` Town string `json:"town"` @@ -296,6 +306,7 @@ func DoLocationLookup(latitude float64, longitude float64, hash string, cache *C Country string `json:"country"` CountryCode string `json:"country_code"` } `json:"address"` + BoundingBox []string `json:"boundingbox"` } // Check the cache first @@ -326,12 +337,15 @@ func DoLocationLookup(latitude float64, longitude float64, hash string, cache *C // Construct GeoLocationMetadata from LocationResponse locationResponse := &LocationResponseStruct{} _ = json.NewDecoder(resp.Body).Decode(locationResponse) + jsonMarshaled, _ := json.Marshal(locationResponse) + data := GeoLocationMetadata{ Latitude: latitude, Longitude: longitude, Country: locationResponse.Address.Country, Place: locationResponse.Name, Geohash: hash, + Json: string(jsonMarshaled), } // Sort out some (hopefully) sensible mappings