Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b1488e347 | ||
|
|
6e3df3ffa0 | ||
|
|
9dc6c217fa | ||
|
|
c4bd121388 | ||
|
|
e26c2af201 | ||
|
|
093c55616c |
@@ -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"
|
||||||
@@ -33,6 +35,7 @@ func (aH *AccessHandler) AddWorkspace(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uid, err := uuid.NewUUID()
|
uid, err := uuid.NewUUID()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
aH.logger.Error("AddWorkspace", err)
|
aH.logger.Error("AddWorkspace", err)
|
||||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||||
@@ -51,7 +54,7 @@ func (aH *AccessHandler) AddWorkspace(c *gin.Context) {
|
|||||||
aH.dbHandler.AddNewColum(&models.Workspace{
|
aH.dbHandler.AddNewColum(&models.Workspace{
|
||||||
Name: workspace.Name,
|
Name: workspace.Name,
|
||||||
Description: workspace.Description,
|
Description: workspace.Description,
|
||||||
Uuid: uid,
|
Uuid: &uid,
|
||||||
})
|
})
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@@ -151,26 +154,76 @@ func (aH *AccessHandler) DeleteWorkspace(c *gin.Context) {
|
|||||||
c.JSON(http.StatusInternalServerError, nil)
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
if u.Settings.Workspace == workspace.Name {
|
if u.Settings.Workspace == nil {
|
||||||
u.Settings.Workspace = ""
|
continue
|
||||||
|
} else if u.Settings.Workspace.Uuid.String() == workspace.Uuid.String() {
|
||||||
|
u.Settings.Workspace = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
u.Workspaces = slices.DeleteFunc(u.Workspaces, func(w *models.Workspace) bool {
|
u.Workspaces = slices.DeleteFunc(u.Workspaces, func(w *models.Workspace) bool {
|
||||||
return w != nil && w.Name == workspace.Name
|
return w != nil && w.Name == workspace.Name
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err := aH.dbHandler.UpdateValuesById(&u, u.Id); err != nil {
|
||||||
|
aH.logger.Error("DeleteWorkspace", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// crearemove folder
|
// remove folder
|
||||||
err = os.RemoveAll(workspace.Uuid.String())
|
err = os.RemoveAll(workspace.Uuid.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
aH.logger.Error("DeleteWorkspace", err)
|
aH.logger.Error("DeleteWorkspace", err)
|
||||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||||
return
|
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 == nil {
|
||||||
|
aH.logger.Error("ReadWorkspaceData", "uuid nil")
|
||||||
|
c.JSON(http.StatusBadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(123, workspace)
|
||||||
|
files, err := os.ReadDir(workspace.Uuid.String())
|
||||||
|
fmt.Println(124, err)
|
||||||
|
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
PrimaryColor string `json:"primaryColor,omitempty"`
|
PrimaryColor string `json:"primaryColor,omitempty"`
|
||||||
PrimaryColorText string `json:"primaryColorText,omitempty"`
|
PrimaryColorText string `json:"primaryColorText,omitempty"`
|
||||||
SecondaryColor string `json:"secondaryColor,omitempty"`
|
SecondaryColor string `json:"secondaryColor,omitempty"`
|
||||||
SecondaryColorText string `json:"secondaryColorText,omitempty"`
|
SecondaryColorText string `json:"secondaryColorText,omitempty"`
|
||||||
Icon string `json:"icon,omitempty"`
|
Icon string `json:"icon,omitempty"`
|
||||||
AppName string `json:"appName,omitempty"`
|
AppName string `json:"appName,omitempty"`
|
||||||
DatabaseName string `json:"databaseName,omitempty"`
|
DatabaseName string `json:"databaseName,omitempty"`
|
||||||
DatabaseToken string `json:"databaseToken,omitempty"`
|
DatabaseToken string `json:"databaseToken,omitempty"`
|
||||||
Workspace string `json:"workspace,omitempty"`
|
Workspace *Workspace `json:"workspace,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) DefaultQuasarSettings() {
|
func (s *Settings) DefaultQuasarSettings() {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package models
|
|||||||
import "github.com/google/uuid"
|
import "github.com/google/uuid"
|
||||||
|
|
||||||
type Workspace struct {
|
type Workspace struct {
|
||||||
Id uint `gorm:"primaryKey" json:"id"`
|
Id uint `gorm:"primaryKey" json:"id"`
|
||||||
Name string `gorm:"column:name" json:"name"`
|
Name string `gorm:"column:name" json:"name"`
|
||||||
Description string `gorm:"type:json" json:"description"`
|
Description string `gorm:"type:json" json:"description"`
|
||||||
Uuid uuid.UUID `gorm:"type:text" json:"uuid"`
|
Uuid *uuid.UUID `gorm:"type:text" json:"uuid,omitempty"`
|
||||||
Users []*User `gorm:"many2many:users_workspaces;" `
|
Users []*User `gorm:"many2many:users_workspaces;" json:"-"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user