storage

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package storage contains a storage interface.

Index

Constants

View Source
const PDVDenominator = 1000000

PDVDenominator is used to guarantee precision for storing pdv with int64.

Variables

View Source
var ErrNotFound = fmt.Errorf("not found")

ErrNotFound ...

Functions

This section is empty.

Types

type CreatePostParams

type CreatePostParams struct {
	UUID         string
	Owner        string
	Title        string
	Category     community.Category
	PreviewImage string
	Text         string
	CreatedAt    time.Time
}

CreatePostParams ...

type DecentrStats added in v0.0.14

type DecentrStats struct {
	ADV float64 // Average earned pdv
	DDV int64   // Whole earned pdv
}

DecentrStats represents all users stats.

type ListPostsParams

type ListPostsParams struct {
	SortBy     SortType
	OrderBy    OrderType
	Limit      uint16
	Category   *community.Category
	Owner      *string
	LikedBy    *string
	FollowedBy *string
	After      *PostID
	From       *uint64
	To         *uint64
}

ListPostsParams ...

type OrderType

type OrderType string

OrderType ...

const (
	// AscendingOrder ...
	AscendingOrder OrderType = "asc"
	// DescendingOrder ...
	DescendingOrder = "desc"
)

type Post

type Post struct {
	UUID         string
	Owner        string
	Title        string
	Category     community.Category
	PreviewImage string
	Text         string
	CreatedAt    time.Time
	Likes        uint32
	Dislikes     uint32
	UPDV         int64
	Slug         string
}

Post ...

type PostID

type PostID struct {
	Owner string
	UUID  string
}

PostID ...

type ProfileStats added in v1.0.0

type ProfileStats struct {
	Address    string
	PostsCount uint16
	Stats      Stats
}

ProfileStats ...

type SortType

type SortType string

SortType ...

const (
	// CreatedAtSortType ...
	CreatedAtSortType SortType = "created_at"
	// LikesSortType ...
	LikesSortType SortType = "likes"
	// DislikesSortType ...
	DislikesSortType SortType = "dislikes"
	// PDVSortType ...
	PDVSortType SortType = "updv"
)

type Stats

type Stats map[string]int64

Stats is map where key is date in RFC3339 format and value is uPDV count.

type Storage

type Storage interface {
	InTx(ctx context.Context, f func(s Storage) error) error
	SetHeight(ctx context.Context, height uint64) error
	GetHeight(ctx context.Context) (uint64, error)
	RefreshViews(ctx context.Context) error

	Follow(ctx context.Context, follower, followee string) error
	Unfollow(ctx context.Context, follower, followee string) error

	ListPosts(ctx context.Context, p *ListPostsParams) ([]*Post, error)
	CreatePost(ctx context.Context, p *CreatePostParams) error
	GetPost(ctx context.Context, id PostID) (*Post, error)
	GetPostBySlug(ctx context.Context, slug string) (*Post, error)
	DeletePost(ctx context.Context, id PostID, timestamp time.Time, deletedBy string) error

	GetLikes(ctx context.Context, likedBy string, id ...PostID) (map[PostID]community.LikeWeight, error)
	SetLike(ctx context.Context, id PostID, weight community.LikeWeight, timestamp time.Time, likeOwner string) error

	AddPDV(ctx context.Context, address string, amount int64, timestamp time.Time) error

	GetProfileStats(ctx context.Context, addr ...string) ([]*ProfileStats, error)
	GetPostStats(ctx context.Context, id ...PostID) (map[PostID]Stats, error)

	GetDecentrStats(ctx context.Context) (*DecentrStats, error)

	ResetAccount(ctx context.Context, owner string) error
}

Storage provides methods for interacting with database.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
Package postgres is implementation of storage interface.
Package postgres is implementation of storage interface.

Jump to

Keyboard shortcuts

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