textualize/core/Document/DocumentCollection.go
2023-01-04 22:19:02 -06:00

48 lines
1020 B
Go

package document
type DocumentCollection struct {
Documents []Entity
ProjectId string
}
var documentCollectionInstance *DocumentCollection
func GetDocumentCollection() *DocumentCollection {
if documentCollectionInstance == nil {
documentCollectionInstance = &DocumentCollection{}
}
return documentCollectionInstance
}
func (collection *DocumentCollection) AddDocument(document Entity) {
collection.Documents = append(collection.Documents, document)
}
func (collection *DocumentCollection) GetDocumentById(id string) *Entity {
var foundDocument *Entity
for index, d := range collection.Documents {
if d.Id == id {
foundDocument = &collection.Documents[index]
break
}
}
return foundDocument
}
func (collection *DocumentCollection) GetDocumentByAreaId(areaId string) *Entity {
var foundDocument *Entity
for dIndex, d := range collection.Documents {
for _, a := range d.Areas {
if a.Id == areaId {
foundDocument = &collection.Documents[dIndex]
}
}
}
return foundDocument
}