comic

package
v0.1.4-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 18 Imported by: 0

README

🎭 Comic

The comic package contains the models and repositories for publishers, issues, and characters and their issues, sources, and sync logs.

Helpful queries

All
SELECT count(*) AS issue_count, c.id, concat_ws(',', c.name, c.other_name) AS name, c.other_name, c.slug
FROM characters c
  INNER JOIN character_issues ci ON ci.character_id = c.id
WHERE c.is_disabled = FALSE
GROUP BY c.slug, c.id, c.name, c.other_name
ORDER BY issue_count DESC;
Marvel
SELECT count(*) AS issue_count, c.id, concat_ws(',', c.name, c.other_name) AS name, c.other_name, c.slug
FROM characters c
  INNER JOIN character_issues ci ON ci.character_id = c.id
WHERE c.publisher_id = 1
  AND c.is_disabled = FALSE
GROUP BY c.slug, c.id, c.name, c.other_name
ORDER BY issue_count DESC;
DC
SELECT count(*) AS issue_count, c.id, concat_ws(',', c.name, c.other_name) AS name, c.other_name, c.slug
FROM characters c
  INNER JOIN character_issues ci ON ci.character_id = c.id
WHERE c.publisher_id = 2
  AND c.is_disabled = FALSE
GROUP BY c.slug, c.id, c.name, c.other_name
ORDER BY issue_count DESC;
All
SELECT count(*) AS issue_count, c.id, concat_ws(',', c.name, c.other_name) AS name, c.other_name, c.slug
FROM characters c
  INNER JOIN character_issues ci ON ci.character_id = c.id
WHERE c.is_disabled = FALSE
  AND ci.appearance_type & B'00000001' > 0::BIT(8)
GROUP BY c.slug, c.id, c.name, c.other_name
ORDER BY issue_count DESC;
Marvel
SELECT count(*) AS issue_count, c.id, concat_ws(',', c.name, c.other_name) AS name, c.slug
FROM characters c
  INNER JOIN character_issues ci ON ci.character_id = c.id
WHERE c.publisher_id = 1
  AND c.is_disabled = FALSE
  AND ci.appearance_type & B'00000001' > 0::BIT(8)
GROUP BY c.slug, c.id, c.name, c.other_name
ORDER BY issue_count DESC;
DC
SELECT count(*) AS issue_count, c.id, concat_ws(',', c.name, c.other_name) AS name, c.other_name, c.slug
FROM characters c
  INNER JOIN character_issues ci ON ci.character_id = c.id
WHERE c.publisher_id = 2
  AND c.is_disabled = FALSE
  AND ci.appearance_type & B'00000001' > 0::BIT(8)
GROUP BY c.slug, c.id, c.name, c.other_name
ORDER BY issue_count DESC;
SELECT count(*) AS issue_count, c.id, c.name, c.other_name, c.slug
FROM characters c
  INNER JOIN character_issues ci ON ci.character_id = c.id
  INNER JOIN issues i on i.id = ci.issue_id
WHERE c.publisher_id = 1
      AND c.is_disabled = FALSE
      AND date_part('year', i.sale_date) > 2010
GROUP BY c.slug, c.id, c.name, c.other_name
ORDER BY issue_count DESC;

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppearanceType

type AppearanceType uint8

AppearanceType is a type of appearance, such as an alternate universe or main character appearance. A bitwise enum representing the types of appearances. Main is 001 Alternate is 100 Both Main and Alternate would be 101 so: `Main | Alternate`

const (
	// Main is their main universe(s)
	Main AppearanceType = 1 << 0
	// Alternate is an alternate reality appearance or whatever.
	Alternate AppearanceType = 1 << 1
)

The types of appearances for a character issue. Bitwise values to represent appearance types.

func (AppearanceType) HasAll

func (u AppearanceType) HasAll(flags AppearanceType) bool

HasAll checks that the category has all of the given flags.

func (AppearanceType) HasAny

func (u AppearanceType) HasAny(flags AppearanceType) bool

HasAny checks that the category has any of the given flags.

func (AppearanceType) MarshalJSON

func (u AppearanceType) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON string representation. TODO: Move marshaling stuff to presentation.

func (*AppearanceType) Scan

func (u *AppearanceType) Scan(value interface{}) error

Scan for the ORM converting the enum.

func (AppearanceType) String

func (u AppearanceType) String() string

String gets the string value of the appearance type.

func (AppearanceType) Value

func (u AppearanceType) Value() (driver.Value, error)

Value for the ORM converting the enum.

type AppearancesByYears

type AppearancesByYears struct {
	CharacterSlug CharacterSlug     `json:"slug"` // The unique identifier for the character.
	Aggregates    []YearlyAggregate `json:"aggregates"`
}

AppearancesByYears represents the key, category, and appearances categorized per year for a character.

func NewAppearancesByYears

func NewAppearancesByYears(slug CharacterSlug, aggs []YearlyAggregate) AppearancesByYears

NewAppearancesByYears creates a new struct with the parameters.

func (*AppearancesByYears) AddAppearance

func (c *AppearancesByYears) AddAppearance(appearance YearlyAggregate) *AppearancesByYears

AddAppearance adds an appearance to the appearances for the character.

func (*AppearancesByYears) AlternateTotal

func (c *AppearancesByYears) AlternateTotal() int

AlternateTotal gets the total alternate appearances per year.

func (*AppearancesByYears) MainTotal

func (c *AppearancesByYears) MainTotal() int

MainTotal gets the total main appearances per year.

func (*AppearancesByYears) Total

func (c *AppearancesByYears) Total() int

Total returns the total number of appearances per year.

type AppearancesByYearsMapRepository

type AppearancesByYearsMapRepository interface {
	ListMap(slugs ...CharacterSlug) (map[CharacterSlug][]AppearancesByYears, error)
}

AppearancesByYearsMapRepository is the repository for listing a character's appearances by years in a map.

type AppearancesByYearsRepository

type AppearancesByYearsRepository interface {
	List(slugs CharacterSlug) (AppearancesByYears, error)
}

AppearancesByYearsRepository is the repository interface for getting a characters appearances per year.

type AppearancesByYearsWriter

type AppearancesByYearsWriter interface {
	Set(apps AppearancesByYears) error
	Delete(slug CharacterSlug) (int64, error)
}

AppearancesByYearsWriter sets the appearances by years for a character.

type AppearancesSyncer

type AppearancesSyncer struct {
	// contains filtered or unexported fields
}

AppearancesSyncer to sync yearly appearances from Postgres to Redis.

func NewAppearancesSyncer

func NewAppearancesSyncer(db ORM, redis RedisClient) *AppearancesSyncer

NewAppearancesSyncer returns a new appearances syncer

func NewAppearancesSyncerRW

NewAppearancesSyncerRW returns a new appearances syncer with the reader and writer for the cache.

func (*AppearancesSyncer) Sync

func (s *AppearancesSyncer) Sync(slug CharacterSlug) (int, error)

Sync gets all the character's appearances from the database and syncs them to Redis. returns the total number of issues synced and an error if any.

type AvgPerYearRank

type AvgPerYearRank uint

AvgPerYearRank is the rank for average issues per year.

func (AvgPerYearRank) Value

