优化页面、修复BUG
This commit is contained in:
@@ -54,20 +54,21 @@ func (p *Post) BeforeUpdate(tx *gorm.DB) error {
|
||||
|
||||
// PostResponse 博客文章响应模型
|
||||
type PostResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
CategoryID uint `json:"categoryId"`
|
||||
CategoryName string `json:"categoryName"`
|
||||
CategorySlug string `json:"categorySlug"`
|
||||
ColumnID *uint `json:"columnId,omitempty"`
|
||||
ColumnName string `json:"columnName,omitempty"`
|
||||
ColumnSlug string `json:"columnSlug,omitempty"`
|
||||
Date string `json:"date"`
|
||||
Excerpt string `json:"excerpt,omitempty"`
|
||||
Content *string `json:"content,omitempty"` // 使用指针类型,当 includeContent=true 时总是设置
|
||||
Tags []Tag `json:"tags,omitempty"`
|
||||
IsPublished int `json:"isPublished,omitempty"`
|
||||
ReadCount uint `json:"readCount,omitempty"`
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
CategoryID uint `json:"categoryId"`
|
||||
CategoryName string `json:"categoryName"`
|
||||
CategorySlug string `json:"categorySlug"`
|
||||
ColumnID *uint `json:"columnId,omitempty"`
|
||||
ColumnName string `json:"columnName,omitempty"`
|
||||
ColumnSlug string `json:"columnSlug,omitempty"`
|
||||
Date string `json:"date"`
|
||||
Excerpt string `json:"excerpt,omitempty"`
|
||||
Content *string `json:"content,omitempty"` // 使用指针类型,当 includeContent=true 时总是设置
|
||||
Tags []Tag `json:"tags,omitempty"`
|
||||
IsPublished int `json:"isPublished,omitempty"`
|
||||
ReadCount uint `json:"readCount,omitempty"`
|
||||
Snippets []SnippetBrief `json:"snippets,omitempty"`
|
||||
}
|
||||
|
||||
// PostHistory 文章历史记录模型
|
||||
|
||||
27
server/models/post_snippet.go
Normal file
27
server/models/post_snippet.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package models
|
||||
|
||||
// PostSnippet 文章与代码片段关联
|
||||
type PostSnippet struct {
|
||||
PostID uint `json:"postId" gorm:"primaryKey;column:post_id"`
|
||||
SnippetID uint `json:"snippetId" gorm:"primaryKey;column:snippet_id"`
|
||||
SortOrder uint `json:"sortOrder" gorm:"column:sort_order;default:0"`
|
||||
CreatedAt int64 `json:"createdAt" gorm:"column:created_at;default:0"`
|
||||
}
|
||||
|
||||
func (PostSnippet) TableName() string {
|
||||
return "post_snippets"
|
||||
}
|
||||
|
||||
// PostBrief 文章简要信息
|
||||
type PostBrief struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// SnippetBrief 代码片段简要信息
|
||||
type SnippetBrief struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
CodeType *CodeTypeResponse `json:"codeType,omitempty"`
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
// Snippet 代码片段模型
|
||||
type Snippet struct {
|
||||
ID string `json:"id" gorm:"primaryKey;column:id"`
|
||||
ID uint `json:"id" gorm:"primaryKey;column:id;autoIncrement"`
|
||||
Title string `json:"title" gorm:"column:title"`
|
||||
Code string `json:"code" gorm:"column:code;type:text"`
|
||||
Type string `json:"type" gorm:"column:type"`
|
||||
@@ -48,7 +48,7 @@ func (s *Snippet) BeforeUpdate(tx *gorm.DB) error {
|
||||
|
||||
// SnippetResponse 代码片段响应模型
|
||||
type SnippetResponse struct {
|
||||
ID string `json:"id"`
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Code string `json:"code"`
|
||||
Type string `json:"type"`
|
||||
@@ -56,4 +56,5 @@ type SnippetResponse struct {
|
||||
CodeType *CodeTypeResponse `json:"codeType,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ViewCount uint `json:"viewCount,omitempty"`
|
||||
Posts []PostBrief `json:"posts,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user