backend/pkg/post/domain/usecase/comment.go

129 lines
5.1 KiB
Go
Raw Permalink Normal View History

2025-11-19 05:33:06 +00:00
package usecase
import (
"context"
"backend/pkg/post/domain/post"
"github.com/gocql/gocql"
)
// CommentUseCase defines the interface for comment business logic operations
type CommentUseCase interface {
CommentCRUDUseCase
CommentQueryUseCase
CommentInteractionUseCase
}
// CommentCRUDUseCase defines CRUD operations for comments
type CommentCRUDUseCase interface {
// CreateComment creates a new comment
CreateComment(ctx context.Context, req CreateCommentRequest) (*CommentResponse, error)
// GetComment retrieves a comment by ID
GetComment(ctx context.Context, req GetCommentRequest) (*CommentResponse, error)
// UpdateComment updates an existing comment
UpdateComment(ctx context.Context, req UpdateCommentRequest) (*CommentResponse, error)
// DeleteComment deletes a comment (soft delete)
DeleteComment(ctx context.Context, req DeleteCommentRequest) error
}
// CommentQueryUseCase defines query operations for comments
type CommentQueryUseCase interface {
// ListComments lists comments for a post
ListComments(ctx context.Context, req ListCommentsRequest) (*ListCommentsResponse, error)
// ListReplies lists replies to a comment
ListReplies(ctx context.Context, req ListRepliesRequest) (*ListCommentsResponse, error)
// ListCommentsByAuthor lists comments by author
ListCommentsByAuthor(ctx context.Context, req ListCommentsByAuthorRequest) (*ListCommentsResponse, error)
}
// CommentInteractionUseCase defines interaction operations for comments
type CommentInteractionUseCase interface {
// LikeComment likes a comment
LikeComment(ctx context.Context, req LikeCommentRequest) error
// UnlikeComment unlikes a comment
UnlikeComment(ctx context.Context, req UnlikeCommentRequest) error
}
// CreateCommentRequest represents a request to create a comment
type CreateCommentRequest struct {
PostID gocql.UUID `json:"post_id"` // Post ID
AuthorUID string `json:"author_uid"` // Author user UID
ParentID *gocql.UUID `json:"parent_id,omitempty"` // Parent comment ID (optional, for replies)
Content string `json:"content"` // Comment content
}
// UpdateCommentRequest represents a request to update a comment
type UpdateCommentRequest struct {
CommentID gocql.UUID `json:"comment_id"` // Comment ID
AuthorUID string `json:"author_uid"` // Author user UID (for authorization)
Content string `json:"content"` // Comment content
}
// GetCommentRequest represents a request to get a comment
type GetCommentRequest struct {
CommentID gocql.UUID `json:"comment_id"` // Comment ID
}
// DeleteCommentRequest represents a request to delete a comment
type DeleteCommentRequest struct {
CommentID gocql.UUID `json:"comment_id"` // Comment ID
AuthorUID string `json:"author_uid"` // Author user UID (for authorization)
}
// ListCommentsRequest represents a request to list comments
type ListCommentsRequest struct {
PostID gocql.UUID `json:"post_id"` // Post ID
ParentID *gocql.UUID `json:"parent_id,omitempty"` // Parent comment ID (optional, for replies only)
PageSize int64 `json:"page_size"` // Page size
PageIndex int64 `json:"page_index"` // Page index
OrderBy string `json:"order_by,omitempty"` // Order by field (default: "created_at")
OrderDirection string `json:"order_direction,omitempty"` // Order direction (ASC/DESC, default: ASC)
}
// ListRepliesRequest represents a request to list replies to a comment
type ListRepliesRequest struct {
CommentID gocql.UUID `json:"comment_id"` // Comment ID
PageSize int64 `json:"page_size"` // Page size
PageIndex int64 `json:"page_index"` // Page index
}
// ListCommentsByAuthorRequest represents a request to list comments by author
type ListCommentsByAuthorRequest struct {
AuthorUID string `json:"author_uid"` // Author UID
PageSize int64 `json:"page_size"` // Page size
PageIndex int64 `json:"page_index"` // Page index
}
// LikeCommentRequest represents a request to like a comment
type LikeCommentRequest struct {
CommentID gocql.UUID `json:"comment_id"` // Comment ID
UserUID string `json:"user_uid"` // User UID
}
// UnlikeCommentRequest represents a request to unlike a comment
type UnlikeCommentRequest struct {
CommentID gocql.UUID `json:"comment_id"` // Comment ID
UserUID string `json:"user_uid"` // User UID
}
// CommentResponse represents a comment response
type CommentResponse struct {
ID gocql.UUID `json:"id"`
PostID gocql.UUID `json:"post_id"`
AuthorUID string `json:"author_uid"`
ParentID *gocql.UUID `json:"parent_id,omitempty"`
Content string `json:"content"`
Status post.CommentStatus `json:"status"`
LikeCount int64 `json:"like_count"`
ReplyCount int64 `json:"reply_count"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
// ListCommentsResponse represents a list of comments response
type ListCommentsResponse struct {
Data []CommentResponse `json:"data"`
Page Pager `json:"page"`
}