store

package
v0.0.0-...-1120f02 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrArtworkNotFound = errors.New("artwork not found")
)

Functions

This section is empty.

Types

type Artwork

type Artwork struct {
	ID        int       `json:"id" bson:"artwork_id"`
	Title     string    `json:"title" bson:"title"`
	Author    string    `json:"author" bson:"author"`
	URL       string    `json:"url" bson:"url"`
	Images    []string  `json:"images" bson:"images"`
	Favorites int       `json:"favourites" bson:"favourites"`
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
	UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}

type ArtworkFilter

type ArtworkFilter struct {
	IDs    []int  `query:"id"`
	Title  string `query:"title"`
	Author string `query:"author"`
	Query  string `query:"query"`
	URL    string `query:"url"`
	Time   time.Duration
}

type ArtworkSearchOptions

type ArtworkSearchOptions struct {
	Limit int64
	Skip  int64
	Order Order
	Sort  ArtworkSort
}

func DefaultSearchOptions

func DefaultSearchOptions() ArtworkSearchOptions

type ArtworkSort

type ArtworkSort int
const (
	ByTime ArtworkSort = iota
	ByPopularity
)

func (ArtworkSort) String

func (s ArtworkSort) String() string

type ArtworkStore

type ArtworkStore interface {
	Artwork(ctx context.Context, id int, url string) (*Artwork, error)
	CreateArtwork(context.Context, *Artwork) (*Artwork, error)
	SearchArtworks(context.Context, ArtworkFilter, ...ArtworkSearchOptions) ([]*Artwork, error)
}

type Bookmark

type Bookmark struct {
	UserID    string    `json:"user_id,omitempty" bson:"user_id"`
	ArtworkID int       `json:"artwork_id,omitempty" bson:"artwork_id"`
	NSFW      bool      `json:"nsfw,omitempty" bson:"nsfw"`
	CreatedAt time.Time `json:"created_at,omitempty" bson:"created_at"`
}

type BookmarkFilter

type BookmarkFilter int
const (
	BookmarkFilterAll BookmarkFilter = iota
	BookmarkFilterSafe
	BookmarkFilterUnsafe
)

type BookmarkStore

type BookmarkStore interface {
	ListBookmarks(ctx context.Context, userID string, filter BookmarkFilter, order Order) ([]*Bookmark, error)
	CountBookmarks(ctx context.Context, userID string) (int64, error)
	AddBookmark(ctx context.Context, fav *Bookmark) (bool, error)
	DeleteBookmark(ctx context.Context, fav *Bookmark) (bool, error)
}

type Group

type Group struct {
	Name     string   `json:"name" bson:"name"`
	Parent   string   `json:"parent" bson:"parent"`
	Children []string `json:"children" bson:"children"`
	IsPair   bool     `json:"is_pair" bson:"is_pair"`
}

type Guild

type Guild struct {
	ID     string `json:"id" bson:"guild_id" validate:"required"`
	Prefix string `json:"prefix" bson:"prefix" validate:"required,max=5"`

	Pixiv      bool `json:"pixiv" bson:"pixiv"`
	Twitter    bool `json:"twitter" bson:"twitter"`
	Deviant    bool `json:"deviant" bson:"deviant"`
	Artstation bool `json:"artstation" bson:"artstation"`

	Tags       bool `json:"tags" bson:"tags"`
	FlavorText bool `json:"flavour_text" bson:"flavour_text"`
	Crosspost  bool `json:"crosspost" bson:"crosspost"`
	Reactions  bool `json:"reactions" bson:"reactions"`
	SkipFirst  bool `json:"skip_first" bson:"skip_first"`
	Limit      int  `json:"limit" bson:"limit" validate:"required"`

	Repost           GuildRepost   `json:"repost" bson:"repost" validate:"required"`
	RepostExpiration time.Duration `json:"repost_expiration" bson:"repost_expiration"`

	ArtChannels []string `json:"art_channels" bson:"art_channels" validate:"required"`
	NSFW        bool     `json:"nsfw" bson:"nsfw"`

	CreatedAt time.Time `json:"created_at" bson:"created_at" validate:"required"`
	UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}

