storage

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package storage contains a storage interface.

Index

Constants

This section is empty.

Variables

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

ErrNotFound ...

View Source
var ErrRequestedHeightIsTooHigh = errors.New("requested height is too high")

ErrRequestedHeightIsTooHigh returned when the height requested in WithLockedHeight function is more than expected.

View Source
var ErrRequestedHeightIsTooLow = errors.New("requested height is too low")

ErrRequestedHeightIsTooLow returned when the height requested in WithLockedHeight function is less than expected.

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 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
}

Post ...

type PostID

type PostID struct {
	Owner string
	UUID  string
}

PostID ...

type Profile

type Profile struct {
	Address   string
	FirstName string
	LastName  string
	Bio       string
	Avatar    string
	Gender    string
	Birthday  string
	CreatedAt time.Time
}

Profile ...

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 {
	WithLockedHeight(ctx context.Context, height uint64, f func(s Storage) error) error
	GetHeight(ctx context.Context) (uint64, error)

	GetProfiles(ctx context.Context, addr ...string) ([]*Profile, error)
	SetProfile(ctx context.Context, p *Profile) 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)
	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

	GetStats(ctx context.Context, id ...PostID) (map[PostID]Stats, 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