go17/vblog/apps/blog/interface.go

81 lines
1.9 KiB
Go
Raw Normal View History

2024-12-01 11:06:09 +08:00
package blog
2024-12-01 16:05:07 +08:00
import (
"context"
2024-12-08 16:20:18 +08:00
"strings"
2024-12-01 16:05:07 +08:00
"gitlab.com/go-course-project/go17/vblog/utils"
)
2024-12-01 11:06:09 +08:00
type Service interface {
// 创建博客
2024-12-01 16:05:07 +08:00
CreateBlog(context.Context, *CreateBlogRequest) (*Blog, error)
2024-12-01 11:06:09 +08:00
// 博客列表查询
2024-12-01 16:05:07 +08:00
QueryBlog(context.Context, *QueryBlogRequest) (*BlogSet, error)
2024-12-01 11:06:09 +08:00
// 博客详情查询
2024-12-01 17:17:51 +08:00
DescribeBlog(context.Context, *DescribeBlogRequest) (*Blog, error)
2024-12-01 11:06:09 +08:00
// 博客编辑
2024-12-01 17:17:51 +08:00
UpdateBlog(context.Context, *UpdateBlogRequest) (*Blog, error)
2024-12-01 11:06:09 +08:00
// 发布
2024-12-01 17:17:51 +08:00
PublishBlog(context.Context, *PublishBlogRequest) (*Blog, error)
2024-12-01 11:06:09 +08:00
// 删除
2024-12-01 17:17:51 +08:00
DeleteBlog(context.Context, *DeleteBlogRequest) error
}
type DeleteBlogRequest struct {
utils.GetRequest
}
type PublishBlogRequest struct {
utils.GetRequest
StatusSpec
}
type UpdateBlogRequest struct {
utils.GetRequest
CreateBlogRequest
}
type DescribeBlogRequest struct {
utils.GetRequest
2024-12-01 11:06:09 +08:00
}
2024-12-01 16:05:07 +08:00
2024-12-08 14:46:15 +08:00
func NewQueryBlogRequest() *QueryBlogRequest {
return &QueryBlogRequest{
PageRequest: *utils.NewPageRequest(),
Tags: map[string]string{},
}
}
2024-12-01 16:05:07 +08:00
type QueryBlogRequest struct {
// 分页参数
utils.PageRequest
// 文章标题模糊匹配, Golang
2024-12-08 16:20:18 +08:00
Keywords string `json:"keywords" form:"keywords"`
2024-12-01 16:05:07 +08:00
// 状态过滤参数, 作者nil, 访客: STAGE_PUBLISHED
2024-12-08 16:20:18 +08:00
Stage *STAGE `json:"stage" form:"stage"`
2024-12-01 16:05:07 +08:00
// 查询某个用户具体的文章: 给作者用的
2024-12-08 16:20:18 +08:00
CreateBy string `json:"create_by" form:"create_by"`
2024-12-01 16:05:07 +08:00
// 分类
2024-12-08 16:20:18 +08:00
Category string `json:"category" form:"category"`
2024-12-01 16:05:07 +08:00
// 查询Tag相关的文章
2024-12-08 14:46:15 +08:00
// SELECT *
// FROM my_table
// WHERE data->>'$.name' = '某个名字';
2024-12-08 16:20:18 +08:00
Tags map[string]string `json:"tag" form:"-"`
}
// tags=key=value,key=value
// key=value,key=value
// key=value
func (r *QueryBlogRequest) SetTag(tag string) {
kvItem := strings.Split(tag, ",")
for i := range kvItem {
kvString := kvItem[i]
kv := strings.Split(kvString, "=")
if len(kv) > 1 {
r.Tags[kv[0]] = strings.Join(kv[1:], "=")
}
}
2024-12-01 16:05:07 +08:00
}