Feat: list objects in specific path

This commit is contained in:
HFO4
2019-11-24 13:06:15 +08:00
parent a89c3cb11a
commit b431f3674c
8 changed files with 144 additions and 15 deletions

View File

@@ -31,6 +31,13 @@ func (file *File) Create() (uint, error) {
// GetFileByPathAndName 给定路径、文件名、用户ID查找文件
func GetFileByPathAndName(path string, name string, uid uint) (File, error) {
var file File
result := DB.Where("user_id = ? AND dir = ? AND name=?", uid, path, name).Find(&file)
result := DB.Where("user_id = ? AND dir = ? AND name=?", uid, path, name).First(&file)
return file, result.Error
}
// GetChildFile 查找目录下子文件 TODO:test
func (folder *Folder) GetChildFile() ([]File, error) {
var files []File
result := DB.Where("folder_id = ?", folder.ID).Find(&files)
return files, result.Error
}

View File

@@ -16,7 +16,7 @@ type Folder struct {
PositionAbsolute string `gorm:"size:65536"`
}
// Create 创建目录
// Create 创建目录 TODO:test
func (folder *Folder) Create() (uint, error) {
if err := DB.Create(folder).Error; err != nil {
util.Log().Warning("无法插入目录记录, %s", err)
@@ -28,6 +28,13 @@ func (folder *Folder) Create() (uint, error) {
// GetFolderByPath 根据绝对路径和UID查找目录
func GetFolderByPath(path string, uid uint) (Folder, error) {
var folder Folder
result := DB.Where("owner_id = ? AND position_absolute = ?", uid, path).Find(&folder)
result := DB.Where("owner_id = ? AND position_absolute = ?", uid, path).First(&folder)
return folder, result.Error
}
// GetChildFolder 查找子目录 TODO:test
func (folder *Folder) GetChildFolder() ([]Folder, error) {
var folders []Folder
result := DB.Where("parent_id = ?", folder.ID).Find(&folders)
return folders, result.Error
}