Documentation
¶
Index ¶
- Variables
- func Connect() *pg.DB
- func MakeSlug(slug string) string
- func MarkProductsInactive(db orm.DB, siteID int, deal bool) error
- func NormalizeTags(tags []string) []string
- func NormalizeUrls(urls []string) []string
- func RunInTestTransaction(logging bool, fn func(orm.DB))
- func TableCountDiff(db orm.DB, table string, testFn func()) int
- func TagQuery(field string, tags []string, fn Normalizer) string
- func TestImageMatchesFixture(t *testing.T, conn *utils.MinioConnection, objectPath, fixtureName string)
- func ValidAPIUser(db orm.DB, token string) bool
- type Artist
- type Category
- type Design
- type ImageType
- type Normalizer
- type Product
- func (p *Product) AfterQuery(db orm.DB) error
- func (p *Product) BeforeInsert(db orm.DB) error
- func (p *Product) BeforeUpdate(db orm.DB) error
- func (p *Product) BuyURL(db orm.DB) (string, error)
- func (p *Product) GoURL() string
- func (p *Product) ImageURL(imageType ImageType) string
- func (p *Product) LargeImageURL() string
- func (p *Product) SmallImageURL() string
- func (p *Product) UpdateImage(db orm.DB, minioConn *utils.MinioConnection, url string) error
- func (p *Product) UpdateImageIfExpired(db orm.DB, minioConn *utils.MinioConnection, url string) error
- type ScrapydItem
- type Site
- type SiteJobType
- type SpiderItem
- type SpiderJob
- type User
Constants ¶
This section is empty.
Variables ¶
var ( OriginalImageType = imageIota(utils.Transform{Format: imaging.PNG, MimeType: "image/png", Path: "original/%d.png"}) SmallImageType = imageIota(utils.Transform{Format: imaging.JPEG, MimeType: "image/jpeg", Size: 300, Path: "thumbs/%d/300.jpg"}) LargeImageType = imageIota(utils.Transform{Format: imaging.JPEG, MimeType: "image/jpeg", Size: 1200, Path: "thumbs/%d/1200.jpg"}) )
var ( SiteDealJobType = siteiota("deal") SiteFullJobType = siteiota("full") )
var ValidSlug = regexp.MustCompile(`^\d{5}-[a-z0-9-]+`)
ValidSlug regexp in "55555-slug-string" format.
Functions ¶
func MakeSlug ¶
MakeSlug creates a slug in the format: 55555-my-slug-name. Fairly crude but ensures a unique slug without having to check the database.
func MarkProductsInactive ¶
MarkProductsInactive sets products belonging to a site as inactive. It either does all deals or non-deals.
func NormalizeTags ¶
NormalizeTags attempts to normalize tags Returns a string slice of unique, normalized tags
func NormalizeUrls ¶
NormalizeUrls attempts to normalize urls Returns a string slice of unique, normalized urls
func RunInTestTransaction ¶
RunInTestTransaction wraps database queries in a transaction.
func TagQuery ¶
func TagQuery(field string, tags []string, fn Normalizer) string
TagQuery queries and normalizes tags stored in a Postgres array column. Returns a sqlboiler QueryMod.
func TestImageMatchesFixture ¶
func TestImageMatchesFixture(t *testing.T, conn *utils.MinioConnection, objectPath, fixtureName string)
Types ¶
type Artist ¶
type Artist struct {
ID int
Name string
Slug string
Urls []string `pg:",array" sql:",notnull"`
Tags []string `pg:",array" sql:",notnull"`
Designs []*Design
}
func FindOrCreateArtist ¶
FindOrCreateArtist convenience function. It attempts to find an artist by name or by urls. Otherwise it creates a new artist.
func ImportArtistFixtures ¶
func (*Artist) ArtistAppendWhitelistedUrls ¶
ArtistAppendWhitelistedUrls normalizes urls and merges any urls from whitelisted domains with the artists urls.
type Design ¶
type Design struct {
ID int
ArtistID int
Name string
Slug string
Description string `sql:",notnull"`
Tags []string `pg:",array" sql:",notnull"`
CategoryTags []string `pg:",array" sql:",notnull"`
Mature bool `sql:",notnull"`
Artist *Artist
Products []*Product
Categories []*Category `pg:",many2many:category_designs"`
}
func FindOrCreateDesign ¶
func ImportDesignFixtures ¶
type Product ¶
type Product struct {
ID int
DesignID int
SiteID int
Slug string `sql:",notnull"`
URL string
Active bool `sql:",notnull"`
Deal bool `sql:",notnull"`
LastChance bool `sql:",notnull"`
Tags []string `pg:",array" sql:"tags,DEFAULT:'{}',notnull"`
Prices map[string]string `pg:",hstore"`
ConvertedPrices map[string]utils.ApproximatePrice `sql:"-"`
ImageBackground string
ImageUpdatedAt time.Time
ExpiresAt pg.NullTime
ActiveAt pg.NullTime
Design *Design
Site *Site
}
func ActiveDeals ¶
ActiveDeals queries the database for currently active deals and eager loads related models. It returns a `model.Product` slice and any error encountered.
func ImportProductFixtures ¶
func (*Product) LargeImageURL ¶
func (*Product) SmallImageURL ¶
func (*Product) UpdateImage ¶
func (*Product) UpdateImageIfExpired ¶
type ScrapydItem ¶
type ScrapydItem struct {
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"url"`
ArtistName string `json:"artist_name"`
ArtistUrls []string `json:"artist_urls"`
Prices map[string]int `json:"prices"`
ImageURL string `json:"image_url"`
Tags []string `json:"tags"`
FabricColors []string `json:"fabric_colors"`
Active bool `json:"active"`
Deal bool `json:"deal"`
LastChance bool `json:"last_chance"`
Valid bool `json:"valid"`
ExpiresAt time.Time `json:"expires_at"`
}
func (*ScrapydItem) StringPrices ¶
func (item *ScrapydItem) StringPrices() map[string]string
type Site ¶
type Site struct {
ID int
Name string
Slug string
DomainName string
AffiliateURL string
DealScraper bool
FullScraper bool
Active bool
DisplayOrder int
Products []*Product
}
func ActiveSitesWithJobType ¶
func ActiveSitesWithJobType(db orm.DB, jobType SiteJobType) ([]*Site, error)
func ImportSiteFixtures ¶
type SiteJobType ¶
type SiteJobType int
func (SiteJobType) DatabaseField ¶
func (e SiteJobType) DatabaseField() string
func (SiteJobType) String ¶
func (e SiteJobType) String() string
type SpiderItem ¶
type SpiderItem struct {
ID int
SpiderJobID int
ProductID int
ItemData string
Error string
CreatedAt time.Time
SpiderJob *SpiderJob
Product *Product
}
func CreateSpiderItem ¶
func FindSpiderItem ¶
func FindSpiderItem(db orm.DB, id int) (*SpiderItem, error)
func (*SpiderItem) ParseItemData ¶
func (item *SpiderItem) ParseItemData(db orm.DB, minioConn *utils.MinioConnection) error
func (*SpiderItem) UpdateError ¶
func (item *SpiderItem) UpdateError(db orm.DB, err error)