repository

package
v0.0.0-...-c1f85f1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Forever             = 0 // Forever indicates an infinite TTL
	TweetTTL            = 2 * time.Hour
	MaxTweetsInTimeline = 40
)

Variables

This section is empty.

Functions

func TimelineKey

func TimelineKey(userID uint) string

TimelineKey returns the key that stores an user's timeline

func TweetKey

func TweetKey(tweetID uuid.UUID) string

TweetKey returns the key that stores a tweet by id

func UserFollowersKey

func UserFollowersKey(userID uint) string

UserFollowersKey returns the key that stores the list of followers of userID in the cache

Types

type IRepository

type IRepository interface {
	// AddFollower adds newFollowerID to the list of followers of userID
	AddFollower(userID, newFollowerID uint) error
	// GetFollowers returns the list of followers of user userID
	GetFollowers(userID uint) ([]uint, error)
	// CreateTweet creates a tweet returning its id
	CreateTweet(tweet models.Tweet) (uuid.UUID, error)
	// GetTweets returns a list of tweets by their ids
	GetTweets(ids []uuid.UUID) ([]models.Tweet, error)
	// AddTweetToTimeline adds a tweetID to the user's timeline, maintaining a maximin length of 40 tweets
	AddTweetToTimeline(tweetID uuid.UUID, userID uint) error
	// GetTimeline returns the list of tweets ids in a user timeline
	GetTimeline(userID uint) ([]uuid.UUID, error)
}

type Repository

type Repository struct {
	RDB *redis.Client
}

func (Repository) AddFollower

func (repository Repository) AddFollower(userID, newFollowerID uint) error

AddFollower adds newFollowerID to the list of followers of userID

func (Repository) AddTweetToTimeline

func (repository Repository) AddTweetToTimeline(tweetID uuid.UUID, userID uint) error

AddTweetToTimeline adds a tweetID to the user's timeline, maintaining a maximin length of 40 tweets

func (Repository) CreateTweet

func (repository Repository) CreateTweet(tweet models.Tweet) (uuid.UUID, error)

CreateTweet creates a tweet returning its id

func (Repository) GetFollowers

func (repository Repository) GetFollowers(userID uint) ([]uint, error)

GetFollowers returns the list of followers of user userID

func (Repository) GetTimeline

func (repository Repository) GetTimeline(userID uint) ([]uuid.UUID, error)

GetTimeline returns the list of tweets ids in a user timeline

func (Repository) GetTweets

func (repository Repository) GetTweets(ids []uuid.UUID) ([]models.Tweet, error)

GetTweets returns a list of tweets by their ids

Jump to

Keyboard shortcuts

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