feat(bookmark): 初始化书签服务并配置路由与权限控制
新增书签服务主程序,使用 Gin 框架搭建 HTTP 服务器,并注册书签相关接口处理器。 配置 CORS 中间件以支持跨域请求。服务监听端口为 8081。 feat(user_np): 初始化用户权限服务并注册认证接口 新增用户权限服务主程序,使用 Gin 框架搭建 HTTP 服务器,并注册登录、注册及修改密码等接口处理器。 服务监听端口为 8082。 refactor(config): 重构 OpenAPI 配置文件结构并拆分模块 将原有合并的 OpenAPI 配置文件按功能模块拆分为 bookmark 和 user_np 两个独立目录, 分别管理各自的 server、client 及 API 定义文件,便于后续维护和扩展。 refactor(vfs): 调整虚拟文件系统 API 接口路径与参数定义 更新 VFS API 配置文件,修改部分接口路径及参数结构, 如将文件路径参数由 path 转为 query 参数,并优化响应结构体定义。
This commit is contained in:
@ -6,50 +6,14 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Bookmark 书签结构体
|
||||
type Bookmark struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey"`
|
||||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ExternalID int64 `json:"external_id" gorm:"uniqueIndex;not null"`
|
||||
Name string `json:"name" gorm:"not null;index;size:255"`
|
||||
Link *string `json:"link" gorm:"type:url"`
|
||||
Detail *string `json:"detail" gorm:"type:text"`
|
||||
Description *string `json:"description" gorm:"type:text"`
|
||||
ParentID int64 `json:"parent_id" gorm:"not null;index"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
}
|
||||
|
||||
// Folder 文件夹结构体
|
||||
type Folder struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey"`
|
||||
Name string `json:"name" gorm:"not null;index;size:255"`
|
||||
ParentID *int64 `json:"parent_id" gorm:"index"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
}
|
||||
|
||||
// IsValidParent 检查父文件夹ID是否有效
|
||||
func (f *Folder) IsValidParent(db *gorm.DB, parentID int64) bool {
|
||||
// 检查父文件夹是否存在且未被删除
|
||||
if err := db.Where("id = ?", parentID).First(&Folder{}).Error; err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// 防止循环引用(不能将文件夹设置为自己的子文件夹)
|
||||
if parentID == f.ID {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// IsValidParent 检查书签的父文件夹ID是否有效
|
||||
func (b *Bookmark) IsValidParent(db *gorm.DB, parentID int64) bool {
|
||||
// 检查父文件夹是否存在且未被删除
|
||||
if err := db.Where("id = ?", parentID).First(&Folder{}).Error; err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user