move files into folders

This commit is contained in:
m
2026-07-13 17:07:00 +02:00
parent 07b03562b1
commit 04b6dfc6d4
8 changed files with 204 additions and 4 deletions
+45
View File
@@ -197,3 +197,48 @@ func (h *FileHandler) GetTags(c *gin.Context) {
}
api.Success(c, tags)
}
func (h *FileHandler) MoveFiles(c *gin.Context) {
var body struct {
FileIDs []string `json:"file_ids" binding:"required"`
ParentFileID *string `json:"parent_file_id"`
}
if err := c.ShouldBindJSON(&body); err != nil {
api.Error(c, http.StatusBadRequest, "INVALID_BODY", "Body must contain 'file_ids' array")
return
}
if err := h.files.MoveFiles(body.FileIDs, body.ParentFileID); err != nil {
api.Error(c, http.StatusInternalServerError, "DB_ERROR", "Failed to move files")
return
}
api.Success(c, gin.H{"moved": len(body.FileIDs)})
}
func (h *FileHandler) ListFolders(c *gin.Context) {
folders, err := h.files.ListFolders()
if err != nil {
api.Error(c, http.StatusInternalServerError, "DB_ERROR", "Failed to list folders")
return
}
api.Success(c, folders)
}
func (h *FileHandler) CreateFolder(c *gin.Context) {
var body struct {
Name string `json:"name" binding:"required"`
}
if err := c.ShouldBindJSON(&body); err != nil {
api.Error(c, http.StatusBadRequest, "INVALID_BODY", "Body must contain 'name'")
return
}
folder, err := h.files.CreateFolder(body.Name)
if err != nil {
api.Error(c, http.StatusInternalServerError, "DB_ERROR", "Failed to create folder")
return
}
api.Success(c, folder)
}
+4 -1
View File
@@ -9,9 +9,12 @@ func SetupRoutes(r *gin.Engine, h *Handler) {
api.GET("/files", h.File.List)
api.POST("/files/upload", h.File.Upload)
api.POST("/files/move", h.File.MoveFiles)
api.POST("/files/folders", h.File.CreateFolder)
api.GET("/files/folders", h.File.ListFolders)
api.GET("/files/download/:id", h.File.Download)
api.GET("/files/:id", h.File.Get)
api.DELETE("/files/:id", h.File.Delete)
api.GET("/files/:id", h.File.Get)
api.POST("/files/:id/tags", h.File.AddTags)
api.GET("/files/:id/tags", h.File.GetTags)