func (r AvgPerYearRank) Value() uint

Value returns the raw value.

type Character

type Character struct {
	ID                CharacterID   `json:"-"`
	Publisher         Publisher     `json:"publisher"`
	PublisherID       PublisherID   `pg:",fk:publisher_id" sql:",notnull,on_delete:CASCADE" json:"-"`
	Name              string        `sql:",notnull" json:"name"`
	OtherName         string        `json:"other_name"`
	Description       string        `json:"description"`
	Image             string        `json:"image"`
	Slug              CharacterSlug `sql:",notnull,unique:uix_character_slug" json:"slug"`
	VendorType        VendorType    `sql:",notnull,unique:uix_vendor_type_vendor_id" json:"-"`
	VendorID          string        `sql:",notnull,unique:uix_vendor_type_vendor_id" json:"-"`
	VendorImage       string        `json:"vendor_image"`
	VendorImageMd5    string        `sql:",type:varchar(32)," json:"-"`
	VendorURL         string        `json:"vendor_url"`
	VendorDescription string        `json:"vendor_description"`
	IsDisabled        bool          `json:"-" sql:",notnull"`
	CreatedAt         time.Time     `sql:",notnull,default:NOW()" json:"-"`
	UpdatedAt         time.Time     `sql:",notnull,default:NOW()" json:"-"`
	// contains filtered or unexported fields
}

Character - A model for a character.

func NewCharacter

func NewCharacter(name string, publisherID PublisherID, vendorType VendorType, vendorID string) *Character

NewCharacter Creates a new character.

type CharacterCriteria

type CharacterCriteria struct {
	IDs               []CharacterID
	Slugs             []CharacterSlug
	PublisherIDs      []PublisherID
	PublisherSlugs    []PublisherSlug
	FilterSources     bool         // Filter characters that only have sources. If false it returns characters regardless.
	FilterIssues      bool         // Filter characters that only have issues. If false it returns characters regardless.
	VendorTypes       []VendorType // Include characters that are disabled. By default it does not.
	IncludeIsDisabled bool
	VendorIds         []string
	Limit             int
	Offset            int
}

CharacterCriteria for querying characters.

type CharacterID

type CharacterID uint

CharacterID is the PK identifier for the character.

func (CharacterID) Value

func (id CharacterID) Value() uint

Value returns the raw value.

type CharacterIssue

type CharacterIssue struct {
	ID             CharacterIssueID
	Character      *Character     // Not eager-loaded. Could be nil.
	CharacterID    CharacterID    `pg:",fk:character_id" sql:",notnull,unique:uix_character_id_issue_id,on_delete:CASCADE"`
	Issue          *Issue         // Not eager-loaded. Could be nil.
	IssueID        IssueID        `pg:",fk:issue_id" sql:",notnull,unique:uix_character_id_issue_id,on_delete:CASCADE"`
	AppearanceType AppearanceType `sql:",notnull,type:bit(8),default:B'00000001'"`
	Importance     *Importance    `sql:",type:smallint"`
	CreatedAt      time.Time      `sql:",notnull,default:NOW()" json:"-"`
	UpdatedAt      time.Time      `sql:",notnull,default:NOW()" json:"-"`
	// contains filtered or unexported fields
}

CharacterIssue references an issue for a character.

func NewCharacterIssue

func NewCharacterIssue(characterID CharacterID, id IssueID, appearanceType AppearanceType) *CharacterIssue

NewCharacterIssue creates a new character issue struct.

type CharacterIssueID

type CharacterIssueID uint

CharacterIssueID is the PK identifier for a character issue.

type CharacterIssueRepository

type CharacterIssueRepository interface {
	CreateAll(cis []*CharacterIssue) error
	Create(ci *CharacterIssue) error
	FindOneBy(characterID CharacterID, issueID IssueID) (*CharacterIssue, error)
	InsertFast(issues []*CharacterIssue) error
	RemoveAllByCharacterID(id CharacterID) (int, error)
}

CharacterIssueRepository is the repository interface for character issues.

type CharacterRepository

type CharacterRepository interface {
	Create(c *Character) error
	Update(c *Character) error
	FindBySlug(slug CharacterSlug, includeIsDisabled bool) (*Character, error)
	FindAll(cr CharacterCriteria) ([]*Character, error)
	UpdateAll(characters []*Character) error
	Remove(id CharacterID) error
	Total(cr CharacterCriteria) (int64, error)
}

CharacterRepository is the repository interface for characters.

type CharacterService

type CharacterService struct {
	// contains filtered or unexported fields
}

CharacterService is the service for characters.

func NewCharacterService

NewCharacterService creates a new character service.

func NewCharacterServiceFactory

func NewCharacterServiceFactory(db ORM) *CharacterService

NewCharacterServiceFactory creates a new character service but with the appearances by years coming from postgres.

func (*CharacterService) Character

func (s *CharacterService) Character(slug CharacterSlug) (*Character, error)

Character gets a non-disabled character by its slug.

func (*CharacterService) CharacterByVendor

func (s *CharacterService) CharacterByVendor(vendorID string, vendorType VendorType, includeIsDisabled bool) (*Character, error)

CharacterByVendor gets a character from the specified vendor and whether the character is disabled or not.

func (*CharacterService) Characters

func (s *CharacterService) Characters(slugs []CharacterSlug, limit, offset int) ([]*Character, error)

Characters gets all non-disabled characters by their slugs. A `limit` of `0` means unlimited.

func (*CharacterService) CharactersByPublisher

func (s *CharacterService) CharactersByPublisher(slugs []PublisherSlug, filterSources bool, limit, offset int) ([]*Character, error)

CharactersByPublisher lists enabled characters by their publisher.

func (*CharacterService) CharactersWithSources

func (s *CharacterService) CharactersWithSources(slugs []CharacterSlug, limit, offset int) ([]*Character, error)

CharactersWithSources gets non-disabled characters who have sources. A `limit` of `0` means unlimited.

func (*CharacterService) Create

func (s *CharacterService) Create(c *Character) error

Create creates a new character

func (*CharacterService) CreateIssue

func (s *CharacterService) CreateIssue(issue *CharacterIssue) error

CreateIssue creates an issue.

func (*CharacterService) CreateIssueP

func (s *CharacterService) CreateIssueP(characterID CharacterID, issueID IssueID, appearanceType AppearanceType, importance *Importance) (*CharacterIssue, error)

CreateIssueP creates an issue from the parameters.

func (*CharacterService) CreateIssues

func (s *CharacterService) CreateIssues(issues []*CharacterIssue) error

CreateIssues creates multiple issues in a bulk query. TODO: Generated ID doesn't get set!

func (*CharacterService) CreateSource

func (s *CharacterService) CreateSource(source *CharacterSource) error

CreateSource creates a source for a character, if it doesn't exist. If it exists, an ErrAlreadyExists gets returned as an error. A little janky right now.

func (*CharacterService) CreateSyncLog

func (s *CharacterService) CreateSyncLog(syncLog *CharacterSyncLog) error

CreateSyncLog creates a sync log for a character.

func (*CharacterService) CreateSyncLogP

func (s *CharacterService) CreateSyncLogP(id CharacterID, status CharacterSyncLogStatus, syncType CharacterSyncLogType, syncedAt *time.Time) (*CharacterSyncLog, error)

