Documentation
¶
Overview ¶
Package postflow provides functionality for managing user posts and feeds.
Package postflow provides functionality for managing user posts and feeds.
The package implements a post management system that supports creating, retrieving, updating and deleting posts, as well as managing user feeds and interactions.
Package postflow provides functionality for managing user posts and feeds.
Package postflow provides functionality for managing user posts and feeds.
Index ¶
- Variables
- type GormPostStore
- func (s *GormPostStore) DeletePost(ctx context.Context, postID string, userID string) error
- func (s *GormPostStore) DeleteReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
- func (s *GormPostStore) GetPost(ctx context.Context, postID string) (*Post, error)
- func (s *GormPostStore) GetReactedUsers(ctx context.Context, postID string, reactionType *ReactionType, ...) ([]string, error)
- func (s *GormPostStore) GetReactionCounts(ctx context.Context, postID string) (map[ReactionType]int, error)
- func (s *GormPostStore) GetTrendingPosts(ctx context.Context, limit int) ([]*Post, error)
- func (s *GormPostStore) GetUserFeed(ctx context.Context, userID string, limit, offset int) ([]*Post, error)
- func (s *GormPostStore) GetUserReaction(ctx context.Context, postID string, userID string) (*ReactionType, error)
- func (s *GormPostStore) ListPosts(ctx context.Context, filter *PostFilter) ([]*Post, error)
- func (s *GormPostStore) SavePost(ctx context.Context, post *Post) error
- func (s *GormPostStore) SaveReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
- type InMemoryPostStore
- func (s *InMemoryPostStore) DeletePost(ctx context.Context, postID string, userID string) error
- func (s *InMemoryPostStore) DeleteReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
- func (s *InMemoryPostStore) GetPost(ctx context.Context, postID string) (*Post, error)
- func (s *InMemoryPostStore) GetReactedUsers(ctx context.Context, postID string, reactionType *ReactionType, ...) ([]string, error)
- func (s *InMemoryPostStore) GetReactionCounts(ctx context.Context, postID string) (map[ReactionType]int, error)
- func (s *InMemoryPostStore) GetTrendingPosts(ctx context.Context, limit int) ([]*Post, error)
- func (s *InMemoryPostStore) GetUserFeed(ctx context.Context, userID string, limit, offset int) ([]*Post, error)
- func (s *InMemoryPostStore) GetUserReaction(ctx context.Context, postID string, userID string) (*ReactionType, error)
- func (s *InMemoryPostStore) ListPosts(ctx context.Context, filter *PostFilter) ([]*Post, error)
- func (s *InMemoryPostStore) SavePost(ctx context.Context, post *Post) error
- func (s *InMemoryPostStore) SaveReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
- type Media
- type MediaModel
- type MediaType
- type Post
- type PostFilter
- type PostManager
- type PostManagerImpl
- func (m *PostManagerImpl) AddReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
- func (m *PostManagerImpl) CreatePost(ctx context.Context, post *Post) (string, error)
- func (m *PostManagerImpl) DeletePost(ctx context.Context, postID string, userID string) error
- func (m *PostManagerImpl) GetPost(ctx context.Context, postID string) (*Post, error)
- func (m *PostManagerImpl) GetReactedUsers(ctx context.Context, postID string, reactionType *ReactionType, ...) ([]string, error)
- func (m *PostManagerImpl) GetReactionCounts(ctx context.Context, postID string) (map[ReactionType]int, error)
- func (m *PostManagerImpl) GetTrendingPosts(ctx context.Context, limit int) ([]*Post, error)
- func (m *PostManagerImpl) GetUserFeed(ctx context.Context, userID string, limit, offset int) ([]*Post, error)
- func (m *PostManagerImpl) GetUserReaction(ctx context.Context, postID string, userID string) (*ReactionType, error)
- func (m *PostManagerImpl) ListPosts(ctx context.Context, filter *PostFilter) ([]*Post, error)
- func (m *PostManagerImpl) RemoveReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
- func (m *PostManagerImpl) UpdatePost(ctx context.Context, post *Post) error
- type PostModel
- type PostStore
- type ReactionModel
- type ReactionType
- type TagModel
- type TimeRange
- type UserReaction
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPostNotFound is returned when a post is not found ErrPostNotFound = errors.New("post not found") // ErrPermissionDenied is returned when a user doesn't have permission to modify a post ErrPermissionDenied = errors.New("permission denied") // ErrInvalidReaction is returned when an invalid reaction is provided ErrInvalidReaction = errors.New("invalid reaction") )
Functions ¶
This section is empty.
Types ¶
type GormPostStore ¶
type GormPostStore struct {
// contains filtered or unexported fields
}
GormPostStore implements PostStore interface with GORM as the underlying storage
func NewGormPostStore ¶
func NewGormPostStore(db *gorm.DB) (*GormPostStore, error)
NewGormPostStore creates a new instance of GormPostStore
func (*GormPostStore) DeletePost ¶
DeletePost removes a post from the store
func (*GormPostStore) DeleteReaction ¶
func (s *GormPostStore) DeleteReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
DeleteReaction removes a reaction from a post
func (*GormPostStore) GetReactedUsers ¶
func (s *GormPostStore) GetReactedUsers(ctx context.Context, postID string, reactionType *ReactionType, limit, offset int) ([]string, error)
GetReactedUsers returns users who reacted to a specific post
func (*GormPostStore) GetReactionCounts ¶
func (s *GormPostStore) GetReactionCounts(ctx context.Context, postID string) (map[ReactionType]int, error)
GetReactionCounts returns the count of each reaction type for a post
func (*GormPostStore) GetTrendingPosts ¶
GetTrendingPosts retrieves currently trending posts
func (*GormPostStore) GetUserFeed ¶
func (s *GormPostStore) GetUserFeed(ctx context.Context, userID string, limit, offset int) ([]*Post, error)
GetUserFeed retrieves posts for a user's feed
func (*GormPostStore) GetUserReaction ¶
func (s *GormPostStore) GetUserReaction(ctx context.Context, postID string, userID string) (*ReactionType, error)
GetUserReaction gets the current reaction of a user for a post
func (*GormPostStore) ListPosts ¶
func (s *GormPostStore) ListPosts(ctx context.Context, filter *PostFilter) ([]*Post, error)
ListPosts retrieves posts based on filter criteria
func (*GormPostStore) SavePost ¶
func (s *GormPostStore) SavePost(ctx context.Context, post *Post) error
SavePost saves a new post or updates an existing post
func (*GormPostStore) SaveReaction ¶
func (s *GormPostStore) SaveReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
SaveReaction saves a reaction to a post
type InMemoryPostStore ¶
type InMemoryPostStore struct {
// contains filtered or unexported fields
}
InMemoryPostStore implements PostStore interface with in-memory storage
func NewInMemoryPostStore ¶
func NewInMemoryPostStore() *InMemoryPostStore
NewInMemoryPostStore creates a new instance of InMemoryPostStore
func (*InMemoryPostStore) DeletePost ¶
DeletePost removes a post from the store
func (*InMemoryPostStore) DeleteReaction ¶
func (s *InMemoryPostStore) DeleteReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
DeleteReaction removes a reaction from a post
func (*InMemoryPostStore) GetReactedUsers ¶
func (s *InMemoryPostStore) GetReactedUsers(ctx context.Context, postID string, reactionType *ReactionType, limit, offset int) ([]string, error)
GetReactedUsers returns users who reacted to a specific post
func (*InMemoryPostStore) GetReactionCounts ¶
func (s *InMemoryPostStore) GetReactionCounts(ctx context.Context, postID string) (map[ReactionType]int, error)
GetReactionCounts returns the count of each reaction type for a post
func (*InMemoryPostStore) GetTrendingPosts ¶
GetTrendingPosts retrieves currently trending posts This simple implementation returns posts with most reactions and comments
func (*InMemoryPostStore) GetUserFeed ¶
func (s *InMemoryPostStore) GetUserFeed(ctx context.Context, userID string, limit, offset int) ([]*Post, error)
GetUserFeed retrieves posts for a user's feed In a real implementation, this would consider followed users, algorithms, etc. This simple version just returns recent public posts
func (*InMemoryPostStore) GetUserReaction ¶
func (s *InMemoryPostStore) GetUserReaction(ctx context.Context, postID string, userID string) (*ReactionType, error)
GetUserReaction gets the current reaction of a user for a post
func (*InMemoryPostStore) ListPosts ¶
func (s *InMemoryPostStore) ListPosts(ctx context.Context, filter *PostFilter) ([]*Post, error)
ListPosts retrieves posts based on filter criteria
func (*InMemoryPostStore) SavePost ¶
func (s *InMemoryPostStore) SavePost(ctx context.Context, post *Post) error
SavePost saves a post to the in-memory store
func (*InMemoryPostStore) SaveReaction ¶
func (s *InMemoryPostStore) SaveReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
SaveReaction saves a reaction to a post
type Media ¶
type Media struct {
ID string `json:"id"`
Type MediaType `json:"type"`
URL string `json:"url"`
ThumbnailURL string `json:"thumbnail_url,omitempty"`
Description string `json:"description,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Duration int `json:"duration,omitempty"` // Duration in seconds for video/audio
FileSize int64 `json:"file_size,omitempty"` // Size in bytes
FileName string `json:"file_name,omitempty"`
MimeType string `json:"mime_type,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
Media represents a media item attached to a post
type MediaModel ¶
type MediaModel struct {
ID string `gorm:"primaryKey"`
PostID string `gorm:"index"`
Type uint8
URL string
ThumbnailURL string
Description string
Width int
Height int
Duration int
FileSize int64
FileName string
MimeType string
CreatedAt time.Time
}
MediaModel is the GORM model for storing media items
type Post ¶
type Post struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Content string `json:"content"`
Media []Media `json:"media,omitempty"`
Tags []string `json:"tags,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Reactions map[ReactionType]int `json:"reactions"`
Comments int `json:"comments"`
Visibility string `json:"visibility"` // public, private, friends
}
Post represents a user post in the system.
type PostFilter ¶
type PostFilter struct {
UserID string
Tags []string
TimeRange *TimeRange
Visibility string
Limit int
Offset int
SortBy string
SortOrder string
}
PostFilter represents filtering options for retrieving posts.
type PostManager ¶
type PostManager interface {
// CreatePost creates a new post in the system.
CreatePost(ctx context.Context, post *Post) (string, error)
// GetPost retrieves a post by its ID.
GetPost(ctx context.Context, postID string) (*Post, error)
// UpdatePost updates an existing post.
UpdatePost(ctx context.Context, post *Post) error
// DeletePost removes a post from the system.
DeletePost(ctx context.Context, postID string, userID string) error
// ListPosts retrieves a list of posts based on filter criteria.
ListPosts(ctx context.Context, filter *PostFilter) ([]*Post, error)
// GetUserFeed returns posts for a user's feed.
GetUserFeed(ctx context.Context, userID string, limit, offset int) ([]*Post, error)
// GetTrendingPosts returns currently trending posts.
GetTrendingPosts(ctx context.Context, limit int) ([]*Post, error)
// AddReaction adds an emotional reaction to a post.
AddReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
// RemoveReaction removes an emotional reaction from a post.
RemoveReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
// GetUserReaction gets the current reaction of a user for a post.
GetUserReaction(ctx context.Context, postID string, userID string) (*ReactionType, error)
// GetReactedUsers returns users who reacted to a specific post with optional reaction type filter.
GetReactedUsers(ctx context.Context, postID string, reactionType *ReactionType, limit, offset int) ([]string, error)
// GetReactionCounts returns the count of each reaction type for a post.
GetReactionCounts(ctx context.Context, postID string) (map[ReactionType]int, error)
}
PostManager defines the interface for managing posts in the system.
type PostManagerImpl ¶
type PostManagerImpl struct {
// contains filtered or unexported fields
}
PostManagerImpl implements the PostManager interface using a PostStore for persistence
func NewPostManager ¶
func NewPostManager(store PostStore) *PostManagerImpl
NewPostManager creates a new instance of PostManagerImpl
func (*PostManagerImpl) AddReaction ¶
func (m *PostManagerImpl) AddReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
AddReaction adds an emotional reaction to a post
func (*PostManagerImpl) CreatePost ¶
CreatePost creates a new post in the system
func (*PostManagerImpl) DeletePost ¶
DeletePost removes a post from the system
func (*PostManagerImpl) GetReactedUsers ¶
func (m *PostManagerImpl) GetReactedUsers(ctx context.Context, postID string, reactionType *ReactionType, limit, offset int) ([]string, error)
GetReactedUsers returns users who reacted to a specific post with optional reaction type filter
func (*PostManagerImpl) GetReactionCounts ¶
func (m *PostManagerImpl) GetReactionCounts(ctx context.Context, postID string) (map[ReactionType]int, error)
GetReactionCounts returns the count of each reaction type for a post
func (*PostManagerImpl) GetTrendingPosts ¶
GetTrendingPosts returns currently trending posts
func (*PostManagerImpl) GetUserFeed ¶
func (m *PostManagerImpl) GetUserFeed(ctx context.Context, userID string, limit, offset int) ([]*Post, error)
GetUserFeed returns posts for a user's feed
func (*PostManagerImpl) GetUserReaction ¶
func (m *PostManagerImpl) GetUserReaction(ctx context.Context, postID string, userID string) (*ReactionType, error)
GetUserReaction gets the current reaction of a user for a post
func (*PostManagerImpl) ListPosts ¶
func (m *PostManagerImpl) ListPosts(ctx context.Context, filter *PostFilter) ([]*Post, error)
ListPosts retrieves a list of posts based on filter criteria
func (*PostManagerImpl) RemoveReaction ¶
func (m *PostManagerImpl) RemoveReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
RemoveReaction removes an emotional reaction from a post
func (*PostManagerImpl) UpdatePost ¶
func (m *PostManagerImpl) UpdatePost(ctx context.Context, post *Post) error
UpdatePost updates an existing post
type PostModel ¶
type PostModel struct {
ID string `gorm:"primaryKey"`
UserID string `gorm:"index"`
Content string
Media []MediaModel `gorm:"foreignKey:PostID"`
Tags []TagModel `gorm:"many2many:post_tags;"`
CreatedAt time.Time
UpdatedAt time.Time
Visibility string
Comments int
}
PostModel is the GORM model for storing posts
type PostStore ¶
type PostStore interface {
// SavePost saves a new post or updates an existing post
SavePost(ctx context.Context, post *Post) error
// GetPost retrieves a post by its ID
GetPost(ctx context.Context, postID string) (*Post, error)
// DeletePost removes a post from the store
DeletePost(ctx context.Context, postID string, userID string) error
// ListPosts retrieves posts based on filter criteria
ListPosts(ctx context.Context, filter *PostFilter) ([]*Post, error)
// GetUserFeed retrieves posts for a user's feed
GetUserFeed(ctx context.Context, userID string, limit, offset int) ([]*Post, error)
// GetTrendingPosts retrieves currently trending posts
GetTrendingPosts(ctx context.Context, limit int) ([]*Post, error)
// SaveReaction saves a reaction to a post
SaveReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
// DeleteReaction removes a reaction from a post
DeleteReaction(ctx context.Context, postID string, userID string, reactionType ReactionType) error
// GetUserReaction gets the current reaction of a user for a post
GetUserReaction(ctx context.Context, postID string, userID string) (*ReactionType, error)
// GetReactedUsers returns users who reacted to a specific post with optional reaction type filter
GetReactedUsers(ctx context.Context, postID string, reactionType *ReactionType, limit, offset int) ([]string, error)
// GetReactionCounts returns the count of each reaction type for a post
GetReactionCounts(ctx context.Context, postID string) (map[ReactionType]int, error)
}
PostStore defines the interface for storing and retrieving posts
type ReactionModel ¶
type ReactionModel struct {
PostID string `gorm:"primaryKey;index"`
UserID string `gorm:"primaryKey;index"`
ReactionType uint8
CreatedAt time.Time
}
ReactionModel is the GORM model for storing user reactions to posts
type ReactionType ¶
type ReactionType uint8
ReactionType represents different emotional reactions to posts using an efficient numeric type
const ( ReactionNone ReactionType = 0 ReactionLike ReactionType = 1 ReactionLove ReactionType = 2 ReactionHaha ReactionType = 3 ReactionWow ReactionType = 4 ReactionSad ReactionType = 5 ReactionAngry ReactionType = 6 )
type TagModel ¶
type TagModel struct {
Name string `gorm:"primaryKey"`
}
TagModel is the GORM model for storing tags
type UserReaction ¶
type UserReaction struct {
UserID string
ReactionType ReactionType
CreatedAt time.Time
}
UserReaction represents a user's reaction to a post