feat: docs api design
This commit is contained in:
10
internal/dal/model/base.go
Normal file
10
internal/dal/model/base.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Base struct {
|
||||
OrgID string `gorm:"column:org_id;type:varchar;primaryKey;comment:组织ID"` // 组织ID
|
||||
ID string `gorm:"column:id;type:varchar;primaryKey;comment:ID"` // ID
|
||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间"`
|
||||
}
|
||||
57
internal/dal/model/docs.go
Normal file
57
internal/dal/model/docs.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"octopus/internal/config"
|
||||
"octopus/internal/dal"
|
||||
"time"
|
||||
|
||||
"github.com/rs/xid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameDocFolder = "doc_folders"
|
||||
const TableNameDoc = "docs"
|
||||
|
||||
type DocFolder struct {
|
||||
Base
|
||||
Name string `gorm:"column:name;type:varchar;not null"` // 文件夹名称
|
||||
IsDeletable bool `gorm:"column:is_deletable;type:boolean;not null;default:true"` // 是否允许被删除
|
||||
IsEditable bool `gorm:"column:is_editable;type:boolean;not null;default:true"` // 是否允许被修改
|
||||
Path string `gorm:"column:path;type:varchar;index:idx_path"` // 路径索引
|
||||
CreatedBy string `gorm:"column:created_by;type:varchar;not null"` // 创建人
|
||||
}
|
||||
|
||||
func (*DocFolder) TableName() string {
|
||||
return TableNameDocFolder
|
||||
}
|
||||
func (df *DocFolder) BeforeCreate(*gorm.DB) error {
|
||||
df.ID = xid.New().String()
|
||||
return nil
|
||||
}
|
||||
|
||||
type Doc struct {
|
||||
Base
|
||||
Name string `gorm:"column:name;type:varchar;not null"` // 文件夹名称
|
||||
IsDeletable bool `gorm:"column:is_deletable;type:boolean;not null;default:true"` // 是否允许被删除
|
||||
IsEditable bool `gorm:"column:is_editable;type:boolean;not null;default:true"` // 是否允许编辑名称
|
||||
FolderID string `gorm:"column:folder_id;type:varchar;index:idx_folder_id"` // 文件夹ID
|
||||
OSSObjectID string `gorm:"column:oss_object_id;type:varchar"` // OSS Object ID
|
||||
CreatedBy string `gorm:"column:created_by;type:varchar;not null"` // 创建人
|
||||
|
||||
Folder *DocFolder `gorm:"foreignKey:FolderID;references:ID"`
|
||||
}
|
||||
|
||||
func (df *Doc) PresignedURL(ctx context.Context) (*url.URL, error) {
|
||||
bucket := config.Get().GetOSSConfig().Bucket
|
||||
return dal.GetMinio().PresignedGetObject(ctx, bucket, df.OSSObjectID, time.Hour, nil)
|
||||
}
|
||||
|
||||
func (*Doc) TableName() string {
|
||||
return TableNameDocFolder
|
||||
}
|
||||
func (df *Doc) BeforeCreate(*gorm.DB) error {
|
||||
df.ID = xid.New().String()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user