CreateSyncLogP creates a sync log with the parameters.

func (*CharacterService) Issue

func (s *CharacterService) Issue(characterID CharacterID, issueID IssueID) (*CharacterIssue, error)

Issue gets a character issue by its character ID and issue ID.

func (*CharacterService) MustNormalizeSources

func (s *CharacterService) MustNormalizeSources(c *Character)

MustNormalizeSources normalizes sources for main and alternate sources and disables any unneeded sources.

func (*CharacterService) RemoveIssues

func (s *CharacterService) RemoveIssues(ids ...CharacterID) (int, error)

RemoveIssues deletes all associated issues for the given character IDs.

func (*CharacterService) Source

func (s *CharacterService) Source(id CharacterID, vendorURL string) (*CharacterSource, error)

Source gets a unique character source by its character ID and vendor url

func (*CharacterService) Sources

func (s *CharacterService) Sources(id CharacterID, vendorType VendorType, isMain *bool) ([]*CharacterSource, error)

Sources lists all non-disabled character sources from the given parameters. If `isMain` is `nil`, it will list both types of sources. If `isMain` is true, it will list main sources. If `isMain` is `false`, it will list alternate sources.

func (*CharacterService) TotalSources

func (s *CharacterService) TotalSources(id CharacterID) (int64, error)

TotalSources gets the total number of sources for a character

func (*CharacterService) Update

func (s *CharacterService) Update(c *Character) error

Update updates a character.

func (*CharacterService) UpdateAll

func (s *CharacterService) UpdateAll(characters []*Character) error

UpdateAll updates all characters

func (*CharacterService) UpdateSource

func (s *CharacterService) UpdateSource(source *CharacterSource) error

UpdateSource updates an existing source

func (*CharacterService) UpdateSyncLog

func (s *CharacterService) UpdateSyncLog(syncLog *CharacterSyncLog) error

UpdateSyncLog updates a sync log for a character.

type CharacterServicer

type CharacterServicer interface {
	// Creates a character
	Create(character *Character) error
	// Character gets a character by its slug.
	Character(slug CharacterSlug) (*Character, error)
	// Updates a character.
	Update(character *Character) error
	// UpdateAll updates all characters
	UpdateAll(characters []*Character) error
	// CharactersWithSources gets all the enabled characters who have sources.
	CharactersWithSources(slug []CharacterSlug, limit, offset int) ([]*Character, error)
	// Characters gets all enabled characters by their slugs.
	Characters(slugs []CharacterSlug, limit, offset int) ([]*Character, error)
	// CharacterByVendor gets all the characters by the vendor. If `includeIsDisabled` is true, it will include disabled characters.
	CharacterByVendor(vendorID string, vendorType VendorType, includeIsDisabled bool) (*Character, error)
	// CharactersByPublisher list characters alphabetically. If `filterSources` is true, it will only list characters with sources.
	CharactersByPublisher(slugs []PublisherSlug, filterSources bool, limit, offset int) ([]*Character, error)
	// CreateSource creates a character source if it doesn't exist. If it exists, it returns the found source and an error.
	// And also modifies `source` to get the found values.
	CreateSource(source *CharacterSource) error
	// UpdateSource updates a character source
	UpdateSource(source *CharacterSource) error
	// MustNormalizeSources so that main vs alternate sources are categorized correctly and disables any unnecessary sources.
	// panics if there's an error.
	MustNormalizeSources(*Character)
	// Source gets a unique source by its character ID and vendor url.
	Source(id CharacterID, vendorURL string) (*CharacterSource, error)
	// Sources gets all the sources for a  character.
	Sources(id CharacterID, vendorType VendorType, isMain *bool) ([]*CharacterSource, error)
	// TotalSources gets the total sources for a character.
	TotalSources(id CharacterID) (int64, error)
	// CreateIssueP creates an issue for a character with the parameters.
	CreateIssueP(
		characterID CharacterID,
		issueID IssueID,
		appearanceType AppearanceType,
		importance *Importance) (*CharacterIssue, error)
	// CreateIssue creates an issue for a character.
	CreateIssue(issue *CharacterIssue) error
	// CreateIssues creates multiple issues for a character. // TODO: Autogenerated IDs not returned in struct!!
	CreateIssues(issues []*CharacterIssue) error
	// Issue gets a character issue by its character ID and issue ID
	Issue(characterID CharacterID, issueID IssueID) (*CharacterIssue, error)
	// RemoveIssues removes all the issues w/ the associated character ID.
	RemoveIssues(ids ...CharacterID) (int, error)
	// CreateSyncLogP creates a sync log for a character with the parameters.
	CreateSyncLogP(
		id CharacterID,
		status CharacterSyncLogStatus,
		syncType CharacterSyncLogType,
		syncedAt *time.Time) (*CharacterSyncLog, error)
	// CreateSyncLog creates a sync log.
	CreateSyncLog(syncLog *CharacterSyncLog) error
	// UpdateSyncLog updates a sync log
	UpdateSyncLog(syncLog *CharacterSyncLog) error
}

CharacterServicer is the service interface for characters. TODO: This interface is huge and not idiomatic Go...fix later.

type CharacterSlug

type CharacterSlug string

CharacterSlug is the unique slug for the character.

func NewCharacterSlugs

func NewCharacterSlugs(strs ...string) []CharacterSlug

NewCharacterSlugs creates character slugs from the specified `strs` string.

func (CharacterSlug) Value

func (slug CharacterSlug) Value() string

Value returns the raw value.

type CharacterSource

type CharacterSource struct {
	ID              CharacterSourceID `json:"id"`
	Character       *Character        // Pointer. Could be nil. Not eager-loaded.
	CharacterID     CharacterID       `pg:",fk:character_id" sql:",notnull,unique:uix_character_id_vendor_url,on_delete:CASCADE" json:"character_id"`
	VendorType      VendorType        `sql:",notnull,type:smallint" json:"type"`
	VendorURL       string            `sql:",notnull,unique:uix_character_id_vendor_url"`
	VendorName      string            `sql:",notnull"`
	VendorOtherName string
	IsDisabled      bool      `sql:",notnull"`
	IsMain          bool      `sql:",notnull"`
	CreatedAt       time.Time `sql:",default:NOW(),notnull" json:"-"`
	UpdatedAt       time.Time `sql:",notnull,default:NOW()" json:"-"`
	// contains filtered or unexported fields
}

CharacterSource contains external profile links to the character.

func NewCharacterSource

func NewCharacterSource(url, name string, id CharacterID, vendorType VendorType) *CharacterSource

NewCharacterSource creates a new character source struct.

type CharacterSourceCriteria

type CharacterSourceCriteria struct {
	CharacterIDs []CharacterID
	VendorUrls   []string
	VendorType   VendorType
	// If IsMain is null, it will  return both.
	IsMain *bool
	// Include sources that are disabled. By default it does not include disabled sources.
	IncludeIsDisabled bool
	Limit             int
	Offset            int
}

CharacterSourceCriteria for querying character sources.

type CharacterSourceID

type CharacterSourceID uint

CharacterSourceID is the PK identifier for the character source struct.

type CharacterSourceRepository

