backend/pkg/post/domain/repository/post.go

55 lines
2.1 KiB
Go
Raw Permalink Normal View History

2025-11-19 05:33:06 +00:00
package repository
import (
"context"
"backend/pkg/post/domain/entity"
"backend/pkg/post/domain/post"
"github.com/gocql/gocql"
)
// PostRepository defines the interface for post data access operations
type PostRepository interface {
BasePostRepository
FindByAuthorUID(ctx context.Context, authorUID string, params *PostQueryParams) ([]*entity.Post, int64, error)
FindByCategoryID(ctx context.Context, categoryID gocql.UUID, params *PostQueryParams) ([]*entity.Post, int64, error)
FindByTag(ctx context.Context, tagName string, params *PostQueryParams) ([]*entity.Post, int64, error)
FindPinnedPosts(ctx context.Context, limit int64) ([]*entity.Post, error)
FindByStatus(ctx context.Context, status post.Status, params *PostQueryParams) ([]*entity.Post, int64, error)
IncrementLikeCount(ctx context.Context, postID gocql.UUID) error
DecrementLikeCount(ctx context.Context, postID gocql.UUID) error
IncrementCommentCount(ctx context.Context, postID gocql.UUID) error
DecrementCommentCount(ctx context.Context, postID gocql.UUID) error
IncrementViewCount(ctx context.Context, postID gocql.UUID) error
UpdateStatus(ctx context.Context, postID gocql.UUID, status post.Status) error
PinPost(ctx context.Context, postID gocql.UUID) error
UnpinPost(ctx context.Context, postID gocql.UUID) error
}
// BasePostRepository defines basic CRUD operations for posts
type BasePostRepository interface {
Insert(ctx context.Context, data *entity.Post) error
FindOne(ctx context.Context, id gocql.UUID) (*entity.Post, error)
Update(ctx context.Context, data *entity.Post) error
Delete(ctx context.Context, id gocql.UUID) error
}
// PostQueryParams defines query parameters for post listing
type PostQueryParams struct {
AuthorUID *string
CategoryID *gocql.UUID
Tag *string
Status *post.Status
Type *post.Type
IsPinned *bool
CreateStartTime *int64
CreateEndTime *int64
PublishedStartTime *int64
PublishedEndTime *int64
PageSize int64
PageIndex int64
OrderBy string // "created_at", "published_at", "like_count", "view_count"
OrderDirection string // "ASC", "DESC"
}