textualize/storage/Local/DocumentDriver.go
Joshua Shoemaker 2963dac8a6 refact: moved storage behind interface
also better read and write methods
2023-03-28 23:50:54 -05:00

23 lines
736 B
Go

package storage
import (
"encoding/json"
entity "textualize/storage/Entities"
)
func (d LocalDriver) WriteDocumentCollection(documentCollection entity.DocumentCollection, projectName string) bool {
jsonData, _ := json.MarshalIndent(documentCollection, "", " ")
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "Documents.json")
return writeError == nil
}
func (d LocalDriver) ReadDocumentCollection(projectName string) entity.DocumentCollection {
documentCollectionData := entity.DocumentCollection{}
readError := AssignFileDataToStruct("/projects/"+projectName+"/Documents.json", &documentCollectionData)
if readError != nil {
return entity.DocumentCollection{}
}
return documentCollectionData
}