type CharacterSourceRepository interface {
	Create(s *CharacterSource) error
	FindAll(criteria CharacterSourceCriteria) ([]*CharacterSource, error)
	Remove(id CharacterSourceID) error
	// Raw runs a raw query on the character sources.
	Raw(query string, params ...interface{}) error
	Update(s *CharacterSource) error
}

CharacterSourceRepository is the repository interface for character sources.

type CharacterStats

type CharacterStats struct {
	Category       CharacterStatsCategory `json:"category"`
	IssueCountRank uint                   `json:"issue_count_rank"`
	IssueCount     uint                   `json:"issue_count"`
	Average        float64                `json:"average_issues_per_year"`
	AverageRank    uint                   `json:"average_issues_per_year_rank"`
}

CharacterStats represents ranking and issue statistic information.

func NewCharacterStats

func NewCharacterStats(c CharacterStatsCategory, rank, issueCount, avgRank uint, avg float64) CharacterStats

NewCharacterStats creates a new character stats struct.

type CharacterStatsCategory

type CharacterStatsCategory string

CharacterStatsCategory is the category types for character stats.

var (
	// AllTimeStats represents stats ALL appearances and rankings for Marvel + DC combined.
	AllTimeStats CharacterStatsCategory = "all_time"
	// MainStats represents stats for MAIN appearances only and rankings per publisher.
	MainStats CharacterStatsCategory = "main"
)

type CharacterStatsSyncer

type CharacterStatsSyncer interface {
	Sync(slug CharacterSlug) error
	SyncAll(characters []*Character) <-chan CharacterSyncResult
}

CharacterStatsSyncer is the interface for syncing characters.

type CharacterSyncLog

type CharacterSyncLog struct {
	ID          CharacterSyncLogID     `json:"id"`
	SyncType    CharacterSyncLogType   `sql:",notnull,type:smallint" json:"type"`
	SyncStatus  CharacterSyncLogStatus `sql:",notnull,type:smallint" json:"status"`
	Message     string
	SyncedAt    *time.Time  `json:"synced_at"`
	Character   *Character  // Not eager-loaded, could be nil.
	CharacterID CharacterID `pg:",fk:character_id" sql:",notnull,on_delete:CASCADE" json:"character_id"`
	CreatedAt   time.Time   `sql:",notnull,default:NOW()" json:"-"`
	UpdatedAt   time.Time   `sql:",notnull,default:NOW()" json:"-"`
	// contains filtered or unexported fields
}

CharacterSyncLog contains information pertaining to syncs for the character.

func NewSyncLog

NewSyncLog Creates a pointer to a new sync log object for the yearly appearances category.

func NewSyncLogPending

func NewSyncLogPending(
	id CharacterID,
	syncLogType CharacterSyncLogType) *CharacterSyncLog

NewSyncLogPending creates a new pending sync log struct for the specified type.

type CharacterSyncLogID

type CharacterSyncLogID uint

CharacterSyncLogID is the PK identifier for character sync logs.

func (CharacterSyncLogID) Value

func (id CharacterSyncLogID) Value() uint

Value returns the raw value.

type CharacterSyncLogRepository

type CharacterSyncLogRepository interface {
	Create(s *CharacterSyncLog) error
	FindAllByCharacterID(characterID CharacterID) ([]*CharacterSyncLog, error)
	Update(s *CharacterSyncLog) error
	FindByID(id CharacterSyncLogID) (*CharacterSyncLog, error)
	LastSyncs(id CharacterID) ([]*LastSync, error)
}

CharacterSyncLogRepository is the repository interface for character sync logs.

type CharacterSyncLogStatus

type CharacterSyncLogStatus int

CharacterSyncLogStatus is the status of the sync.

const (
	// Pending - when a sync is pending and waiting in the queue.
	Pending CharacterSyncLogStatus = iota + 1
	// InProgress - when a sync is currently in progress and tallying appearances.
	InProgress
	// Fail - when a sync failed.
	Fail
	// Success - when a sync succeeded.
	Success
)

Constants for character sync log statuses.

type CharacterSyncLogType

type CharacterSyncLogType int

CharacterSyncLogType is the type of sync that occurred for the character.

const (
	// YearlyAppearances is the syncing for yearly appearances.
	YearlyAppearances CharacterSyncLogType = iota + 1
	// Characters is the syncing for characters.
	Characters
)

Constants for character sync log types.

type CharacterSyncResult

type CharacterSyncResult struct {
	Slug  CharacterSlug
	Error error
}

CharacterSyncResult is the result set for a synced character to redis and an error if any.

type CharacterThumbRepository

type CharacterThumbRepository interface {
	AllThumbnails(slugs ...CharacterSlug) (map[CharacterSlug]*CharacterThumbnails, error)
	Thumbnails(slug CharacterSlug) (*CharacterThumbnails, error)
}

CharacterThumbRepository is the repository for getting character thumbnails.

type CharacterThumbService

type CharacterThumbService struct {
	// contains filtered or unexported fields
}

CharacterThumbService is the service for creating and uploading thumbnails for characters.

func NewCharacterThumbnailService

func NewCharacterThumbnailService(r RedisClient, tu imaging.ThumbnailUploader) *CharacterThumbService

NewCharacterThumbnailService creates a new thumbnail service.

func (*CharacterThumbService) Upload

Upload uploads thumbnails for the given character struct.

type CharacterThumbServicer

type CharacterThumbServicer interface {
	Upload(c *Character) (*CharacterThumbnails, error)
}

CharacterThumbServicer is the interface for creating and getting thumbnails for a character.

type CharacterThumbnails

type CharacterThumbnails struct {
	Slug        CharacterSlug   `json:"slug"`
	Image       *ThumbnailSizes `json:"image"`
	VendorImage *ThumbnailSizes `json:"vendor_image"`
}

CharacterThumbnails represents thumbnails for a character.

type ExpandedCharacter

type ExpandedCharacter struct {
	*Character
	Thumbnails  *CharacterThumbnails `json:"thumbnails"`
	LastSyncs   []*LastSync          `json:"last_syncs"`
	Stats       []CharacterStats     `json:"stats"`
	Appearances AppearancesByYears   `json:"appearances"`
}

ExpandedCharacter represents a character with their all-time rank as well as their rank for their main appearances per publisher and the last sync for the character.

func (*ExpandedCharacter) MarshalJSON

func (c *ExpandedCharacter) MarshalJSON() ([]byte, error)

MarshalJSON overrides the marshaling of JSON with presentation for CDN urls. TODO: Move marshaling stuff to presentation.

type ExpandedService

type ExpandedService struct {
	// contains filtered or unexported fields
}

ExpandedService gets an expanded character.

func NewExpandedService

NewExpandedService creates a new expanded service.

func NewExpandedServiceFactory

func NewExpandedServiceFactory(db ORM, r RedisClient) *ExpandedService

NewExpandedServiceFactory creates a new service for getting expanded details for a character

func (*ExpandedService) Character

func (s *ExpandedService) Character(slug CharacterSlug) (*ExpandedCharacter, error)

Character gets an expanded character.

type ExpandedServicer

type ExpandedServicer interface {
	Character(slug CharacterSlug) (*ExpandedCharacter, error)
}

ExpandedServicer is the interface for getting a character with expanded details.

