Compare commits

..

3 Commits

Author SHA1 Message Date
Adrian Zürcher
e26c2af201 add uuid nil check 2026-02-17 12:16:21 +01:00
Adrian Zürcher
093c55616c add new function to read files in workspace 2026-02-17 12:07:56 +01:00
Adrian Zürcher
a99189b31a add remove folder in delete workspace 2026-02-17 07:34:34 +01:00

View File

@@ -4,8 +4,10 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
"path/filepath"
"slices" "slices"
"strconv" "strconv"
"strings"
"gitea.tecamino.com/paadi/access-handler/models" "gitea.tecamino.com/paadi/access-handler/models"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -160,9 +162,54 @@ func (aH *AccessHandler) DeleteWorkspace(c *gin.Context) {
return w != nil && w.Name == workspace.Name return w != nil && w.Name == workspace.Name
}) })
} }
// crearemove folder
err = os.RemoveAll(workspace.Uuid.String())
if err != nil {
aH.logger.Error("DeleteWorkspace", err)
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
return
}
} }
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "workspace(s) deleted", "message": "workspace(s) deleted",
}) })
} }
func (aH *AccessHandler) ReadWorkspaceData(c *gin.Context) {
var workspace models.Workspace
err := c.ShouldBindBodyWithJSON(&workspace)
if err != nil {
aH.logger.Error("ReadWorkspaceData", err)
c.JSON(http.StatusBadRequest, nil)
return
}
if workspace.Uuid == uuid.Nil {
aH.logger.Error("ReadWorkspaceData", "uuid nil")
c.JSON(http.StatusBadRequest, nil)
return
}
files, err := os.ReadDir(workspace.Uuid.String())
if err != nil {
aH.logger.Error("ReadWorkspaceData", err)
c.JSON(http.StatusBadRequest, nil)
return
}
var response []string
for _, f := range files {
if f.IsDir() || !strings.Contains(filepath.Ext(f.Name()), ".db") {
continue
}
response = append(response, f.Name())
}
c.JSON(http.StatusOK, gin.H{
"data": response,
})
}