Milestone 3
This commit is contained in:
47
internal/storage/workstreams.go
Normal file
47
internal/storage/workstreams.go
Normal file
@ -0,0 +1,47 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.dws.rip/DWS/onyx/internal/models"
|
||||
)
|
||||
|
||||
// LoadWorkstreams loads the workstream collection from the workstreams.json file
|
||||
func LoadWorkstreams(path string) (*models.WorkstreamCollection, error) {
|
||||
// Check if file exists
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
// Return empty collection if file doesn't exist
|
||||
return models.NewWorkstreamCollection(), nil
|
||||
}
|
||||
|
||||
// Read the file
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read workstreams file: %w", err)
|
||||
}
|
||||
|
||||
// Deserialize the workstream collection
|
||||
collection, err := models.DeserializeWorkstreamCollection(data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to deserialize workstreams: %w", err)
|
||||
}
|
||||
|
||||
return collection, nil
|
||||
}
|
||||
|
||||
// SaveWorkstreams saves the workstream collection to the workstreams.json file
|
||||
func SaveWorkstreams(path string, collection *models.WorkstreamCollection) error {
|
||||
// Serialize the collection
|
||||
data, err := collection.Serialize()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to serialize workstreams: %w", err)
|
||||
}
|
||||
|
||||
// Write to file
|
||||
if err := os.WriteFile(path, data, 0644); err != nil {
|
||||
return fmt.Errorf("failed to write workstreams file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user