cards

package
v0.0.0-...-0fb68f2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLang = "eng"

Variables

View Source
var ErrCardNotFound = errors.New("card not found")
View Source
var ErrInvalidID = errors.New("invalid id")
View Source
var (
	ErrMatchNotFound = errors.New("no match found")
)

Functions

func GetPage

func GetPage[T any](data []T, page Page) []T

func TimeTracker

func TimeTracker(start time.Time, name string)

Types

type Card

type Card struct {
	// Set the set that the card belongs to
	Set Set
	// Name is the name of the card.
	Name string
	// Image the card image metadata
	Image Image
	// ID is the identifier of the card.
	ID ID
	// Amount show how often the card is in the users collection.
	Amount int
}

type CardRepository

type CardRepository interface {
	// Find returns the cards for the requested page matching the given criteria.
	Find(ctx context.Context, filter Filter, page Page) (Cards, error)
}

type CardService

type CardService interface {
	Search(ctx context.Context, name string, collector Collector, page Page) (Cards, error)
}

func NewCardService

func NewCardService(repo CardRepository) CardService

type Cards

type Cards struct {
	PagedResult[Card]
}

func EmptyCards

func EmptyCards(p Page) Cards

func NewCards

func NewCards(cards []Card, p Page) Cards

type Collectable

type Collectable struct {
	ID     ID
	Amount int
}

Collectable a collectable item.

func NewCollectable

func NewCollectable(id int, amount int) (Collectable, error)

type CollectionRepository

type CollectionRepository interface {
	// Find returns the cards for the requested page matching the given criteria.
	Find(ctx context.Context, filter Filter, page Page) (Cards, error)
	// Exist returns true if a card with the given ID exist, false otherwise.
	Exist(ctx context.Context, id ID) (bool, error)
	// Collect adds or removes an card from a collection.
	Collect(ctx context.Context, item Collectable, c Collector) error
	// Remove removes the item from the collection.
	Remove(ctx context.Context, item Collectable, c Collector) error
}

type CollectionService

type CollectionService interface {
	Search(ctx context.Context, name string, c Collector, p Page) (Cards, error)
	Collect(ctx context.Context, item Collectable, c Collector) (Collectable, error)
}

func NewCollectionService

func NewCollectionService(cRepo CollectionRepository) CollectionService

type Collector

type Collector struct {
	ID string
}

Collector user who interacts with his collection.

func NewCollector

func NewCollector(id string) Collector

type DetectRepository

type DetectRepository interface {
	Top5MatchesByHash(ctx context.Context, hashes ...image.Hash) (Scores, error)
}

type DetectService

type DetectService interface {
	Detect(ctx context.Context, collector Collector, in io.Reader) (Matches, error)
}

func NewDetectService

func NewDetectService(cRepo CardRepository, dRepo DetectRepository, detector image.Detector,
	hasher image.Hasher) DetectService

type Filter

type Filter struct {
	Collector     *Collector
	Name          string
	Lang          string
	IDs           IDs
	OnlyCollected bool
}

func NewFilter

func NewFilter() Filter

func (Filter) WithCollector

func (f Filter) WithCollector(c Collector) Filter

func (Filter) WithID

func (f Filter) WithID(id ...ID) Filter

func (Filter) WithLanguage

func (f Filter) WithLanguage(lang string) Filter

func (Filter) WithName

func (f Filter) WithName(name string) Filter

func (Filter) WithOnlyCollected

func (f Filter) WithOnlyCollected() Filter

type ID

type ID struct {
	// CardID the card ID
	CardID int
	// FaceID the face ID
	FaceID int
}

func NewID

func NewID(id int) ID

func (ID) Eq

func (id ID) Eq(o ID) bool

func (ID) String

func (id ID) String() string

func (ID) WithFace

func (id ID) WithFace(faceID int) ID

type IDs

type IDs []ID

func (IDs) Find

func (ids IDs) Find(oID ID) *ID

func (IDs) NotEmpty

func (ids IDs) NotEmpty() bool

type Image

type Image struct {
	// URL the image URL
	URL string
}

type Match

type Match struct {
	Card
	Confidence int
}

type Matches

type Matches struct {
	PagedResult[Match]
}

func EmptyMatches

func EmptyMatches(p Page) Matches

func NewMatches

func NewMatches(cards Cards, scores Scores, page Page) Matches

type Page

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

func DefaultPage

func DefaultPage() Page

func NewPage

func NewPage(page, size int) Page

func (Page) Offset

func (p Page) Offset() int

func (Page) Page

func (p Page) Page() int

func (Page) Size

func (p Page) Size() int

type PagedResult

type PagedResult[T any] struct {
	Result  []T
	HasMore bool
	Page    int
}

func NewEmptyResult

func NewEmptyResult[T any](page Page) PagedResult[T]

func NewPagedResult

func NewPagedResult[T any](data []T, page Page) PagedResult[T]

type Score

type Score struct {
	ID    ID
	Score int
}

type Scores

type Scores []Score

func (Scores) Find

func (s Scores) Find(oID ID) *Score

type Set

type Set struct {
	// Name is the set name.
	Name string
	// Code is the set identifier.
	Code string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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