votes

package
v0.0.0-...-b84af7b Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	UP voteDir = iota
	DOWN
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps interface {
	LedisDB() *ledis.DB
	Mgo() *mgo.Database
}

type List

type List []Vote

List aggregates a list of votes for certain event.

func FindList

func FindList(deps Deps, scopes ...common.Scope) (list List, err error)

FindList of votes for given scopes.

func (List) ValuesMap

func (ls List) ValuesMap() map[string][]string

ValuesMap is a map of votes with values.

type NotAllowed

type NotAllowed struct {
	Reason string
}

NotAllowed check.

func (*NotAllowed) Error

func (e *NotAllowed) Error() string

type Votable

type Votable interface {
	VotableType() string
	VotableID() bson.ObjectId
}

type Vote

type Vote struct {
	ID         bson.ObjectId `bson:"_id,omitempty" json:"id,omitempty"`
	UserID     bson.ObjectId `bson:"user_id" json:"user_id"`
	Type       string        `bson:"type" json:"type"`
	NestedType string        `bson:"nested_type,omitempty" json:"nested_type,omitempty"`
	RelatedID  bson.ObjectId `bson:"related_id" json:"related_id"`
	Value      string        `bson:"value" json:"value"`
	Created    time.Time     `bson:"created_at" json:"created_at"`
	Deleted    *time.Time    `bson:"deleted_at,omitempty" json:"-"`
}

Vote represents a reaction to a post || comment

func FindVotableByUser

func FindVotableByUser(deps Deps, votable Votable, userID bson.ObjectId) (vote Vote, err error)

FindVotableByUser gets the votes for ref.

func UpsertVote

func UpsertVote(deps Deps, item Votable, userID bson.ObjectId, kind string) (vote Vote, status voteStatus, err error)

UpsertVote creates or removes a vote for given votable item<->user

func (Vote) DbField

func (v Vote) DbField() string

func (Vote) Remove

func (v Vote) Remove(deps Deps) error

type VoteType

type VoteType string

VoteType should be an integer in the form of up or down.

type Votes

type Votes map[string]int

Votes represents the aggregated count of votes

Jump to

Keyboard shortcuts

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