feat(api): prepare for svc implemention
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"net/url"
|
||||
"octopus/internal/dal"
|
||||
"octopus/internal/schema"
|
||||
"time"
|
||||
|
||||
"github.com/rs/xid"
|
||||
@@ -25,31 +26,58 @@ type DocFolder struct {
|
||||
func (*DocFolder) TableName() string {
|
||||
return TableNameDocFolder
|
||||
}
|
||||
func (df *DocFolder) BeforeCreate(*gorm.DB) error {
|
||||
df.ID = xid.New().String()
|
||||
|
||||
func (df *DocFolder) ToSchema() *schema.DocFolder {
|
||||
return &schema.DocFolder{
|
||||
ID: df.ID,
|
||||
IsDeletable: df.IsDeletable,
|
||||
IsEditable: df.IsEditable,
|
||||
CreatedAt: df.CreatedAt,
|
||||
UpdatedAt: df.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DocFolder) BeforeCreate(*gorm.DB) error {
|
||||
d.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
|
||||
ObjectName string `gorm:"column:object_name;type:varchar"` // 对象存储中对应的object_name
|
||||
CreatedBy string `gorm:"column:created_by;type:varchar;not null"` // 创建人
|
||||
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
|
||||
ObjectName string `gorm:"column:object_name;type:varchar"` // 对象存储中对应的object_name
|
||||
UploadedAt time.Time `gorm:"column:uploaded_at;type:datetime"` // 上传时间
|
||||
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) {
|
||||
return dal.GetStorage().PresignedGetObject(ctx, df.ObjectName, time.Hour)
|
||||
func (d *Doc) ToSchema(ctx context.Context) *schema.Doc {
|
||||
url, _ := d.PresignedURL(ctx)
|
||||
|
||||
return &schema.Doc{
|
||||
ID: d.ID,
|
||||
Folder: d.Folder.ToSchema(),
|
||||
PresignedURL: url,
|
||||
IsDeletable: d.IsDeletable,
|
||||
IsEditable: d.IsEditable,
|
||||
UploadedAt: d.UploadedAt,
|
||||
CreatedAt: d.CreatedAt,
|
||||
UpdatedAt: d.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Doc) PresignedURL(ctx context.Context) (*url.URL, error) {
|
||||
return dal.GetStorage().PresignedGetObject(ctx, d.ObjectName, time.Hour)
|
||||
}
|
||||
|
||||
func (*Doc) TableName() string {
|
||||
return TableNameDocFolder
|
||||
}
|
||||
func (df *Doc) BeforeCreate(*gorm.DB) error {
|
||||
df.ID = xid.New().String()
|
||||
func (d *Doc) BeforeCreate(*gorm.DB) error {
|
||||
d.ID = xid.New().String()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user