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
|
|
@ -0,0 +1,28 @@
|
|||
package collection
|
||||
|
||||
// Repository defines the data access operations for collections
|
||||
type Repository interface {
|
||||
// Create stores a new collection record
|
||||
Create(collection *Collection) error
|
||||
|
||||
// Get retrieves a collection by its ID
|
||||
Get(id string) (*Collection, error)
|
||||
|
||||
// Update modifies an existing collection record
|
||||
Update(collection *Collection) error
|
||||
|
||||
// Delete removes a collection record by its ID
|
||||
Delete(id string) error
|
||||
|
||||
// List returns all collection records
|
||||
List() ([]*Collection, error)
|
||||
|
||||
// ListByParent returns all collections with a specific parent ID
|
||||
ListByParent(parentID string) ([]*Collection, error)
|
||||
|
||||
// ListRoot returns all root-level collections (no parent)
|
||||
ListRoot() ([]*Collection, error)
|
||||
|
||||
// Exists checks if a collection with the given ID exists
|
||||
Exists(id string) (bool, error)
|
||||
}
|
||||
98
native/desktop/maplefile/internal/domain/collection/model.go
Normal file
98
native/desktop/maplefile/internal/domain/collection/model.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package collection
|
||||
|
||||
import "time"
|
||||
|
||||
// Collection represents a collection (folder/album) stored locally with sync capabilities.
|
||||
type Collection struct {
|
||||
// Identifiers (from cloud)
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id,omitempty"`
|
||||
OwnerID string `json:"owner_id"` // UserID from cloud
|
||||
|
||||
// Encryption data (from cloud)
|
||||
EncryptedCollectionKey string `json:"encrypted_collection_key"`
|
||||
Nonce string `json:"nonce"`
|
||||
|
||||
// Collection metadata (from cloud - name is decrypted client-side)
|
||||
Name string `json:"name"` // Decrypted name
|
||||
Description string `json:"description,omitempty"` // Optional description
|
||||
// CustomIcon is the decrypted custom icon for this collection.
|
||||
// Empty string means use default folder/album icon.
|
||||
// Contains either an emoji character (e.g., "📷") or "icon:<identifier>" for predefined icons.
|
||||
CustomIcon string `json:"custom_icon,omitempty"`
|
||||
|
||||
// Statistics (from cloud)
|
||||
TotalFiles int `json:"total_files"`
|
||||
TotalSizeInBytes int64 `json:"total_size_in_bytes"`
|
||||
|
||||
// Sharing info (from cloud)
|
||||
PermissionLevel string `json:"permission_level,omitempty"` // read_only, read_write, admin
|
||||
IsOwner bool `json:"is_owner"`
|
||||
OwnerName string `json:"owner_name,omitempty"`
|
||||
OwnerEmail string `json:"owner_email,omitempty"`
|
||||
|
||||
// Sync tracking (local only)
|
||||
SyncStatus SyncStatus `json:"sync_status"`
|
||||
LastSyncedAt time.Time `json:"last_synced_at,omitempty"`
|
||||
|
||||
// State from cloud
|
||||
State string `json:"state"` // active, deleted
|
||||
|
||||
// Timestamps (from cloud)
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ModifiedAt time.Time `json:"modified_at"`
|
||||
}
|
||||
|
||||
// SyncStatus defines the synchronization status of a collection
|
||||
type SyncStatus int
|
||||
|
||||
const (
|
||||
// SyncStatusCloudOnly indicates the collection metadata is synced from cloud
|
||||
SyncStatusCloudOnly SyncStatus = iota
|
||||
|
||||
// SyncStatusSynced indicates the collection is fully synchronized
|
||||
SyncStatusSynced
|
||||
)
|
||||
|
||||
// String returns a human-readable string representation of the sync status
|
||||
func (s SyncStatus) String() string {
|
||||
switch s {
|
||||
case SyncStatusCloudOnly:
|
||||
return "cloud_only"
|
||||
case SyncStatusSynced:
|
||||
return "synced"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// Collection state constants
|
||||
const (
|
||||
// StateActive indicates the collection is active
|
||||
StateActive = "active"
|
||||
|
||||
// StateDeleted indicates the collection is deleted
|
||||
StateDeleted = "deleted"
|
||||
)
|
||||
|
||||
// Permission level constants
|
||||
const (
|
||||
PermissionReadOnly = "read_only"
|
||||
PermissionReadWrite = "read_write"
|
||||
PermissionAdmin = "admin"
|
||||
)
|
||||
|
||||
// IsDeleted returns true if the collection is marked as deleted
|
||||
func (c *Collection) IsDeleted() bool {
|
||||
return c.State == StateDeleted
|
||||
}
|
||||
|
||||
// CanWrite returns true if the user has write permissions
|
||||
func (c *Collection) CanWrite() bool {
|
||||
return c.IsOwner || c.PermissionLevel == PermissionReadWrite || c.PermissionLevel == PermissionAdmin
|
||||
}
|
||||
|
||||
// CanAdmin returns true if the user has admin permissions
|
||||
func (c *Collection) CanAdmin() bool {
|
||||
return c.IsOwner || c.PermissionLevel == PermissionAdmin
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue