230 lines
9.8 KiB
Go
230 lines
9.8 KiB
Go
package usecase
|
|
|
|
import (
|
|
"context"
|
|
|
|
"backend/pkg/post/domain/post"
|
|
|
|
"github.com/gocql/gocql"
|
|
)
|
|
|
|
// PostUseCase defines the interface for post business logic operations
|
|
type PostUseCase interface {
|
|
PostCRUDUseCase
|
|
PostQueryUseCase
|
|
PostInteractionUseCase
|
|
PostManagementUseCase
|
|
}
|
|
|
|
// PostCRUDUseCase defines CRUD operations for posts
|
|
type PostCRUDUseCase interface {
|
|
// CreatePost creates a new post
|
|
CreatePost(ctx context.Context, req CreatePostRequest) (*PostResponse, error)
|
|
// GetPost retrieves a post by ID
|
|
GetPost(ctx context.Context, req GetPostRequest) (*PostResponse, error)
|
|
// UpdatePost updates an existing post
|
|
UpdatePost(ctx context.Context, req UpdatePostRequest) (*PostResponse, error)
|
|
// DeletePost deletes a post (soft delete)
|
|
DeletePost(ctx context.Context, req DeletePostRequest) error
|
|
// PublishPost publishes a draft post
|
|
PublishPost(ctx context.Context, req PublishPostRequest) (*PostResponse, error)
|
|
// ArchivePost archives a post
|
|
ArchivePost(ctx context.Context, req ArchivePostRequest) error
|
|
}
|
|
|
|
// PostQueryUseCase defines query operations for posts
|
|
type PostQueryUseCase interface {
|
|
// ListPosts lists posts with filters and pagination
|
|
ListPosts(ctx context.Context, req ListPostsRequest) (*ListPostsResponse, error)
|
|
// ListPostsByAuthor lists posts by author UID
|
|
ListPostsByAuthor(ctx context.Context, req ListPostsByAuthorRequest) (*ListPostsResponse, error)
|
|
// ListPostsByCategory lists posts by category
|
|
ListPostsByCategory(ctx context.Context, req ListPostsByCategoryRequest) (*ListPostsResponse, error)
|
|
// ListPostsByTag lists posts by tag
|
|
ListPostsByTag(ctx context.Context, req ListPostsByTagRequest) (*ListPostsResponse, error)
|
|
// GetPinnedPosts gets pinned posts
|
|
GetPinnedPosts(ctx context.Context, req GetPinnedPostsRequest) (*ListPostsResponse, error)
|
|
}
|
|
|
|
// PostInteractionUseCase defines interaction operations for posts
|
|
type PostInteractionUseCase interface {
|
|
// LikePost likes a post
|
|
LikePost(ctx context.Context, req LikePostRequest) error
|
|
// UnlikePost unlikes a post
|
|
UnlikePost(ctx context.Context, req UnlikePostRequest) error
|
|
// ViewPost increments view count
|
|
ViewPost(ctx context.Context, req ViewPostRequest) error
|
|
}
|
|
|
|
// PostManagementUseCase defines management operations for posts
|
|
type PostManagementUseCase interface {
|
|
// PinPost pins a post
|
|
PinPost(ctx context.Context, req PinPostRequest) error
|
|
// UnpinPost unpins a post
|
|
UnpinPost(ctx context.Context, req UnpinPostRequest) error
|
|
}
|
|
|
|
// CreatePostRequest represents a request to create a post
|
|
type CreatePostRequest struct {
|
|
AuthorUID string `json:"author_uid"` // Author user UID
|
|
Title string `json:"title"` // Post title
|
|
Content string `json:"content"` // Post content
|
|
Type post.Type `json:"type"` // Post type
|
|
CategoryID *gocql.UUID `json:"category_id,omitempty"` // Category ID (optional)
|
|
Tags []string `json:"tags,omitempty"` // Post tags (optional)
|
|
Images []string `json:"images,omitempty"` // Image URLs (optional)
|
|
VideoURL *string `json:"video_url,omitempty"` // Video URL (optional)
|
|
LinkURL *string `json:"link_url,omitempty"` // Link URL (optional)
|
|
Status post.Status `json:"status,omitempty"` // Post status (default: draft)
|
|
}
|
|
|
|
// UpdatePostRequest represents a request to update a post
|
|
type UpdatePostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
AuthorUID string `json:"author_uid"` // Author user UID (for authorization)
|
|
Title *string `json:"title,omitempty"` // Post title (optional)
|
|
Content *string `json:"content,omitempty"` // Post content (optional)
|
|
Type *post.Type `json:"type,omitempty"` // Post type (optional)
|
|
CategoryID *gocql.UUID `json:"category_id,omitempty"` // Category ID (optional)
|
|
Tags []string `json:"tags,omitempty"` // Post tags (optional)
|
|
Images []string `json:"images,omitempty"` // Image URLs (optional)
|
|
VideoURL *string `json:"video_url,omitempty"` // Video URL (optional)
|
|
LinkURL *string `json:"link_url,omitempty"` // Link URL (optional)
|
|
}
|
|
|
|
// GetPostRequest represents a request to get a post
|
|
type GetPostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
UserUID *string `json:"user_uid,omitempty"` // User UID (for view count increment)
|
|
}
|
|
|
|
// DeletePostRequest represents a request to delete a post
|
|
type DeletePostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
AuthorUID string `json:"author_uid"` // Author user UID (for authorization)
|
|
}
|
|
|
|
// PublishPostRequest represents a request to publish a post
|
|
type PublishPostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
AuthorUID string `json:"author_uid"` // Author user UID (for authorization)
|
|
}
|
|
|
|
// ArchivePostRequest represents a request to archive a post
|
|
type ArchivePostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
AuthorUID string `json:"author_uid"` // Author user UID (for authorization)
|
|
}
|
|
|
|
// ListPostsRequest represents a request to list posts
|
|
type ListPostsRequest struct {
|
|
CategoryID *gocql.UUID `json:"category_id,omitempty"` // Category ID (optional)
|
|
Tag *string `json:"tag,omitempty"` // Tag name (optional)
|
|
Status *post.Status `json:"status,omitempty"` // Post status (optional)
|
|
Type *post.Type `json:"type,omitempty"` // Post type (optional)
|
|
AuthorUID *string `json:"author_uid,omitempty"` // Author UID (optional)
|
|
CreateStartTime *int64 `json:"create_start_time,omitempty"` // Create start time (optional)
|
|
CreateEndTime *int64 `json:"create_end_time,omitempty"` // Create end time (optional)
|
|
PageSize int64 `json:"page_size"` // Page size
|
|
PageIndex int64 `json:"page_index"` // Page index
|
|
OrderBy string `json:"order_by,omitempty"` // Order by field
|
|
OrderDirection string `json:"order_direction,omitempty"` // Order direction (ASC/DESC)
|
|
}
|
|
|
|
// ListPostsByAuthorRequest represents a request to list posts by author
|
|
type ListPostsByAuthorRequest struct {
|
|
AuthorUID string `json:"author_uid"` // Author UID
|
|
Status *post.Status `json:"status,omitempty"` // Post status (optional)
|
|
PageSize int64 `json:"page_size"` // Page size
|
|
PageIndex int64 `json:"page_index"` // Page index
|
|
}
|
|
|
|
// ListPostsByCategoryRequest represents a request to list posts by category
|
|
type ListPostsByCategoryRequest struct {
|
|
CategoryID gocql.UUID `json:"category_id"` // Category ID
|
|
Status *post.Status `json:"status,omitempty"` // Post status (optional)
|
|
PageSize int64 `json:"page_size"` // Page size
|
|
PageIndex int64 `json:"page_index"` // Page index
|
|
}
|
|
|
|
// ListPostsByTagRequest represents a request to list posts by tag
|
|
type ListPostsByTagRequest struct {
|
|
Tag string `json:"tag"` // Tag name
|
|
Status *post.Status `json:"status,omitempty"` // Post status (optional)
|
|
PageSize int64 `json:"page_size"` // Page size
|
|
PageIndex int64 `json:"page_index"` // Page index
|
|
}
|
|
|
|
// GetPinnedPostsRequest represents a request to get pinned posts
|
|
type GetPinnedPostsRequest struct {
|
|
Limit int64 `json:"limit,omitempty"` // Limit (optional, default: 10)
|
|
}
|
|
|
|
// LikePostRequest represents a request to like a post
|
|
type LikePostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
UserUID string `json:"user_uid"` // User UID
|
|
}
|
|
|
|
// UnlikePostRequest represents a request to unlike a post
|
|
type UnlikePostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
UserUID string `json:"user_uid"` // User UID
|
|
}
|
|
|
|
// ViewPostRequest represents a request to view a post
|
|
type ViewPostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
UserUID *string `json:"user_uid,omitempty"` // User UID (optional)
|
|
}
|
|
|
|
// PinPostRequest represents a request to pin a post
|
|
type PinPostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
AuthorUID string `json:"author_uid"` // Author user UID (for authorization)
|
|
}
|
|
|
|
// UnpinPostRequest represents a request to unpin a post
|
|
type UnpinPostRequest struct {
|
|
PostID gocql.UUID `json:"post_id"` // Post ID
|
|
AuthorUID string `json:"author_uid"` // Author user UID (for authorization)
|
|
}
|
|
|
|
// PostResponse represents a post response
|
|
type PostResponse struct {
|
|
ID gocql.UUID `json:"id"`
|
|
AuthorUID string `json:"author_uid"`
|
|
Title string `json:"title"`
|
|
Content string `json:"content"`
|
|
Type post.Type `json:"type"`
|
|
Status post.Status `json:"status"`
|
|
CategoryID *gocql.UUID `json:"category_id,omitempty"`
|
|
Tags []string `json:"tags,omitempty"`
|
|
Images []string `json:"images,omitempty"`
|
|
VideoURL *string `json:"video_url,omitempty"`
|
|
LinkURL *string `json:"link_url,omitempty"`
|
|
LikeCount int64 `json:"like_count"`
|
|
CommentCount int64 `json:"comment_count"`
|
|
ViewCount int64 `json:"view_count"`
|
|
IsPinned bool `json:"is_pinned"`
|
|
PinnedAt *int64 `json:"pinned_at,omitempty"`
|
|
PublishedAt *int64 `json:"published_at,omitempty"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
UpdatedAt int64 `json:"updated_at"`
|
|
}
|
|
|
|
// ListPostsResponse represents a list of posts response
|
|
type ListPostsResponse struct {
|
|
Data []PostResponse `json:"data"`
|
|
Page Pager `json:"page"`
|
|
}
|
|
|
|
// Pager represents pagination information
|
|
type Pager struct {
|
|
PageIndex int64 `json:"page_index"`
|
|
PageSize int64 `json:"page_size"`
|
|
Total int64 `json:"total"`
|
|
TotalPage int64 `json:"total_page"`
|
|
}
|
|
|