model

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableCity

func EnableCity(tx *gorm.DB, city CityEnabled) error

EnableCity creates an entry in cities_enabled table

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns whether an error represents a "not found" error.

func UpdateOrCreateCities

func UpdateOrCreateCities(tx *gorm.DB, cities []*City) error

UpdateOrCreateCities updates or creates the given cities in our database

Types

type City

type City struct {
	ID      json.Number `json:"id" gorm:"primary_key;unique_index"` // citylist can use floats as ID WTF
	Name    string      `json:"name" gorm:"type:varchar(100)"`
	State   string      `json:"state" gorm:"type:varchar(100)"` // SH / BW blabla
	Country string      `json:"country" gorm:"type:varchar(3)"` // max ISO3
	Coords  struct {
		Latitude  float64 `json:"lat" gorm:"column:lat"`
		Longitude float64 `json:"lon" gorm:"column:lon"`
	} `json:"coord" gorm:"embedded"`
}

City reflects a City of openweathermap longest german city name is currently: Schmedeswurtherwesterdeich 26 chars.

func FindCitiesByName

func FindCitiesByName(tx *gorm.DB, name string) ([]*City, error)

FindCitiesByName searches our storage by name dont use fmt to inject % tags, this is a sec vuln in databases

func FindCityByID

func FindCityByID(tx *gorm.DB, id string) (*City, error)

FindCityByID returns a City by it's id, error or nil

func FindEnabledCityByID

func FindEnabledCityByID(tx *gorm.DB, id string) (*City, error)

FindEnabledCityByID returns a City by it's id, error or nil

func (*City) TableName

func (c *City) TableName() string

TableName returns the TableName of our user

type CityEnabled

type CityEnabled struct {
	ID      json.Number `json:"id" gorm:"primary_key;unique_index"` // citylist can use floats as ID WTF
	Name    string      `json:"name" gorm:"type:varchar(100)"`
	State   string      `json:"state" gorm:"type:varchar(100)"` // SH / BW blabla
	Country string      `json:"country" gorm:"type:varchar(3)"` // max ISO3
	Coords  struct {
		Latitude  float64 `json:"lat" gorm:"column:lat"`
		Longitude float64 `json:"lon" gorm:"column:lon"`
	} `json:"coord" gorm:"embedded"`
}

CityEnabled holds enabled cities we are going to use a second table `cities_enabled` as `cities` can get quite huge. the cities_enabled table is used to store "only" cities we are going to update this allows us fast selects without creating complex statistic tables (pg_statistics) we are not referencing *city to allow OneOnOne struct conversion

func FindEnabledCities

func FindEnabledCities(tx *gorm.DB) ([]*CityEnabled, error)

FindEnabledCities returns all enabled cities

func (*CityEnabled) TableName

func (ce *CityEnabled) TableName() string

TableName returns the TableName of our user

type CityNotFoundError

type CityNotFoundError struct{}

CityNotFoundError represents when a user is not found.

func (CityNotFoundError) Error

func (e CityNotFoundError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL