humandao

package
v0.0.0-...-5c9f048 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHumanNotFound      = errors.New("human not found")
	ErrHumanAlreadyExists = errors.New("human already exists")
	ErrInvalidOrderBy     = errors.New("orderBy must be one of: created_at, views")
	ErrInvalidGender      = errors.New("invalid gender")
)
View Source
var ErrUnauthorized = errors.New("user is not authorized to perform this operation")
View Source
var ValidGenders = map[Gender]struct{}{
	GenderMale:      {},
	GenderFemale:    {},
	GenderNonBinary: {},
}

Functions

This section is empty.

Types

type AddHumanInput

type AddHumanInput struct {
	HumanID     string
	Name        string
	DOB         string
	DOD         string
	Ethnicity   []string
	Description string
	Location    []string
	Website     string
	Twitter     string
	Instagram   string
	IMDB        string
	Tags        []string
	Draft       bool
	CreatedBy   string
	Affiliates  []Affiliate
	Gender      Gender
}

type Affiliate

type Affiliate struct {
	ID    string `firestore:"id,omitempty"`
	URL   string `firestore:"url,omitempty"`
	Image string `firestore:"image,omitempty"`
	Name  string `firestore:"name,omitempty"`
}

type CreatedByInput

type CreatedByInput struct {
	CreatedBy string
	Limit     int
	Offset    int
}

type DAO

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

func NewDAO

func NewDAO(client *firestore.Client, options ...Option) *DAO

func (*DAO) AddHuman

func (d *DAO) AddHuman(ctx context.Context, input AddHumanInput) (Human, error)

func (*DAO) CreatedBy

func (d *DAO) CreatedBy(ctx context.Context, input CreatedByInput) ([]Human, error)

func (*DAO) Delete

func (d *DAO) Delete(ctx context.Context, input DeleteInput) error

func (*DAO) Drafts

func (d *DAO) Drafts(ctx context.Context, input DraftsInput) ([]Human, error)

func (*DAO) GetReactions

func (d *DAO) GetReactions(ctx context.Context, input GetReactionsInput) ([]Reaction, error)

func (*DAO) Human

func (d *DAO) Human(ctx context.Context, input HumanInput) (human Human, err error)

func (*DAO) HumansByID

func (d *DAO) HumansByID(ctx context.Context, input HumansByIDInput) ([]Human, error)

func (*DAO) ListHumans

func (d *DAO) ListHumans(ctx context.Context, input ListHumansInput) ([]Human, error)

func (*DAO) Publish

func (d *DAO) Publish(ctx context.Context, input PublishInput) error

func (*DAO) React

func (d *DAO) React(ctx context.Context, input ReactInput) (Reaction, error)

func (*DAO) ReactUndo

func (d *DAO) ReactUndo(ctx context.Context, input ReactUndoInput) error

func (*DAO) UpdateHuman

func (d *DAO) UpdateHuman(ctx context.Context, human Human) error

func (*DAO) UserDrafts

func (d *DAO) UserDrafts(ctx context.Context, input UserDraftsInput) ([]Human, error)

func (*DAO) View

func (d *DAO) View(ctx context.Context, input ViewInput) error

type DeleteInput

type DeleteInput struct {
	HumanID string
}

type DraftsInput

type DraftsInput struct {
	Limit  int
	Offset int
}

type FilterOpt

type FilterOpt func(f Filterable) Filterable

func ByAgeOlderThan

func ByAgeOlderThan(age time.Time) FilterOpt

func ByAgeYoungerThan

func ByAgeYoungerThan(age time.Time) FilterOpt

func ByEthnicity

func ByEthnicity(ethnicity string) FilterOpt

func ByGender

func ByGender(gender Gender) FilterOpt

ByGender is a FilterOpts implementation to filter by gender

func ByIDs

func ByIDs(ids ...string) FilterOpt

func ByTags

func ByTags(tags ...string) FilterOpt

type Filterable

type Filterable []Human

func ApplyFilters

func ApplyFilters(f Filterable, opts ...FilterOpt) Filterable

type Gender

