oc-lib/models/utils/abstracts.go
2024-07-18 13:35:14 +02:00

32 lines
875 B
Go

package utils
import (
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/logs"
"github.com/rs/zerolog"
)
type AbstractAccessor struct {
Logger zerolog.Logger
}
func (dma *AbstractAccessor) SetLogger() {
dma.Logger = logs.CreateLogger("oclib", "")
}
func (dma *AbstractAccessor) GenericDeleteOne(id string, accessor Accessor) DBObject {
res := accessor.LoadOne(id)
_, err := mongo.MONGOService.DeleteOne(id, "data")
if err != nil {
dma.Logger.Error().Msg("Could not delete " + id + " to db. Error: " + err.Error())
}
return res
}
func (dma *AbstractAccessor) GenericUpdateOne(set map[string]interface{}, id string, accessor Accessor) DBObject {
id, err := mongo.MONGOService.UpdateOne(set, id, "data")
if err != nil {
dma.Logger.Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
}
return accessor.LoadOne(id)
}