Documentation ¶
Index ¶
- type Category
- type CategoryRepo
- type CategoryUseCase
- func (uc *CategoryUseCase) CreateCategory(c *Category) error
- func (uc *CategoryUseCase) DeleteCategory(id uint) error
- func (uc *CategoryUseCase) DeleteCategoryByName(name string) error
- func (uc *CategoryUseCase) GetAllCategories() ([]*Category, error)
- func (uc *CategoryUseCase) GetCategoryByID(id uint) (*Category, error)
- func (uc *CategoryUseCase) GetCategoryByName(name string) (*Category, error)
- type Comment
- type CommentRepo
- type CommentUseCase
- type ListOptions
- type Post
- type PostRepo
- type PostUseCase
- func (uc *PostUseCase) Create(ctx context.Context, p *Post) (*Post, error)
- func (uc *PostUseCase) Delete(ctx context.Context, id uint32) error
- func (uc *PostUseCase) DeleteBySlug(ctx context.Context, slug string) error
- func (uc *PostUseCase) GetByID(ctx context.Context, id uint32) (*Post, error)
- func (uc *PostUseCase) GetBySlug(ctx context.Context, slug string) (*Post, error)
- func (uc *PostUseCase) List(ctx context.Context, opts *ListOptions) ([]*Post, uint32, error)
- func (uc *PostUseCase) Update(ctx context.Context, p *Post) (*Post, error)
- type Tag
- type TagRepo
- type TagUseCase
- func (uc *TagUseCase) CreateTag(c *Tag) error
- func (uc *TagUseCase) DeleteTag(id uint) error
- func (uc *TagUseCase) DeleteTagByName(name string) error
- func (uc *TagUseCase) GetAllTags() ([]*Tag, error)
- func (uc *TagUseCase) GetTagByID(id uint) (*Tag, error)
- func (uc *TagUseCase) GetTagByName(name string) (*Tag, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CategoryRepo ¶
type CategoryRepo interface { SaveCategory(*Category) error GetCategoryByID(uint) (*Category, error) GetCategoryByName(string) (*Category, error) GetAllCategories() ([]*Category, error) DeleteCategory(uint) error DeleteCategoryByName(string) error }
CategoryRepo defines the storage interface for category.
type CategoryUseCase ¶
type CategoryUseCase struct {
// contains filtered or unexported fields
}
CategoryUseCase defines the use case for category.
func NewCategoryUseCase ¶
func NewCategoryUseCase(repo CategoryRepo, logger log.Logger) *CategoryUseCase
NewCategoryUseCase creates a new CategoryUseCase.
func (*CategoryUseCase) CreateCategory ¶
func (uc *CategoryUseCase) CreateCategory(c *Category) error
CreateCategory creates a new category.
func (*CategoryUseCase) DeleteCategory ¶
func (uc *CategoryUseCase) DeleteCategory(id uint) error
DeleteCategory deletes a category by its ID.
func (*CategoryUseCase) DeleteCategoryByName ¶
func (uc *CategoryUseCase) DeleteCategoryByName(name string) error
DeleteCategoryByName deletes a category by its name.
func (*CategoryUseCase) GetAllCategories ¶
func (uc *CategoryUseCase) GetAllCategories() ([]*Category, error)
GetAllCategories gets all categories.
func (*CategoryUseCase) GetCategoryByID ¶
func (uc *CategoryUseCase) GetCategoryByID(id uint) (*Category, error)
GetCategoryByID gets a category by its ID.
func (*CategoryUseCase) GetCategoryByName ¶
func (uc *CategoryUseCase) GetCategoryByName(name string) (*Category, error)
GetCategoryByName gets a category by its name.
type CommentRepo ¶
type CommentRepo interface { SaveComment(*Comment) error GetCommentsByID(uint) ([]*Comment, error) // if the comment has children, its children will be returned as well GetPostCommentsByPostID(uint) ([]*Comment, error) DeleteComment(uint) error // if the comment has children, its children will be deleted as well }
CommentRepo defines the storage interface for comment.
type CommentUseCase ¶
type CommentUseCase struct {
// contains filtered or unexported fields
}
CommentUseCase defines the use case for comment.
func NewCommentUseCase ¶
func NewCommentUseCase(repo CommentRepo, logger log.Logger) *CommentUseCase
func (*CommentUseCase) CreateComment ¶
func (uc *CommentUseCase) CreateComment(c *Comment) error
func (*CommentUseCase) DeleteComment ¶
func (uc *CommentUseCase) DeleteComment(id uint) error
func (*CommentUseCase) GetCommentsByID ¶
func (uc *CommentUseCase) GetCommentsByID(id uint) ([]*Comment, error)
func (*CommentUseCase) GetPostCommentsByPostID ¶
func (uc *CommentUseCase) GetPostCommentsByPostID(id uint) ([]*Comment, error)
type ListOptions ¶
type ListOptions struct { Page uint32 PageSize uint32 Author string Category string Status string Slug string }
ListOptions 定义列表查询选项
type PostRepo ¶
type PostRepo interface { // 创建文章 CreatePost(ctx context.Context, post *Post) (*Post, error) // 更新文章 UpdatePost(ctx context.Context, post *Post) (*Post, error) // 根据 ID 获取文章 GetPostByID(ctx context.Context, id uint32) (*Post, error) // 根据 Slug 获取文章 GetPostBySlug(ctx context.Context, slug string) (*Post, error) // 列出文章 ListPosts(ctx context.Context, opts *ListOptions) ([]*Post, uint32, error) // 删除文章 DeletePost(ctx context.Context, id uint32) error // 根据 Slug 删除文章 DeletePostBySlug(ctx context.Context, slug string) error }
PostRepo defines the storage interface for post.
type PostUseCase ¶
type PostUseCase struct {
// contains filtered or unexported fields
}
PostUseCase defines the use case for post.
func NewPostUseCase ¶
func NewPostUseCase(repo PostRepo, logger log.Logger) *PostUseCase
func (*PostUseCase) Delete ¶
func (uc *PostUseCase) Delete(ctx context.Context, id uint32) error
Delete 删除文章
func (*PostUseCase) DeleteBySlug ¶
func (uc *PostUseCase) DeleteBySlug(ctx context.Context, slug string) error
DeleteBySlug 根据 Slug 删除文章
func (*PostUseCase) List ¶
func (uc *PostUseCase) List(ctx context.Context, opts *ListOptions) ([]*Post, uint32, error)
List 列出文章
type TagRepo ¶
type TagRepo interface { SaveTag(*Tag) error GetTagByID(uint) (*Tag, error) GetTagByName(string) (*Tag, error) GetAllTags() ([]*Tag, error) DeleteTag(uint) error DeleteTagByName(string) error }
TagRepo defines the storage interface for tag.
type TagUseCase ¶
type TagUseCase struct {
// contains filtered or unexported fields
}
TagUseCase defines the use case for tag.
func NewTagUseCase ¶
func NewTagUseCase(repo TagRepo, logger log.Logger) *TagUseCase
func (*TagUseCase) CreateTag ¶
func (uc *TagUseCase) CreateTag(c *Tag) error
func (*TagUseCase) DeleteTag ¶
func (uc *TagUseCase) DeleteTag(id uint) error
func (*TagUseCase) DeleteTagByName ¶
func (uc *TagUseCase) DeleteTagByName(name string) error
func (*TagUseCase) GetAllTags ¶
func (uc *TagUseCase) GetAllTags() ([]*Tag, error)
func (*TagUseCase) GetTagByID ¶
func (uc *TagUseCase) GetTagByID(id uint) (*Tag, error)
func (*TagUseCase) GetTagByName ¶
func (uc *TagUseCase) GetTagByName(name string) (*Tag, error)