like

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidIDFormat     = fmt.Errorf("invalid ID format")
	ErrLikeCreationFailed  = fmt.Errorf("like creation failed")
	ErrLikeNotFound        = fmt.Errorf("like not found")
	ErrLikeQueryFailed     = fmt.Errorf("failed to query Like by ID")
	ErrLikeUpdateFailed    = fmt.Errorf("like update failed")
	ErrLikeDeletionFailed  = fmt.Errorf("like deletion failed")
	ErrInvalidUserIDFormat = fmt.Errorf("invalid User ID format")
	ErrLikeAlreadyExists   = fmt.Errorf("like already exist")
)

Custom errors for Like operations

Functions

func IdToCacheKey

func IdToCacheKey(idHex string) string

func IsInvalidIDFormat added in v0.4.1

func IsInvalidIDFormat(err error) bool

IsInvalidIDFormat checks if an error is due to invalid ID format.

func IsInvalidUserIDFormat added in v0.4.1

func IsInvalidUserIDFormat(err error) bool

IsInvalidUserIDFormat checks if an error is due to invalid User ID format.

func IsLikeCreationFailed added in v0.4.1

func IsLikeCreationFailed(err error) bool

IsLikeCreationFailed checks if an error is due to like creation failure.

func IsLikeDeletionFailed added in v0.4.1

func IsLikeDeletionFailed(err error) bool

IsLikeDeletionFailed checks if an error is due to like deletion failure.

func IsLikeNotFound added in v0.4.1

func IsLikeNotFound(err error) bool

IsLikeNotFound checks if an error is due to a like not being found.

func IsLikeUpdateFailed added in v0.4.1

func IsLikeUpdateFailed(err error) bool

IsLikeUpdateFailed checks if an error is due to like update failure.

Types

type Core

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

func NewCore

func NewCore(cache cachestore.CacheStore, storer Storer, userStore user.Storer, likeProducer producer.Producer) *Core

func (*Core) Create

func (c *Core) Create(ctx context.Context, newLike Like) (Like, error)

func (*Core) DeleteByID

func (c *Core) DeleteByID(ctx context.Context, likeID string) error

func (*Core) QueryAllByPostID

func (c *Core) QueryAllByPostID(ctx context.Context, postID string) ([]Like, error)

QueryAllByPostID retrieves all likes for a specific post

func (*Core) QueryAllByUserID

func (c *Core) QueryAllByUserID(ctx context.Context, userID string) ([]Like, error)

func (*Core) QueryByID

func (c *Core) QueryByID(ctx context.Context, likeID string) (Like, error)

func (*Core) Update

func (c *Core) Update(ctx context.Context, updatedLike Like) (Like, error)

type Like

type Like struct {
	ID         primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	UserID     primitive.ObjectID `json:"user_id,omitempty" bson:"user_id,omitempty"`
	PostID     int64              `json:"post_id" bson:"post_id,omitempty"`
	IsPositive bool               `json:"is_positive"`
}

func (Like) CacheExpiration

func (p Like) CacheExpiration() time.Duration

func (Like) CacheKey

func (l Like) CacheKey() string

type NewLike

type NewLike struct {
	PostID     int64 `json:"post_id"`
	IsPositive bool  `json:"is_positive"`
}

type Storer

type Storer interface {
	Create(ctx context.Context, newLike Like) (Like, error)
	QueryByID(ctx context.Context, likeID string) (Like, error)
	QueryAllByUserID(ctx context.Context, userID string) ([]Like, error)
	QueryAllByPostID(ctx context.Context, postID string) ([]Like, error)
	QueryByUserAndPostID(ctx context.Context, userID string, postID int64) (Like, error)
	Update(ctx context.Context, updatedLike Like) (Like, error)
	DeleteByID(ctx context.Context, likeID string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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