type Format

type Format string

Format is the format for the issue.

const (
	FormatUnknown      Format = "unknown"
	FormatStandard     Format = "standard"
	FormatTPB          Format = "tpb"
	FormatManga        Format = "manga"
	FormatHC           Format = "hc"
	FormatOGN          Format = "ogn"
	FormatWeb          Format = "web"
	FormatAnthology    Format = "anthology"
	FormatMagazine     Format = "magazine"
	FormatDigitalMedia Format = "digital"
	FormatMiniComic    Format = "mini"
	FormatFlipbook     Format = "flipbook"
	FormatPrestige     Format = "prestige"
	FormatOther        Format = "other"
)

The format types for the issue.

type Importance

type Importance int

Importance -- for a later feature -- ranks a character issue by the character's importance in the issue.

const (
	// Cameo - they just make a cameo appearance
	Cameo Importance = iota + 1
	// Minor - meh, minor
	Minor
	// Major  character in issue
	Major
)

Consts for a later feature. The available importance types.

type Issue

type Issue struct {
	ID                 IssueID
	PublicationDate    time.Time `sql:",notnull"`
	SaleDate           time.Time `sql:",notnull"` // @TODO: add an index.
	IsVariant          bool      `sql:",notnull"`
	MonthUncertain     bool      `sql:",notnull"`
	Format             Format    `sql:",notnull"`
	VendorPublisher    string    `sql:",notnull"`
	VendorSeriesName   string    `sql:",notnull"`
	VendorSeriesNumber string    `sql:",notnull"`
	// IsReprint means the issue is a full reprint with no original story. (So something like Classic X-Men 7 would not count).
	IsReprint  bool       `sql:"default:false,notnull"`
	VendorType VendorType `sql:",notnull,unique:uix_vendor_type_vendor_id,type:smallint"`
	VendorID   string     `sql:",notnull,unique:uix_vendor_type_vendor_id"`
	CreatedAt  time.Time  `sql:",notnull,default:NOW()" json:"-"`
	UpdatedAt  time.Time  `sql:",notnull,default:NOW()" json:"-"`
	// contains filtered or unexported fields
}

Issue is an issue with details about its publication and on sale dates.

func NewIssue

func NewIssue(
	vendorID, vendorPublisher, vendorSeriesName, vendorSeriesNumber string,
	publicationDate, saleDate time.Time,
	isVariant, monthUncertain, isReprint bool,
	format Format) *Issue

NewIssue creates a new issue struct.

type IssueCountRank

type IssueCountRank uint

IssueCountRank is the ranking for the number of issues for a character.

func (IssueCountRank) Value

func (r IssueCountRank) Value() uint

Value returns the raw value.

type IssueCriteria

type IssueCriteria struct {
	Ids        []IssueID
	VendorIds  []string
	VendorType VendorType
	Formats    []Format
	Limit      int
	Offset     int
}

IssueCriteria for querying issues.

type IssueID

type IssueID uint

IssueID is the PK identifier for the issue.

func (IssueID) Value

func (id IssueID) Value() uint

Value returns the raw value

type IssueRepository

type IssueRepository interface {
	Create(issue *Issue) error
	CreateAll(issues []*Issue) error
	Update(issue *Issue) error
	FindByVendorID(vendorID string) (*Issue, error)
	FindAll(c IssueCriteria) ([]*Issue, error)
}

IssueRepository is the repository interface for issues.

type IssueService

type IssueService struct {
	// contains filtered or unexported fields
}

IssueService is the service for issues.

func NewIssueService

func NewIssueService(repository IssueRepository) *IssueService

NewIssueService creates a new service.

func NewIssueServiceFactory

func NewIssueServiceFactory(db ORM) *IssueService

NewIssueServiceFactory creates a new issue service from the repository container.

func (*IssueService) Create

func (s *IssueService) Create(i *Issue) error

Create creates an issue.

func (*IssueService) CreateP

func (s *IssueService) CreateP(vendorID, vendorPublisher, vendorSeriesName, vendorSeriesNumber string, pubDate, saleDate time.Time, isVariant, isMonthUncertain, isReprint bool, format Format) error

CreateP Creates an issue from the parameters.

func (*IssueService) Issues

func (s *IssueService) Issues(ids []IssueID, limit, offset int) ([]*Issue, error)

Issues gets all the issues by their IDs. A `limit` of `0` means no limit.

func (*IssueService) IssuesByVendor

func (s *IssueService) IssuesByVendor(ids []string, vendorType VendorType, limit, offset int) ([]*Issue, error)

IssuesByVendor gets all the issues by the vendor IDs and vendor type. A limit of `0` means no limit.

type IssueServicer

type IssueServicer interface {
	// Issues gets issues by their IDs.
	Issues(ids []IssueID, limit, offset int) ([]*Issue, error)
	// IssuesByVendor gets issues by their vendor IDs and vendor types.
	IssuesByVendor(vendorIds []string, vendorType VendorType, limit, offset int) ([]*Issue, error)
	// Creates an issue.
	Create(issue *Issue) error
	// CreateP ceates an issue from parameters.
	CreateP(
		vendorID, vendorPublisher, vendorSeriesName, vendorSeriesNumber string,
		pubDate, saleDate time.Time,
		isVariant, isMonthUncertain, isReprint bool,
		format Format) error
}

IssueServicer is the service interface for issues.

type LastSync

type LastSync struct {
	CharacterID CharacterID `json:"-"`
	SyncedAt    time.Time   `json:"synced_at"`
	NumIssues   int         `json:"num_issues"`
}

LastSync represents the last sync for a character.

type MaterializedView

type MaterializedView string

MaterializedView is the name of a table with a materialized view to cache expensive query results.

var (
	// AllView is the materialized view for all characters with both main and alternate appearances.
	AllView MaterializedView = "mv_ranked_characters"
	// MainView is the materialized view for all characters with main appearances.
	MainView MaterializedView = "mv_ranked_characters_main"
	// AltView is the materialized view for all characters with alternate appearances.
	AltView MaterializedView = "mv_ranked_characters_alternate"
	// DcMainView is the materialized view for DC characters with main appearances.
	DcMainView MaterializedView = "mv_ranked_characters_dc_main"
	// MarvelMainView is the materialized view for Marvel characters with main appearances.
	MarvelMainView MaterializedView = "mv_ranked_characters_marvel_main"
	// MarvelTrendingView is the materialized view for trending Marvel characters for main appearances only.
	MarvelTrendingView MaterializedView = "mv_trending_characters_marvel"
	// DCTrendingView is the materialized view for trending DC characters for main appearances only.
	DCTrendingView MaterializedView = "mv_trending_characters_dc"
)

func (MaterializedView) Value

func (v MaterializedView) Value() string

Value returns the string value.

type ORM

type ORM interface {
	Model(model ...interface{}) *orm.Query
	Update(model interface{}) error
	Query(model, query interface{}, params ...interface{}) (res orm.Result, err error)
	Exec(query interface{}, params ...interface{}) (res orm.Result, err error)
	Insert(model ...interface{}) error
	QueryOne(model, query interface{}, params ...interface{}) (orm.Result, error)
	RunInTransaction(fn func(tx *pg.Tx) error) error
}

