Files
tm_back/pkg/mongo/interfaces.go
T

65 lines
1.5 KiB
Go

package mongo
// Logger defines the interface for logging operations
type Logger interface {
Info(message string, fields map[string]interface{})
Error(message string, fields map[string]interface{})
Debug(message string, fields map[string]interface{})
Warn(message string, fields map[string]interface{})
}
// Timestampable interface for models that support timestamps
type Timestampable interface {
SetCreatedAt(timestamp int64)
SetUpdatedAt(timestamp int64)
GetCreatedAt() int64
GetUpdatedAt() int64
}
// IDGetter interface for models that can provide their ID
type IDGetter interface {
GetID() string
}
// IDSetter interface for models that can set their ID
type IDSetter interface {
SetID(id string)
}
// Model provides a common base for MongoDB documents
type Model struct {
ID string `bson:"_id,omitempty" json:"id,omitempty"`
CreatedAt int64 `bson:"created_at" json:"created_at"`
UpdatedAt int64 `bson:"updated_at" json:"updated_at"`
}
// GetID returns the document ID
func (b *Model) GetID() string {
return b.ID
}
// SetID sets the document ID
func (b *Model) SetID(id string) {
b.ID = id
}
// SetCreatedAt sets the creation timestamp
func (b *Model) SetCreatedAt(timestamp int64) {
b.CreatedAt = timestamp
}
// SetUpdatedAt sets the update timestamp
func (b *Model) SetUpdatedAt(timestamp int64) {
b.UpdatedAt = timestamp
}
// GetCreatedAt returns the creation timestamp
func (b *Model) GetCreatedAt() int64 {
return b.CreatedAt
}
// GetUpdatedAt returns the update timestamp
func (b *Model) GetUpdatedAt() int64 {
return b.UpdatedAt
}