oc-lib/models/utils/interfaces.go

51 lines
1.5 KiB
Go
Raw Permalink Normal View History

2024-07-18 11:51:12 +02:00
package utils
import (
"cloud.o-forge.io/core/oc-lib/dbs"
"cloud.o-forge.io/core/oc-lib/tools"
2024-11-28 11:05:54 +01:00
"github.com/rs/zerolog"
)
2024-08-01 09:13:10 +02:00
// ShallowDBObject is an interface that defines the basic methods shallowed version of a DBObject
2024-07-23 11:22:50 +02:00
type ShallowDBObject interface {
GenerateID()
GetID() string
GetName() string
2024-11-28 11:05:54 +01:00
Deserialize(j map[string]interface{}, obj DBObject) DBObject
Serialize(obj DBObject) map[string]interface{}
2024-07-23 11:22:50 +02:00
}
// DBObject is an interface that defines the basic methods for a DBObject
2024-07-18 11:51:12 +02:00
type DBObject interface {
2024-07-19 10:54:58 +02:00
GenerateID()
2024-07-19 13:27:34 +02:00
GetID() string
2024-07-18 11:51:12 +02:00
GetName() string
IsDrafted() bool
StoreDraftDefault()
CanUpdate(set DBObject) (bool, DBObject)
CanDelete() bool
2024-12-04 12:14:55 +01:00
UpToDate(user string, create bool)
VerifyAuth(request *tools.APIRequest) bool
2024-11-28 11:05:54 +01:00
Deserialize(j map[string]interface{}, obj DBObject) DBObject
Serialize(obj DBObject) map[string]interface{}
GetAccessor(request *tools.APIRequest) Accessor
2024-07-18 11:51:12 +02:00
}
// Accessor is an interface that defines the basic methods for an Accessor
2024-07-18 11:51:12 +02:00
type Accessor interface {
GetRequest() *tools.APIRequest
2024-11-28 16:49:41 +01:00
GetType() tools.DataType
2024-12-04 11:33:08 +01:00
GetUser() string
2024-11-28 11:05:54 +01:00
GetPeerID() string
GetGroups() []string
GetLogger() *zerolog.Logger
GetCaller() *tools.HTTPCaller
Search(filters *dbs.Filters, search string, isDraft bool) ([]ShallowDBObject, int, error)
LoadAll(isDraft bool) ([]ShallowDBObject, int, error)
2024-07-19 11:27:58 +02:00
LoadOne(id string) (DBObject, int, error)
DeleteOne(id string) (DBObject, int, error)
2024-07-19 13:41:10 +02:00
CopyOne(data DBObject) (DBObject, int, error)
2024-07-19 11:27:58 +02:00
StoreOne(data DBObject) (DBObject, int, error)
2024-07-22 16:12:38 +02:00
UpdateOne(set DBObject, id string) (DBObject, int, error)
2024-07-18 11:51:12 +02:00
}