ORM is the interface for interacting w/ the ORM.

type PGAppearancesByYearsRepository

type PGAppearancesByYearsRepository struct {
	// contains filtered or unexported fields
}

PGAppearancesByYearsRepository is the postgres implementation for the appearances per year repository.

func NewPGAppearancesPerYearRepository

func NewPGAppearancesPerYearRepository(db ORM) *PGAppearancesByYearsRepository

NewPGAppearancesPerYearRepository creates the new appearances by year repository for postgres.

func (*PGAppearancesByYearsRepository) List

List gets a slice of a character's main and alternate appearances. This isn't very efficient for multiple characters so you should use the Redis repo instead.

type PGCharacterIssueRepository

type PGCharacterIssueRepository struct {
	// contains filtered or unexported fields
}

PGCharacterIssueRepository is the postgres implementation for the character issue repository.

func NewPGCharacterIssueRepository

func NewPGCharacterIssueRepository(db ORM) *PGCharacterIssueRepository

NewPGCharacterIssueRepository creates the new character issue repository for the postgres implementation.

func (*PGCharacterIssueRepository) Create

Create creates a character issue.

func (*PGCharacterIssueRepository) CreateAll

func (r *PGCharacterIssueRepository) CreateAll(issues []*CharacterIssue) error

CreateAll creates the issues in the slice.

func (*PGCharacterIssueRepository) FindOneBy

func (r *PGCharacterIssueRepository) FindOneBy(characterID CharacterID, issueID IssueID) (*CharacterIssue, error)

FindOneBy finds a character issue by the params.

func (*PGCharacterIssueRepository) InsertFast

func (r *PGCharacterIssueRepository) InsertFast(issues []*CharacterIssue) error

InsertFast creates all the issues in the db ... but NOTE it does not generate the autoincremented ID's into the models of the slice. :( TODO: Find out why ORM can't do this?!?!

func (*PGCharacterIssueRepository) RemoveAllByCharacterID

func (r *PGCharacterIssueRepository) RemoveAllByCharacterID(id CharacterID) (int, error)

RemoveAllByCharacterID removes ALL character issues associated with the given character ID.

type PGCharacterRepository

type PGCharacterRepository struct {
	// contains filtered or unexported fields
}

PGCharacterRepository is the postgres implementation for the character repository.

func NewPGCharacterRepository

func NewPGCharacterRepository(db ORM) *PGCharacterRepository

NewPGCharacterRepository creates the new character repository.

func (*PGCharacterRepository) Create

func (r *PGCharacterRepository) Create(c *Character) error

Create creates a character.

func (*PGCharacterRepository) FindAll

FindAll finds characters by the criteria.

func (*PGCharacterRepository) FindBySlug

func (r *PGCharacterRepository) FindBySlug(slug CharacterSlug, includeIsDisabled bool) (*Character, error)

FindBySlug finds a character by its slug. `includeIsDisabled` means to also include disabled characters in the find.

func (*PGCharacterRepository) Remove

func (r *PGCharacterRepository) Remove(id CharacterID) error

Remove removes a character by its ID.

func (*PGCharacterRepository) Total

Total gets total number of characters based on the criteria.

func (*PGCharacterRepository) Update

func (r *PGCharacterRepository) Update(c *Character) error

Update updates a character.

func (*PGCharacterRepository) UpdateAll

func (r *PGCharacterRepository) UpdateAll(characters []*Character) error

UpdateAll updates all the characters in the slice.

type PGCharacterSourceRepository

type PGCharacterSourceRepository struct {
	// contains filtered or unexported fields
}

PGCharacterSourceRepository is the postgres implementation for the character source repository.

func NewPGCharacterSourceRepository

func NewPGCharacterSourceRepository(db ORM) *PGCharacterSourceRepository

NewPGCharacterSourceRepository creates the new character source repository for the postgres implementation.

func (*PGCharacterSourceRepository) Create

Create creates a character source.

func (*PGCharacterSourceRepository) FindAll

FindAll finds all the character sources for the criteria.

func (*PGCharacterSourceRepository) Raw

func (r *PGCharacterSourceRepository) Raw(query string, params ...interface{}) error

Raw performs a raw query on the character source. Not ideal but fine for now.

func (*PGCharacterSourceRepository) Remove

Remove removes a character source by its ID.

func (*PGCharacterSourceRepository) Update

Update updates a character source...

type PGCharacterSyncLogRepository

type PGCharacterSyncLogRepository struct {
	// contains filtered or unexported fields
}

PGCharacterSyncLogRepository is the postgres implementation for the character sync log repository.

func NewPGCharacterSyncLogRepository

func NewPGCharacterSyncLogRepository(db ORM) *PGCharacterSyncLogRepository

NewPGCharacterSyncLogRepository creates the new character sync log repository.

func (*PGCharacterSyncLogRepository) Create

Create creates a new character sync log.

func (*PGCharacterSyncLogRepository) FindAllByCharacterID

func (r *PGCharacterSyncLogRepository) FindAllByCharacterID(id CharacterID) ([]*CharacterSyncLog, error)

FindAllByCharacterID gets all the sync logs by the character ID.

func (*PGCharacterSyncLogRepository) FindByID

FindByID finds a character sync log by the id.

func (*PGCharacterSyncLogRepository) LastSyncs

func (r *PGCharacterSyncLogRepository) LastSyncs(id CharacterID) ([]*LastSync, error)

LastSyncs gets the last successful sync logs for a character.

func (*PGCharacterSyncLogRepository) Update

Update updates a sync log.

type PGIssueRepository

type PGIssueRepository struct {
	// contains filtered or unexported fields
}

PGIssueRepository is the postgres implementation for the issue repository.

func NewPGIssueRepository

func NewPGIssueRepository(db ORM) *PGIssueRepository

NewPGIssueRepository creates a new issue repository for the postgres implementation.

func (*PGIssueRepository) Create

func (r *PGIssueRepository) Create(issue *Issue) error

Create creates an issue.

func (*PGIssueRepository) CreateAll

func (r *PGIssueRepository) CreateAll(issues []*Issue) error

CreateAll creates all the issue in the slice.

func (*PGIssueRepository) FindAll

func (r *PGIssueRepository) FindAll(cr IssueCriteria) ([]*Issue, error)

FindAll finds all the issues from the criteria.

func (*PGIssueRepository) FindByVendorID

func (r *PGIssueRepository) FindByVendorID(vendorID string) (*Issue, error)

FindByVendorID finds the issues with the specified vendor IDs.

func (*PGIssueRepository) Update

func (r *PGIssueRepository) Update(issue *Issue) error

Update updates an issue.

type PGPopularRepository

type PGPopularRepository struct {
	// contains filtered or unexported fields
}

PGPopularRepository is the postgres implementation for the popular character repository.

func NewPGPopularRepository

func NewPGPopularRepository(db ORM, ctr CharacterThumbRepository) *PGPopularRepository

NewPGPopularRepository creates the new popular characters repository for postgres and the redis cache for appearances.

func NewPopularRefresher

func NewPopularRefresher(db ORM) *PGPopularRepository

NewPopularRefresher creates a new refresher for refreshing the materialized views.

func (*PGPopularRepository) All

All returns all the popular characters for DC and Marvel.