type Gender string
const (
	GenderMale      Gender = "male"
	GenderFemale    Gender = "female"
	GenderNonBinary Gender = "nonbinary"
)

type GetReactionsInput

type GetReactionsInput struct {
	UserID string
}

type Human

type Human struct {
	ID            string        `firestore:"-"`
	Name          string        `firestore:"name"`
	Path          string        `firestore:"urn_path"`
	ReactionCount ReactionCount `firestore:"reaction_count"`
	DOB           string        `firestore:"dob,omitempty"`
	DOD           string        `firestore:"dod,omitempty"`
	Tags          []string      `firestore:"tags,omitempty"`
	Ethnicity     []string      `firestore:"ethnicity,omitempty"`
	BirthLocation string        `firestore:"birth_location,omitempty"`
	Location      []string      `firestore:"location,omitempty"`
	InfluencedBy  []string      `firestore:"influenced_by,omitempty"`
	FeaturedImage string        `firestore:"featured_image,omitempty"`
	Draft         bool          `firestore:"draft"`
	AIGenerated   bool          `firestore:"ai_generated,omitempty"`
	Description   string        `firestore:"description,omitempty"`

	CreatedAt time.Time `firestore:"created_at"`
	CreatedBy string    `firestore:"created_by,omitempty"`

	UpdatedAt   time.Time   `firestore:"updated_at"`
	PublishedBy string      `firestore:"published_by,omitempty"`
	PublishedAt time.Time   `firestore:"published_at,omitempty"`
	Affiliates  []Affiliate `firestore:"affiliates,omitempty"`
	Socials     Socials     `firestore:"socials,omitempty"`
	Views       int64       `firestore:"views,omitempty"`
	Gender      Gender      `firestore:"gender,omitempty"`
}

func (Human) CurrentAge

func (h Human) CurrentAge(inputTime ...time.Time) (string, error)

type HumanInput

type HumanInput struct {
	HumanID string
	Path    string
}

type HumansByIDInput

type HumansByIDInput struct {
	HumanIDs []string
}

type ListHumansInput

type ListHumansInput struct {
	Limit         int
	Offset        int
	OrderBy       OrderBy
	Direction     firestore.Direction
	IncludeDrafts bool
}

type Option

type Option func(d *DAO)

func WithHumanCollectionName

func WithHumanCollectionName(name string) Option

func WithReactionCollectionName

func WithReactionCollectionName(name string) Option

type OrderBy

type OrderBy string
var (
	OrderByCreatedAt OrderBy = "created_at"
	OrderByViews     OrderBy = "views"
)

type PublishInput

type PublishInput struct {
	HumanID string
	UserID  string
}

type ReactInput

type ReactInput struct {
	UserID       string
	HumanID      string
	ReactionKind ReactionKind
}

type ReactUndoInput

type ReactUndoInput struct {
	UserID     string
	ReactionID string
}

type Reaction

type Reaction struct {
	ID           string       `firestore:"-"`
	UserID       string       `firestore:"user_id,omitempty"`
	HumanID      string       `firestore:"human_id,omitempty"`
	ReactionKind ReactionKind `firestore:"reaction_kind,omitempty"`
	CreatedAt    time.Time    `firestore:"created_at,omitempty"`
}

type ReactionCount

type ReactionCount map[string]int

type ReactionKind

type ReactionKind string
var (
	ReactionKindLove   ReactionKind = "love"
	ReactionKindFire   ReactionKind = "fire"
	ReactionKindJoy    ReactionKind = "joy"
	ReactionKindFlower ReactionKind = "flower"
)

func ToReactionKind

func ToReactionKind(kind string) (ReactionKind, error)

type Socials

type Socials struct {
	IMDB      string `firestore:"imdb,omitempty"`
	Website   string `firestore:"website,omitempty"`
	X         string `firestore:"x,omitempty"`
	YouTube   string `firestore:"youtube,omitempty"`
	Instagram string `firestore:"instagram,omitempty"`
}

type UserDraftsInput

type UserDraftsInput struct {
	Limit  int
	Offset int
	UserID string
}

type ViewInput

type ViewInput struct {
	HumanID string
}

Jump to

Keyboard shortcuts

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