oc-lib/data/data_mongo_accessor.go
2024-07-17 17:48:20 +02:00

38 lines
691 B
Go

package data
import (
logger "oc-lib/logs"
mongo "oc-lib/mongo"
)
type DataMongoAccessor struct{
}
func (dma *DataMongoAccessor) StoreOne(data Data) string {
id, err := mongo.StoreOne(data,"data")
if err != nil{
l := logger.CreateLogger("oclib","")
l.Error().Msg("Could not store " + data.Name + " to db. Error: " + err.Error())
return ""
}
return id
}
func (dma *DataMongoAccessor) LoadOne(id string) Data {
var data Data
res_mongo, err := mongo.LoadOne(id,"data")
if err != nil{
l := logger.CreateLogger("oclib","")
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return Data{}
}
res_mongo.Decode(&data)
return data
}