Documentation ¶
Index ¶
- Constants
- func ToDomain(s *Subscription) *domain.Subscription
- func ToDomainSlice(subs []*Subscription) []*domain.Subscription
- type Filter
- type Subscription
- type SubscriptionRepository
- func (r *SubscriptionRepository) Begin() error
- func (r *SubscriptionRepository) Connect(uri string, databaseName string) error
- func (r *SubscriptionRepository) Disconnect() error
- func (r *SubscriptionRepository) Fail()
- func (r *SubscriptionRepository) Get(id string) (*domain.Subscription, error)
- func (r *SubscriptionRepository) GetAllForCurrency(currencySymbol string, updatedBefore uint64) ([]*domain.Subscription, error)
- func (r *SubscriptionRepository) GetAllForUser(userID string) ([]*domain.Subscription, error)
- func (r *SubscriptionRepository) NextIdentity(userID string) string
- func (r *SubscriptionRepository) Remove(s *domain.Subscription) error
- func (r *SubscriptionRepository) Save(s *domain.Subscription) error
- func (r *SubscriptionRepository) Size() int64
- func (r *SubscriptionRepository) Success()
Constants ¶
const CollectionName = "Subscriptions"
CollectionName is the name of Subscription collection
const DocumentLimitsPerQuery = 1000
DocumentLimitsPerQuery limits query result to a certain number of documents
Variables ¶
This section is empty.
Functions ¶
func ToDomain ¶
func ToDomain(s *Subscription) *domain.Subscription
ToDomain converts MongoDB document representation of Subscription to domain model
func ToDomainSlice ¶
func ToDomainSlice(subs []*Subscription) []*domain.Subscription
ToDomainSlice converts slice of MongoDB documents to slice of domain models
Types ¶
type Filter ¶
type Filter struct { Condition string `bson:"condition" json:"condition"` IsMust bool `bson:"is_must" json:"is_must"` Type string `bson:"type" json:"type"` }
Filter represents a document in MongoDB corresponding to domain.Filter
type Subscription ¶
type Subscription struct { ID string `bson:"_id" json:"_id"` UserID string `bson:"user_id" json:"user_id"` Currency string `bson:"currency" json:"currency"` CurrencyDecimal string `bson:"currency_decimal" json:"currency_decimal"` Account string `bson:"account" json:"account"` BlockHeight uint64 `bson:"block_height" json:"block_height"` TotalReceived string `bson:"total_received" json:"total_received"` TotalSpent string `bson:"total_spent" json:"total_spent"` StartingBlockHeight uint64 `bson:"starting_block_height" json:"starting_block_height"` Filters []Filter `bson:"filters" json:"filters"` }
Subscription represents a document in MongoDB corresponding to domain.Subscription
func FromDomain ¶
func FromDomain(s *domain.Subscription) *Subscription
FromDomain converts domain.Subscription model to a MongoDB document representation
type SubscriptionRepository ¶
type SubscriptionRepository struct {
// contains filtered or unexported fields
}
SubscriptionRepository is MongoDB implementation of SubscriptionRepository
func NewSubscriptionRepository ¶
func NewSubscriptionRepository() *SubscriptionRepository
NewSubscriptionRepository creates a new instance of SubscriptionRepository
func (*SubscriptionRepository) Begin ¶
func (r *SubscriptionRepository) Begin() error
Begin starts a new session for ACID operation
func (*SubscriptionRepository) Connect ¶
func (r *SubscriptionRepository) Connect(uri string, databaseName string) error
Connect creates a connection to the given mongodb instance and the database
func (*SubscriptionRepository) Disconnect ¶
func (r *SubscriptionRepository) Disconnect() error
Disconnect closes connection with the connected mongodb instance
func (*SubscriptionRepository) Fail ¶
func (r *SubscriptionRepository) Fail()
Fail rollbacks to the state before this change. Notice that due to the fact that every operation is wrapped in MongoDB Callback-API (https://docs.mongodb.com/manual/core/transactions-in-applications/#callback-api) Here, just close the session and release the locked mutex
func (*SubscriptionRepository) Get ¶
func (r *SubscriptionRepository) Get(id string) (*domain.Subscription, error)
Get returns the subscription for the given subscription id
func (*SubscriptionRepository) GetAllForCurrency ¶
func (r *SubscriptionRepository) GetAllForCurrency(currencySymbol string, updatedBefore uint64) ([]*domain.Subscription, error)
GetAllForCurrency returns all subscriptions for the given currency
func (*SubscriptionRepository) GetAllForUser ¶
func (r *SubscriptionRepository) GetAllForUser(userID string) ([]*domain.Subscription, error)
GetAllForUser returns all subscriptions for the given user id
func (*SubscriptionRepository) NextIdentity ¶
func (r *SubscriptionRepository) NextIdentity(userID string) string
NextIdentity returns the next available identity
func (*SubscriptionRepository) Remove ¶
func (r *SubscriptionRepository) Remove(s *domain.Subscription) error
Remove removes the given subscription from the persistance
func (*SubscriptionRepository) Save ¶
func (r *SubscriptionRepository) Save(s *domain.Subscription) error
Save persists/updates the given subscription
func (*SubscriptionRepository) Size ¶
func (r *SubscriptionRepository) Size() int64
Size returns the total number of subscriptions persited in the repository
func (*SubscriptionRepository) Success ¶
func (r *SubscriptionRepository) Success()
Success finalizes ACID operation Notice that due to the fact that every operation is wrapped in MongoDB Callback-API (https://docs.mongodb.com/manual/core/transactions-in-applications/#callback-api) Here, just close the session and release the locked mutex