leaf/document.go
2024-01-07 08:40:41 +03:00

38 lines
844 B
Go

package leaf
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Document interface {
ID() primitive.ObjectID
SetID(id primitive.ObjectID)
SetCreatedAt(ts time.Time)
SetUpdatedAt(ts time.Time)
}
type Base struct {
ObjectID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty" example:"507f1f77bcf86cd799439011"`
CreatedAt time.Time `json:"created_at" bson:"created_at" format:"dateTime" example:"2020-01-01T00:00:00Z"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at" format:"dateTime" example:"2020-01-01T00:00:00Z"`
}
func (s *Base) ID() primitive.ObjectID {
return s.ObjectID
}
func (s *Base) SetID(id primitive.ObjectID) {
s.ObjectID = id
}
func (s *Base) SetCreatedAt(ts time.Time) {
s.CreatedAt = ts
}
func (s *Base) SetUpdatedAt(ts time.Time) {
s.UpdatedAt = ts
}