func DefaultGuild

func DefaultGuild(id string) *Guild

func UserGuild

func UserGuild() *Guild

type GuildRepost

type GuildRepost string
const (
	GuildRepostEnabled  GuildRepost = "enabled"
	GuildRepostDisabled GuildRepost = "disabled"
	GuildRepostStrict   GuildRepost = "strict"
)

type GuildStore

type GuildStore interface {
	Guild(ctx context.Context, guildID string) (*Guild, error)
	CreateGuild(ctx context.Context, guildID string) (*Guild, error)
	UpdateGuild(ctx context.Context, guild *Guild) (*Guild, error)
	AddArtChannels(ctx context.Context, guildID string, channels []string) (*Guild, error)
	DeleteArtChannels(ctx context.Context, guildID string, channels []string) (*Guild, error)
}

type Order

type Order int
const (
	Descending Order = iota - 1

	Ascending
)

type StatefulStore

type StatefulStore struct {
	Store
	// contains filtered or unexported fields
}

func (*StatefulStore) AddArtChannels

func (s *StatefulStore) AddArtChannels(ctx context.Context, guildID string, channels []string) (*Guild, error)

func (*StatefulStore) Artwork

func (s *StatefulStore) Artwork(ctx context.Context, id int, url string) (*Artwork, error)

func (*StatefulStore) CreateArtwork

func (s *StatefulStore) CreateArtwork(ctx context.Context, a *Artwork) (*Artwork, error)

func (*StatefulStore) CreateGuild

func (s *StatefulStore) CreateGuild(ctx context.Context, guildID string) (*Guild, error)

func (*StatefulStore) DeleteArtChannels

func (s *StatefulStore) DeleteArtChannels(ctx context.Context, guildID string, channels []string) (*Guild, error)

func (*StatefulStore) Guild

func (s *StatefulStore) Guild(ctx context.Context, guildID string) (*Guild, error)

func (*StatefulStore) SearchArtworks

func (s *StatefulStore) SearchArtworks(ctx context.Context, filter ArtworkFilter, opts ...ArtworkSearchOptions) ([]*Artwork, error)

func (*StatefulStore) UpdateGuild

func (s *StatefulStore) UpdateGuild(ctx context.Context, guild *Guild) (*Guild, error)

type Store

func NewStatefulStore

func NewStatefulStore(store Store, c *cache.Cache) Store

type User

type User struct {
	ID        string    `json:"id" bson:"user_id"`
	DM        bool      `json:"dm" bson:"dm"`
	Crosspost bool      `json:"crosspost" bson:"crosspost"`
	Ignore    bool      `json:"ignore" bson:"ignore"`
	Groups    []*Group  `json:"groups" bson:"channel_groups"`
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
	UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}

func DefaultUser

func DefaultUser(id string) *User

func (*User) FindGroup

func (u *User) FindGroup(channelID string) (*Group, bool)

func (*User) FindGroupByName

func (u *User) FindGroupByName(name string) (*Group, bool)

type UserStore

type UserStore interface {
	CreateUser(ctx context.Context, userID string) (*User, error)
	UpdateUser(ctx context.Context, user *User) (*User, error)
	User(ctx context.Context, userID string) (*User, error)

	CreateCrosspostGroup(ctx context.Context, userID string, group *Group) (*User, error)
	CreateCrosspostPair(ctx context.Context, userID string, pair *Group) (*User, error)
	DeleteCrosspostGroup(ctx context.Context, userID string, group string) (*User, error)
	RenameCrosspostGroup(ctx context.Context, userID string, name string, newName string) (*User, error)
	AddCrosspostChannel(ctx context.Context, userID string, group string, child string) (*User, error)
	DeleteCrosspostChannel(ctx context.Context, userID string, group string, child string) (*User, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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