Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
36
cloud/maplefile-backend/internal/repo/collection/restore.go
Normal file
36
cloud/maplefile-backend/internal/repo/collection/restore.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// monorepo/cloud/maplefile-backend/internal/maplefile/repo/collection/restore.go
|
||||
package collection
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
dom_collection "codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/domain/collection"
|
||||
)
|
||||
|
||||
func (impl *collectionRepositoryImpl) Restore(ctx context.Context, id gocql.UUID) error {
|
||||
collection, err := impl.Get(ctx, id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get collection for restore: %w", err)
|
||||
}
|
||||
|
||||
if collection == nil {
|
||||
return fmt.Errorf("collection not found")
|
||||
}
|
||||
|
||||
// Validate state transition
|
||||
if err := dom_collection.IsValidStateTransition(collection.State, dom_collection.CollectionStateActive); err != nil {
|
||||
return fmt.Errorf("invalid state transition: %w", err)
|
||||
}
|
||||
|
||||
// Update collection state
|
||||
collection.State = dom_collection.CollectionStateActive
|
||||
collection.ModifiedAt = time.Now()
|
||||
collection.Version++
|
||||
collection.TombstoneVersion = 0
|
||||
collection.TombstoneExpiry = time.Time{}
|
||||
|
||||
return impl.Update(ctx, collection)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue