Files
oc-lib/models/live/live_mongo_accessor.go

58 lines
1.9 KiB
Go
Raw Normal View History

2025-06-24 11:29:04 +02:00
package live
import (
2026-04-08 15:40:44 +02:00
"cloud.o-forge.io/core/oc-lib/dbs"
2025-06-24 11:29:04 +02:00
"cloud.o-forge.io/core/oc-lib/logs"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
)
2026-03-17 16:24:42 +01:00
type liveMongoAccessor[T LiveInterface] struct {
2026-02-18 12:24:19 +01:00
utils.AbstractAccessor[LiveInterface] // AbstractAccessor contains the basic fields of an accessor (model, caller)
2025-06-24 11:29:04 +02:00
}
// New creates a new instance of the computeUnitsMongoAccessor
2026-03-17 16:24:42 +01:00
func NewAccessor[T LiveInterface](t tools.DataType, request *tools.APIRequest) *liveMongoAccessor[T] {
return &liveMongoAccessor[T]{
2026-02-18 12:24:19 +01:00
AbstractAccessor: utils.AbstractAccessor[LiveInterface]{
2025-06-26 15:59:21 +02:00
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
2025-06-24 11:29:04 +02:00
Request: request,
2025-06-26 15:59:21 +02:00
Type: t,
2026-02-18 12:24:19 +01:00
New: func() LiveInterface {
switch t {
case tools.LIVE_DATACENTER:
return &LiveDatacenter{}
case tools.LIVE_STORAGE:
return &LiveStorage{}
2026-04-27 11:16:50 +02:00
case tools.LIVE_SERVICE:
return &LiveService{}
2026-02-18 12:24:19 +01:00
}
return &LiveDatacenter{}
},
2026-04-28 11:48:23 +02:00
NotImplemented: []string{"CopyOne"},
2025-06-24 11:29:04 +02:00
},
}
}
2026-04-08 15:40:44 +02:00
func (wfa *liveMongoAccessor[T]) LoadAll(isDraft bool, offset int64, limit int64) ([]utils.ShallowDBObject, int, error) {
return utils.GenericLoadAll[T](wfa.GetExec(isDraft), isDraft, wfa, offset, limit)
}
func (wfa *liveMongoAccessor[T]) Search(filters *dbs.Filters, search string, isDraft bool, offset int64, limit int64) ([]utils.ShallowDBObject, int, error) {
if filters == nil && search == "*" {
return utils.GenericLoadAll[T](func(d utils.DBObject) utils.ShallowDBObject {
return d
}, isDraft, wfa, offset, limit)
}
return utils.GenericSearch[T](filters, search, wfa.New().GetObjectFilters(search),
func(d utils.DBObject) utils.ShallowDBObject {
return d
}, isDraft, wfa, offset, limit)
}
func (a *liveMongoAccessor[T]) GetExec(isDraft bool) func(utils.DBObject) utils.ShallowDBObject {
return func(d utils.DBObject) utils.ShallowDBObject {
return d
}
}