func (*PGPopularRepository) DC

DC gets the popular characters for DC characters only. The rank will be adjusted for DC.

func (*PGPopularRepository) DCTrending

func (r *PGPopularRepository) DCTrending(limit, offset int) ([]*RankedCharacter, error)

DCTrending gets the trending characters for DC.

func (*PGPopularRepository) FindOneByAll

func (r *PGPopularRepository) FindOneByAll(id CharacterID) (*RankedCharacter, error)

FindOneByAll finds a ranked character for all-time types of appearances.

func (*PGPopularRepository) FindOneByDC

func (r *PGPopularRepository) FindOneByDC(id CharacterID) (*RankedCharacter, error)

FindOneByDC finds a ranked character for DC main appearances.

func (*PGPopularRepository) FindOneByMarvel

func (r *PGPopularRepository) FindOneByMarvel(id CharacterID) (*RankedCharacter, error)

FindOneByMarvel finds a ranked character for Marvel main appearances.

func (*PGPopularRepository) Marvel

Marvel gets the popular characters for Marvel characters only. The rank will be adjusted for Marvel.

func (*PGPopularRepository) MarvelTrending

func (r *PGPopularRepository) MarvelTrending(limit, offset int) ([]*RankedCharacter, error)

MarvelTrending gets the trending characters for Marvel.

func (*PGPopularRepository) Refresh

func (r *PGPopularRepository) Refresh(view MaterializedView) error

Refresh refreshes the specified the materialized view. Note this can take several seconds!

func (*PGPopularRepository) RefreshAll

func (r *PGPopularRepository) RefreshAll() error

RefreshAll refreshes all the materialized views in a transaction. Note this can take a while, so refreshing is done concurrently for all tables!

type PGPublisherRepository

type PGPublisherRepository struct {
	// contains filtered or unexported fields
}

PGPublisherRepository is the postgres implementation for the publisher repository.

func NewPGPublisherRepository

func NewPGPublisherRepository(db ORM) *PGPublisherRepository

NewPGPublisherRepository creates a new publisher repository for the postgres implementation.

func (*PGPublisherRepository) FindBySlug

func (r *PGPublisherRepository) FindBySlug(slug PublisherSlug) (*Publisher, error)

FindBySlug gets a publisher by its slug.

type PGStatsRepository

type PGStatsRepository struct {
	// contains filtered or unexported fields
}

PGStatsRepository is the postgres implementation for the stats repository.

func NewPGStatsRepository

func NewPGStatsRepository(db ORM) *PGStatsRepository

NewPGStatsRepository creates a new stats repository for the postgres implementation.

func (*PGStatsRepository) Stats

func (r *PGStatsRepository) Stats() (Stats, error)

Stats gets stats for the comic repository.

type PopularCriteria

type PopularCriteria struct {
	AppearanceType AppearanceType
	SortBy         PopularSortCriteria
	Limit          int
	Offset         int
}

PopularCriteria is for querying ranked and popular characters.

type PopularRefresher

type PopularRefresher interface {
	Refresh(view MaterializedView) error
	RefreshAll() error
}

PopularRefresher concurrently refreshes the materialized views.

type PopularRepository

type PopularRepository interface {
	All(cr PopularCriteria) ([]*RankedCharacter, error)
	DC(cr PopularCriteria) ([]*RankedCharacter, error)
	Marvel(cr PopularCriteria) ([]*RankedCharacter, error)
	FindOneByDC(id CharacterID) (*RankedCharacter, error)
	FindOneByMarvel(id CharacterID) (*RankedCharacter, error)
	FindOneByAll(id CharacterID) (*RankedCharacter, error)
	MarvelTrending(limit, offset int) ([]*RankedCharacter, error)
	DCTrending(limit, offset int) ([]*RankedCharacter, error)
}

PopularRepository is the repository interface for popular character rankings.

type PopularSortCriteria

type PopularSortCriteria string

PopularSortCriteria is criteria for sorting popular characters.

const (
	// MostIssues sorts by the most issues for a character.
	MostIssues PopularSortCriteria = "issue_count_rank"
	// AverageIssuesPerYear sorts by the highest average issues per year for each character.
	AverageIssuesPerYear = "average_per_year_rank"
)

type Publisher

type Publisher struct {
	ID        PublisherID   `json:"-"`
	Name      string        `json:"name" sql:",notnull"`
	Slug      PublisherSlug `json:"slug" sql:",notnull,unique:uix_publisher_slug"`
	CreatedAt time.Time     `json:"-" sql:",notnull,default:NOW()"`
	UpdatedAt time.Time     `sql:",notnull,default:NOW()" json:"-"`
	// contains filtered or unexported fields
}

Publisher is a publisher is an entity that publishes comics and characters.

type PublisherID

type PublisherID uint

PublisherID is the PK identifier for the publisher.

type PublisherRepository

type PublisherRepository interface {
	FindBySlug(slug PublisherSlug) (*Publisher, error)
}

PublisherRepository is the repository interface for publishers.

type PublisherService

type PublisherService struct {
	// contains filtered or unexported fields
}

PublisherService is the service for publishers.

func NewPublisherService

func NewPublisherService(repository PublisherRepository) *PublisherService

NewPublisherService creates a new publisher service.

func NewPublisherServiceFactory

func NewPublisherServiceFactory(db ORM) *PublisherService

NewPublisherServiceFactory creates a new publisher service

func (*PublisherService) Publisher

func (s *PublisherService) Publisher(slug PublisherSlug) (*Publisher, error)

Publisher gets a publisher by its slug.

type PublisherServicer

type PublisherServicer interface {
	// Publisher gets a publisher by its slug.
	Publisher(slug PublisherSlug) (*Publisher, error)
}

PublisherServicer is the service interface for publishers.

type PublisherSlug

type PublisherSlug string

PublisherSlug is the unique string identifier for the publisher.

func (PublisherSlug) Value

func (slug PublisherSlug) Value() string

Value returns the raw value.

type RankedCharacter

type RankedCharacter struct {
	ID                CharacterID          `json:"-"`
	Publisher         Publisher            `json:"publisher"`
	PublisherID       PublisherID          `json:"-"`
	Name              string               `json:"name"`
	OtherName         string               `json:"other_name"`
	Description       string               `json:"description"`
	Image             string               `json:"image"`
	Slug              CharacterSlug        `json:"slug"`
	VendorImage       string               `json:"vendor_image"`
	VendorURL         string               `json:"vendor_url"`
	VendorDescription string               `json:"vendor_description"`
	Thumbnails        *CharacterThumbnails `json:"thumbnails"`
	Stats             CharacterStats       `json:"stats"`
}

RankedCharacter represents a character who has its rank and issue count accounted for with its appearances attached..

func (*RankedCharacter) MarshalJSON

func (c *RankedCharacter) MarshalJSON() ([]byte, error)

MarshalJSON overrides the image and vendor image for the CDN url. TODO: Move marshaling stuff to presentation.

type RankedService

type RankedService struct {
	// contains filtered or unexported fields
}

RankedService is the service for getting ranked and popular characters.

func NewRankedService

func NewRankedService(p PopularRepository) *RankedService

NewRankedService creates a new service.

func NewRankedServiceFactory

