优化页面、修复BUG
This commit is contained in:
43
server/models/code_type.go
Normal file
43
server/models/code_type.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CodeType 代码类型
|
||||
type CodeType struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;column:id"`
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
Category int `json:"category" gorm:"column:category"` // 0前端 1后端 2其他
|
||||
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"`
|
||||
UpdatedAt int64 `json:"updatedAt" gorm:"column:updated_at"`
|
||||
DeletedAt int64 `json:"deletedAt" gorm:"column:deleted_at;default:0"`
|
||||
}
|
||||
|
||||
func (CodeType) TableName() string {
|
||||
return "code_types"
|
||||
}
|
||||
|
||||
func (c *CodeType) BeforeCreate(tx *gorm.DB) error {
|
||||
now := time.Now().Unix()
|
||||
if c.CreatedAt == 0 {
|
||||
c.CreatedAt = now
|
||||
}
|
||||
if c.UpdatedAt == 0 {
|
||||
c.UpdatedAt = now
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *CodeType) BeforeUpdate(tx *gorm.DB) error {
|
||||
c.UpdatedAt = time.Now().Unix()
|
||||
return nil
|
||||
}
|
||||
|
||||
type CodeTypeResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Category int `json:"category"`
|
||||
}
|
||||
@@ -15,6 +15,7 @@ type OperationLog struct {
|
||||
Region string `json:"region" gorm:"column:region"` // IP归属地
|
||||
Path string `json:"path" gorm:"column:path;index"`
|
||||
Method string `json:"method" gorm:"column:method"`
|
||||
Action string `json:"action" gorm:"column:action;index"`
|
||||
Params string `json:"params" gorm:"column:params;type:text"`
|
||||
Status int `json:"status" gorm:"column:status"`
|
||||
Duration int `json:"duration" gorm:"column:duration"`
|
||||
|
||||
@@ -118,21 +118,24 @@ func (ph *PostHistory) BeforeCreate(tx *gorm.DB) error {
|
||||
|
||||
// PostHistoryResponse 文章历史记录响应模型
|
||||
type PostHistoryResponse struct {
|
||||
ID uint `json:"id"`
|
||||
PostID uint `json:"postId"`
|
||||
Version int `json:"version"`
|
||||
Title string `json:"title"`
|
||||
CategoryID uint `json:"categoryId"`
|
||||
CategoryName string `json:"categoryName,omitempty"`
|
||||
ColumnID *uint `json:"columnId,omitempty"`
|
||||
TagIDs []uint `json:"tagIds,omitempty"`
|
||||
Excerpt string `json:"excerpt,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Date string `json:"date"`
|
||||
IsPublished int `json:"isPublished"`
|
||||
ModifiedBy uint `json:"modifiedBy"`
|
||||
ModifiedAt string `json:"modifiedAt"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
ID uint `json:"id"`
|
||||
PostID uint `json:"postId"`
|
||||
Version int `json:"version"`
|
||||
Title string `json:"title"`
|
||||
CategoryID uint `json:"categoryId"`
|
||||
CategoryName string `json:"categoryName,omitempty"`
|
||||
ColumnID *uint `json:"columnId,omitempty"`
|
||||
TagIDs []uint `json:"tagIds,omitempty"`
|
||||
Excerpt string `json:"excerpt,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Date string `json:"date"`
|
||||
IsPublished int `json:"isPublished"`
|
||||
ModifiedBy uint `json:"modifiedBy"`
|
||||
ModifiedByName string `json:"modifiedByName,omitempty"`
|
||||
ColumnName string `json:"columnName,omitempty"`
|
||||
TagNames []string `json:"tagNames,omitempty"`
|
||||
ModifiedAt string `json:"modifiedAt"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
|
||||
// PostHistoryFieldDiff 字段对比结果
|
||||
|
||||
@@ -12,6 +12,7 @@ type Snippet struct {
|
||||
Title string `json:"title" gorm:"column:title"`
|
||||
Code string `json:"code" gorm:"column:code;type:text"`
|
||||
Type string `json:"type" gorm:"column:type"`
|
||||
CodeTypeID uint `json:"codeTypeId" gorm:"column:code_type_id"`
|
||||
Description string `json:"description" gorm:"column:description;type:text"`
|
||||
ViewCount uint `json:"viewCount" gorm:"column:view_count;default:0"`
|
||||
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"`
|
||||
@@ -47,8 +48,12 @@ func (s *Snippet) BeforeUpdate(tx *gorm.DB) error {
|
||||
|
||||
// SnippetResponse 代码片段响应模型
|
||||
type SnippetResponse struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Code string `json:"code"`
|
||||
Type string `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Code string `json:"code"`
|
||||
Type string `json:"type"`
|
||||
CodeTypeID uint `json:"codeTypeId,omitempty"`
|
||||
CodeType *CodeTypeResponse `json:"codeType,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ViewCount uint `json:"viewCount,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user