From f2082dec6dd347935313897edb37023788636792 Mon Sep 17 00:00:00 2001 From: yumaojun03 <719118794@qq.com> Date: Sun, 1 Dec 2024 16:05:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85blog=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vblog/apps/blog/enum.go | 8 ++ vblog/apps/blog/interface.go | 25 +++++- vblog/apps/blog/model.go | 45 +++++++++++ vblog/docs/page.drawio | 142 ++++++++++++++++++++++------------- vblog/utils/page.go | 8 ++ vblog/utils/resource.go | 2 + 6 files changed, 174 insertions(+), 56 deletions(-) create mode 100644 vblog/apps/blog/enum.go create mode 100644 vblog/apps/blog/model.go create mode 100644 vblog/utils/page.go diff --git a/vblog/apps/blog/enum.go b/vblog/apps/blog/enum.go new file mode 100644 index 0000000..b8ee1ab --- /dev/null +++ b/vblog/apps/blog/enum.go @@ -0,0 +1,8 @@ +package blog + +type STAGE int + +const ( + STAGE_DRAFT STAGE = iota + STAGE_PUBLISHED +) diff --git a/vblog/apps/blog/interface.go b/vblog/apps/blog/interface.go index bdb260e..7599cdd 100644 --- a/vblog/apps/blog/interface.go +++ b/vblog/apps/blog/interface.go @@ -1,10 +1,16 @@ package blog +import ( + "context" + + "gitlab.com/go-course-project/go17/vblog/utils" +) + type Service interface { // 创建博客 - CreateBlog() + CreateBlog(context.Context, *CreateBlogRequest) (*Blog, error) // 博客列表查询 - QueryBlog() + QueryBlog(context.Context, *QueryBlogRequest) (*BlogSet, error) // 博客详情查询 DescribeBlog() // 博客编辑 @@ -14,3 +20,18 @@ type Service interface { // 删除 DeleteBlog() } + +type QueryBlogRequest struct { + // 分页参数 + utils.PageRequest + // 文章标题模糊匹配, Golang + Keywords string `json:"keywords"` + // 状态过滤参数, 作者:nil, 访客: STAGE_PUBLISHED + Stage *STAGE `json:"stage"` + // 查询某个用户具体的文章: 给作者用的 + Username string `json:"username"` + // 分类 + Category string `json:"category"` + // 查询Tag相关的文章 + Tags map[string]string `json:"tag"` +} diff --git a/vblog/apps/blog/model.go b/vblog/apps/blog/model.go new file mode 100644 index 0000000..9ad229e --- /dev/null +++ b/vblog/apps/blog/model.go @@ -0,0 +1,45 @@ +package blog + +import ( + "time" + + "gitlab.com/go-course-project/go17/vblog/utils" +) + +type BlogSet struct { + Total int32 `json:"total"` + Items []*Blog `json:"items"` +} + +type Blog struct { + // 存放到数据里的对象的远数据信息 + utils.ResourceMeta + // 创建是的具体信息 + CreateBlogRequest + // 文章状态 + Status +} + +func (t *Blog) TableName() string { + return "blogs" +} + +type CreateBlogRequest struct { + // 标题 + Title string `json:"title" gorm:"column:title;type:varchar(200)"` + // 摘要 + Summary string `json:"summary" gorm:"column:summary;type:text"` + // 内容 + Content string `json:"content" gorm:"column:content;type:text"` + // 分类 + Category string `json:"category" gorm:"column:category;type:text"` + // 标签 + Tags map[string]string `json:"tags" gorm:"column:tags;serializer:json"` +} + +type Status struct { + // 0: 草稿, 1: 已发布, 2: 审核 ... + Stage STAGE `json:"stage" gorm:"column:stage;type:tinyint(1)"` + // 状态变化的时间, 拿发布时间 + ChangeAt *time.Time `json:"change_at" gorm:"column:change_at"` +} diff --git a/vblog/docs/page.drawio b/vblog/docs/page.drawio index 6800ecc..3dd60f6 100644 --- a/vblog/docs/page.drawio +++ b/vblog/docs/page.drawio @@ -1,10 +1,10 @@ - + - + @@ -13,7 +13,7 @@ - + @@ -25,43 +25,43 @@ - + - + - - + + - + - + - + - + - + - + - + - + - + - + @@ -69,119 +69,153 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vblog/utils/page.go b/vblog/utils/page.go new file mode 100644 index 0000000..bdc7b4c --- /dev/null +++ b/vblog/utils/page.go @@ -0,0 +1,8 @@ +package utils + +type PageRequest struct { + // 分页大小 + PageSize uint `json:"page_size"` + // 当前是多少页面 + PageNumber uint `json:"page_number"` +} diff --git a/vblog/utils/resource.go b/vblog/utils/resource.go index 9b359d7..23bc14a 100644 --- a/vblog/utils/resource.go +++ b/vblog/utils/resource.go @@ -7,6 +7,8 @@ type ResourceMeta struct { Id uint `json:"id" gorm:"primaryKey;column:id"` // 创建时间 CreatedAt time.Time `json:"created_at" gorm:"column:created_at;not null"` + // 用户名称 + CreateBy string `json:"create_by" gorm:"column:create_by;type:varchar(100)"` // 更新时间 UpdatedAt *time.Time `json:"updated_at" gorm:"column:updated_at"` }