func NewRankedServiceFactory(db ORM, r RedisClient) *RankedService

NewRankedServiceFactory creates a new service for ranked characters.

func (*RankedService) AllPopular

func (s *RankedService) AllPopular(cr PopularCriteria) ([]*RankedCharacter, error)

AllPopular gets the most popular characters per year ordered by either issue count or average appearances per year.

func (*RankedService) DCPopular

func (s *RankedService) DCPopular(cr PopularCriteria) ([]*RankedCharacter, error)

DCPopular gets DC's most popular characters per year.

func (*RankedService) DCTrending

func (s *RankedService) DCTrending(limit, offset int) ([]*RankedCharacter, error)

DCTrending gets the trending characters for marvel.

func (*RankedService) MarvelPopular

func (s *RankedService) MarvelPopular(cr PopularCriteria) ([]*RankedCharacter, error)

MarvelPopular gets Marvel's most popular characters per year ordered by either issue count o or average appearances per year.

func (*RankedService) MarvelTrending

func (s *RankedService) MarvelTrending(limit, offset int) ([]*RankedCharacter, error)

MarvelTrending gets the trending characters for marvel.

type RankedServicer

type RankedServicer interface {
	AllPopular(cr PopularCriteria) ([]*RankedCharacter, error)
	DCPopular(cr PopularCriteria) ([]*RankedCharacter, error)
	MarvelPopular(cr PopularCriteria) ([]*RankedCharacter, error)
	MarvelTrending(limit, offset int) ([]*RankedCharacter, error)
	DCTrending(limit, offset int) ([]*RankedCharacter, error)
}

RankedServicer is the interface for getting ranked and popular characters.

type RedisAppearancesByYearsRepository

type RedisAppearancesByYearsRepository struct {
	// contains filtered or unexported fields
}

RedisAppearancesByYearsRepository is the Redis implementation for appearances per year repository.

func NewRedisAppearancesPerYearRepository

func NewRedisAppearancesPerYearRepository(client RedisClient) *RedisAppearancesByYearsRepository

NewRedisAppearancesPerYearRepository creates the redis yearly appearances repository.

func (*RedisAppearancesByYearsRepository) Delete

Delete deletes all the appearances per years for the given slug.

func (*RedisAppearancesByYearsRepository) List

List returns a slice of appearances per year for the given characters' slugs main and alternate appearances.

func (*RedisAppearancesByYearsRepository) ListMap

ListMap returns a map of appearances per year for the given characters' slugs main and alternate appearances.

func (*RedisAppearancesByYearsRepository) Set

Set sets the character's appearances in Redis.

type RedisCharacterStatsSyncer

type RedisCharacterStatsSyncer struct {
	// contains filtered or unexported fields
}

RedisCharacterStatsSyncer is for syncing characters to redis.

func NewCharacterStatsSyncer

NewCharacterStatsSyncer returns a new character stats syncer with dependencies.

func (*RedisCharacterStatsSyncer) Sync

Sync syncs the character's ranking stats to Redis.

func (*RedisCharacterStatsSyncer) SyncAll

func (s *RedisCharacterStatsSyncer) SyncAll(characters []*Character) <-chan CharacterSyncResult

SyncAll syncs multiple characters to redis in goroutines.

type RedisCharacterThumbRepository

type RedisCharacterThumbRepository struct {
	// contains filtered or unexported fields
}

RedisCharacterThumbRepository is for a redis repository for getting character thumbnails.

func NewRedisCharacterThumbRepository

func NewRedisCharacterThumbRepository(r RedisClient) *RedisCharacterThumbRepository

NewRedisCharacterThumbRepository creates a new redis character thumb repository.

func (*RedisCharacterThumbRepository) AllThumbnails

AllThumbnails efficiently gets the thumbnails for many characters.

func (*RedisCharacterThumbRepository) Thumbnails

Thumbnails gets the thumbnails for a character.

type RedisClient

type RedisClient interface {
	Get(key string) *redis.StringCmd
	MGet(keys ...string) *redis.SliceCmd
	Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	HMSet(key string, fields map[string]interface{}) *redis.StatusCmd
	HGetAll(key string) *redis.StringStringMapCmd
	Del(keys ...string) *redis.IntCmd
}

RedisClient is the interface for interacting with Redis.

type RedisHmSetter

type RedisHmSetter interface {
	HMSet(key string, fields map[string]interface{}) *redis.StatusCmd
}

RedisHmSetter is a redis client for setting hash-sets.

type RedisYearlyAggregateDeserializer

type RedisYearlyAggregateDeserializer struct {
}

RedisYearlyAggregateDeserializer deserializes a Redis string into a struct.

func (*RedisYearlyAggregateDeserializer) Deserialize

Deserialize deserializes the string into the yearly aggregates structs.

type RedisYearlyAggregateSerializer

type RedisYearlyAggregateSerializer struct {
}

RedisYearlyAggregateSerializer serializes a struct into a string for Redis storage.

func (*RedisYearlyAggregateSerializer) Serialize

func (s *RedisYearlyAggregateSerializer) Serialize(aggregates []YearlyAggregate) string

Serialize serializes the structs into a string for Redis storage.

type Stats

type Stats struct {
	TotalCharacters  int `json:"total_characters"`
	TotalAppearances int `json:"total_appearances"`
	MinYear          int `json:"min_year"`
	MaxYear          int `json:"max_year"`
	TotalIssues      int `json:"total_issues"`
}

Stats represents general stats about the db.

type StatsRepository

type StatsRepository interface {
	Stats() (Stats, error)
}

StatsRepository is the repository interface for general stats about the db.

type Syncer

type Syncer interface {
	// Syncs appearances from postgres to redis. Returns the number of issues synced and an error if any.
	Sync(slug CharacterSlug) (int, error)
}

Syncer is the interface for syncing yearly appearances from persistence to a cache.

type ThumbnailSizes

type ThumbnailSizes struct {
	Small  string `json:"small"`
	Medium string `json:"medium"`
	Large  string `json:"large"`
}

ThumbnailSizes represents the sizes of thumbnails.

type Transactional

type Transactional interface {
	RunInTransaction(fn func(tx *pg.Tx) error) error
}

Transactional is an interface for running in a transaction.

type TrendingCriteria

type TrendingCriteria struct {
	PublisherID PublisherID
	Limit       int
	Offset      int
}

TrendingCriteria is for querying characters who are trending.

type VendorType

type VendorType int

VendorType is type of vendor from an external source for an issue.

const (
	VendorTypeCb VendorType = iota
	VendorTypeMarvel
	VendorTypeDC
)

Vendor types for the characters and character sources.

type YearlyAggregate

type YearlyAggregate struct {
	Main      int `json:"main"`
	Alternate int `json:"alternate"`
	Year      int `json:"year"`
}

YearlyAggregate is the aggregated year and count of an appearance for that year.

type YearlyAggregateDeserializer

type YearlyAggregateDeserializer interface {
	Deserialize(val string) []YearlyAggregate
}

YearlyAggregateDeserializer deserializes a string into a struct.

type YearlyAggregateSerializer

type YearlyAggregateSerializer interface {
	Serialize(aggregates []YearlyAggregate) string
}

YearlyAggregateSerializer serializes a struct into a string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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