add history

This commit is contained in:
mr
2024-10-02 11:35:22 +02:00
parent 3c1a84011e
commit 93903b4938
23 changed files with 140 additions and 63 deletions

View File

@@ -50,7 +50,7 @@ func (d *CollaborativeArea) GetName() string {
func (d *CollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor
data.Init(utils.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type
data.Init(tools.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type
return data
}

View File

@@ -32,7 +32,7 @@ func (d *Rule) GetName() string {
func (d *Rule) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New()
data.Init(utils.RULE, caller)
data.Init(tools.RULE, caller)
return data
}

View File

@@ -37,7 +37,7 @@ func (d *ShallowCollaborativeArea) GetName() string {
func (d *ShallowCollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New()
data.Init(utils.COLLABORATIVE_AREA, caller)
data.Init(tools.COLLABORATIVE_AREA, caller)
return data
}

View File

@@ -34,7 +34,7 @@ func (d *Workspace) GetName() string {
func (d *Workspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor
data.Init(utils.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
data.Init(tools.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
return data
}

View File

@@ -0,0 +1,34 @@
package workspace
import (
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
"github.com/google/uuid"
)
type WorkspaceHistory struct{ Workspace }
func (d *WorkspaceHistory) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor
data.Init(tools.WORKSPACE_HISTORY, caller) // Initialize the accessor with the WORKSPACE model type
return data
}
func (r *WorkspaceHistory) GenerateID() {
r.UUID = uuid.New().String()
}
// Workspace is a struct that represents a workspace
type workspaceHistoryMongoAccessor struct {
workspaceMongoAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
}
// New creates a new instance of the workspaceMongoAccessor
func NewHistory() *workspaceHistoryMongoAccessor {
return &workspaceHistoryMongoAccessor{}
}
func (r *workspaceHistoryMongoAccessor) MapFromWorkspace(w *Workspace) *WorkspaceHistory {
wh := &WorkspaceHistory{Workspace: *w}
wh.GenerateID()
return wh
}

View File

@@ -221,6 +221,8 @@ func (wfa *workspaceMongoAccessor) share(realData *Workspace, delete bool, calle
continue
}
if delete { // If the workspace is deleted, share the deletion
history := NewHistory()
history.StoreOne(history.MapFromWorkspace(res.(*Workspace)))
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
} else { // If the workspace is updated, share the update
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.PUT, res.Serialize(), caller)