add new uuid for workspace and create uuid folder
This commit is contained in:
2
go.mod
2
go.mod
@@ -8,6 +8,7 @@ require (
|
|||||||
github.com/gin-gonic/gin v1.11.0
|
github.com/gin-gonic/gin v1.11.0
|
||||||
github.com/go-playground/assert/v2 v2.2.0
|
github.com/go-playground/assert/v2 v2.2.0
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0
|
github.com/golang-jwt/jwt/v5 v5.3.0
|
||||||
|
github.com/google/uuid v1.3.0
|
||||||
golang.org/x/crypto v0.43.0
|
golang.org/x/crypto v0.43.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +26,6 @@ require (
|
|||||||
github.com/go-playground/validator/v10 v10.27.0 // indirect
|
github.com/go-playground/validator/v10 v10.27.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/goccy/go-yaml v1.18.0 // indirect
|
github.com/goccy/go-yaml v1.18.0 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gitea.tecamino.com/paadi/access-handler/models"
|
"gitea.tecamino.com/paadi/access-handler/models"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (aH *AccessHandler) AddWorkspaceTable() error {
|
func (aH *AccessHandler) AddWorkspaceTable() error {
|
||||||
@@ -30,10 +32,26 @@ func (aH *AccessHandler) AddWorkspace(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uid, err := uuid.NewUUID()
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("AddWorkspace", err)
|
||||||
|
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// create new folder
|
||||||
|
err = os.MkdirAll(uid.String(), 0644)
|
||||||
|
if err != nil {
|
||||||
|
aH.logger.Error("AddWorkspace", err)
|
||||||
|
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Insert new workspace with provided permissions
|
// Insert new workspace with provided permissions
|
||||||
aH.dbHandler.AddNewColum(&models.Workspace{
|
aH.dbHandler.AddNewColum(&models.Workspace{
|
||||||
Name: workspace.Name,
|
Name: workspace.Name,
|
||||||
Description: workspace.Description,
|
Description: workspace.Description,
|
||||||
|
Uuid: uid,
|
||||||
})
|
})
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
|
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"`
|
||||||
Users []*User `gorm:"many2many:users_workspaces;" `
|
Users []*User `gorm:"many2many:users_workspaces;" `
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user