repo

package
v0.0.0-...-2e936b0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memory

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

Memory Represents in-memory storage for posts data.

func NewMemory

func NewMemory() *Memory

NewMemory Creates new in-memory storage.

func (*Memory) Add

func (r *Memory) Add(_ context.Context, newPost *post.Post) (postID uuid.UUID, err error)

Add Creates post in the app storage.

func (*Memory) AddComment

func (r *Memory) AddComment(_ context.Context, postID uuid.UUID, newComment *post.Comment) (commentID uuid.UUID, err error)

AddComment Adds comment to the givven post.

func (*Memory) AddVote

func (r *Memory) AddVote(_ context.Context, postID uuid.UUID, vote *post.Vote) error

AddVote Adds vote to the givven post.

func (*Memory) Delete

func (r *Memory) Delete(_ context.Context, postID uuid.UUID) error

Delete Removes post from the app storage.

func (*Memory) DeleteComment

func (r *Memory) DeleteComment(_ context.Context, postID, commentID uuid.UUID) error

DeleteComment Removes comment from storage by post, comment IDs.

func (*Memory) GetAll

func (r *Memory) GetAll(_ context.Context) ([]*post.Post, error)

GetAll Return all posts from the app storage.

func (*Memory) GetByCatName

func (r *Memory) GetByCatName(_ context.Context, catName string) ([]*post.Post, error)

GetByCatName Finds posts of given category.

func (*Memory) GetByID

func (r *Memory) GetByID(_ context.Context, postID uuid.UUID) (*post.Post, error)

GetByID Finds post by it ID.

func (*Memory) GetByUserID

func (r *Memory) GetByUserID(_ context.Context, userID uuid.UUID) ([]*post.Post, error)

GetByUserID Finds posts of given user by user ID.

func (*Memory) GetCommentByID

func (r *Memory) GetCommentByID(_ context.Context, commentID uuid.UUID) (*post.Comment, error)

GetCommentByID Finds comment by comment ID.

func (*Memory) GetComments

func (r *Memory) GetComments(_ context.Context, postID uuid.UUID) ([]*post.Comment, error)

GetComments Finds comments of the givven post in the app strorage.

func (*Memory) GetVotes

func (r *Memory) GetVotes(_ context.Context, postID uuid.UUID) ([]*post.Vote, error)

GetVotes Finds votes of the given post by ID in the app storage.

type PostDB

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

PostDB represents single post in the storage.

func (PostDB) CommentsList

func (p PostDB) CommentsList() []*post.Comment

CommentsList Returns all comments as list.

type Postgres

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

Postgres represents postgres storage for posts data.

func NewPostgres

func NewPostgres(db *sqlx.DB, log *logger.Logger) *Postgres

func (*Postgres) Add

func (r *Postgres) Add(ctx context.Context, newPost post.Post) error

Add create post in the app storage.

func (*Postgres) AddComment

func (r *Postgres) AddComment(ctx context.Context, newComment post.Comment) error

AddComment create comment in the app storage.

func (*Postgres) AddVote

func (r *Postgres) AddVote(ctx context.Context, postID uuid.UUID, vote post.Vote) error

AddVote creates vote in the storage.

func (*Postgres) CheckVote

func (r *Postgres) CheckVote(ctx context.Context, postID uuid.UUID, userID uuid.UUID) error

CheckVote checks if user already voted or not.

func (*Postgres) Count

func (r *Postgres) Count(ctx context.Context) (int, error)

Count retunns total number of posts in the DB.

func (*Postgres) Delete

func (r *Postgres) Delete(ctx context.Context, postID uuid.UUID) error

Delete Removes post from the app storage.

func (*Postgres) DeleteComment

func (r *Postgres) DeleteComment(ctx context.Context, commentID uuid.UUID) error

DeleteComment removes comment from the app storage.

func (*Postgres) GetAll

func (r *Postgres) GetAll(ctx context.Context, pageNum int, rowsPerPage int) ([]post.Post, error)

GetAll return all posts from the app storage.

func (*Postgres) GetByCatName

func (r *Postgres) GetByCatName(ctx context.Context, catName string) ([]post.Post, error)

GetByCatName finds posts of given category.

func (*Postgres) GetByID

func (r *Postgres) GetByID(ctx context.Context, postID uuid.UUID) (post.Post, error)

GetByID finds post by it ID.

func (*Postgres) GetByUserID

func (r *Postgres) GetByUserID(ctx context.Context, userID uuid.UUID) ([]post.Post, error)

GetByUserID finds posts of given user by user ID.

func (*Postgres) GetCommentByID

func (r *Postgres) GetCommentByID(ctx context.Context, commentID uuid.UUID) (post.Comment, error)

GetCommentByID finds comment by it ID.

func (*Postgres) GetCommentsByPostID

func (r *Postgres) GetCommentsByPostID(ctx context.Context, postID uuid.UUID) ([]post.Comment, error)

GetComments returns a list of post comments.

func (*Postgres) GetCommentsByPostIDs

func (r *Postgres) GetCommentsByPostIDs(ctx context.Context, postIDs []uuid.UUID) ([]post.Comment, error)

GetCommentsByPostIDs returns a list of posts comments.

func (*Postgres) GetVotesByPostID

func (r *Postgres) GetVotesByPostID(ctx context.Context, postID uuid.UUID) ([]post.Vote, error)

GetVotes returns a list of post votes.

func (*Postgres) GetVotesByPostIDs

func (r *Postgres) GetVotesByPostIDs(ctx context.Context, postIDs []uuid.UUID) ([]post.Vote, error)

GetVotesByPostIDs returns a list of posts votes.

func (*Postgres) UpdateVote

func (r *Postgres) UpdateVote(ctx context.Context, postID uuid.UUID, vote post.Vote) error

UpdateVote changes vote of the user in the storage.

Jump to

Keyboard shortcuts

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