2024-07-18 11:51:12 +02:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2024-07-18 13:35:14 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/logs"
|
2024-07-18 11:51:12 +02:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AbstractAccessor struct {
|
|
|
|
Logger zerolog.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dma *AbstractAccessor) SetLogger() {
|
2024-07-18 13:35:14 +02:00
|
|
|
dma.Logger = logs.CreateLogger("oclib", "")
|
2024-07-18 11:51:12 +02:00
|
|
|
}
|
|
|
|
func (dma *AbstractAccessor) GenericDeleteOne(id string, accessor Accessor) DBObject {
|
|
|
|
res := accessor.LoadOne(id)
|
2024-07-18 13:35:14 +02:00
|
|
|
_, err := mongo.MONGOService.DeleteOne(id, "data")
|
2024-07-18 11:51:12 +02:00
|
|
|
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 {
|
2024-07-18 13:35:14 +02:00
|
|
|
id, err := mongo.MONGOService.UpdateOne(set, id, "data")
|
2024-07-18 11:51:12 +02:00
|
|
|
if err != nil {
|
|
|
|
dma.Logger.Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
|
|
|
|
}
|
|
|
|
return accessor.LoadOne(id)
|
|
|
|
}
|