Capstone/ui/db/models/actions.go

52 lines
1.2 KiB
Go
Raw Normal View History

2023-11-04 23:43:01 -04:00
package models
import (
"time"
2023-11-04 23:43:01 -04:00
"go.mongodb.org/mongo-driver/bson/primitive"
)
const (
ACTION_MAPPING_TYPE = "action"
)
2023-11-04 23:43:01 -04:00
type ActionMapping struct {
*CommonFields `bson:"obj_info"`
Id primitive.ObjectID `bson:"_id,omitempty"`
UserId primitive.ObjectID `bson:"user_id,omitempty"`
SourceEvent *Event `bson:"source_event,omitempty"`
Action *Action `bson:"action,omitempty"`
}
type Action struct {
VendorName string `bson:"vendor_name,omitempty"`
Type string `bson:"type,omitempty"`
Fields map[string]string `bson:"fields,omitempty"`
}
type Event struct {
VendorName string `bson:"vendor_name,omitempty"`
Key string `bson:"key,omitempty"`
Fields map[string]string `bson:"fields,omitempty"`
}
func (am *ActionMapping) MongoId() primitive.ObjectID {
if am.Id.IsZero() {
now := time.Now()
am.Id = primitive.NewObjectIDFromTimestamp(now)
}
return am.Id
}
func (am *ActionMapping) UpdateObjectInfo() {
now := time.Now()
if am.CommonFields == nil {
am.CommonFields = new(CommonFields)
am.EntityType = ACTION_MAPPING_TYPE
am.CreatedAt = now
}
am.UpdatedAt = now
2023-11-04 23:43:01 -04:00
}