ducky/subscriptions

Paddy 2015-09-30 Parent:b240b6123548

14:fb2c0e498e37 Go to Latest

ducky/subscriptions/subscription_memstore.go

Update with comments for all exported functions. We now have golint-approved comments for all the exported functions in the subscriptions package. Next challenge: all the sub-packages!

History
     1.1 --- a/subscription_memstore.go	Sun Sep 27 21:20:46 2015 -0700
     1.2 +++ b/subscription_memstore.go	Wed Sep 30 01:03:39 2015 -0700
     1.3 @@ -13,6 +13,11 @@
     1.4  	return false
     1.5  }
     1.6  
     1.7 +// CreateSubscription stores the passed Subscription in the Memstore. If
     1.8 +// a Subscription sharing the same UserID already exists, an
     1.9 +// ErrSubscriptionAlreadyExists error will be returned. If a Subscription
    1.10 +// sharing the same StripeSubscription already exists, an
    1.11 +// ErrStripeSubscriptionAlreadyExists error will be returned.
    1.12  func (m *Memstore) CreateSubscription(sub Subscription) error {
    1.13  	m.subscriptionLock.Lock()
    1.14  	defer m.subscriptionLock.Unlock()
    1.15 @@ -27,6 +32,13 @@
    1.16  	return nil
    1.17  }
    1.18  
    1.19 +// UpdateSubscription applies the SubscriptionChange passed to the Subscription
    1.20 +// stored in the Memstore associated with the passed ID. If change is empty,
    1.21 +// an ErrSubscriptionChangeEmpty error is returned. If no Subscription is found
    1.22 +// in the Memstore with the passed ID, an ErrSubscriptionNotFound error is returned.
    1.23 +// If change is updating the StripeSubscription, and a Subscription in the Memstore
    1.24 +// already has that value set for StripeSubscription, an
    1.25 +// ErrStripeSubscriptionAlreadyExists error is returned.
    1.26  func (m *Memstore) UpdateSubscription(id uuid.ID, change SubscriptionChange) error {
    1.27  	if change.IsEmpty() {
    1.28  		return ErrSubscriptionChangeEmpty
    1.29 @@ -49,6 +61,9 @@
    1.30  	return nil
    1.31  }
    1.32  
    1.33 +// DeleteSubscription removes the Subscription stored in the Memstore associated
    1.34 +// with the passed ID from the Memstore. If no Subscription is found
    1.35 +// in the Memstore with the passed ID, an ErrSubscriptionNotFound error is returned.
    1.36  func (m *Memstore) DeleteSubscription(id uuid.ID) error {
    1.37  	m.subscriptionLock.Lock()
    1.38  	defer m.subscriptionLock.Unlock()
    1.39 @@ -61,6 +76,11 @@
    1.40  	return nil
    1.41  }
    1.42  
    1.43 +// GetSubscriptions retrieves the Subscriptions stored in the Memstore associated
    1.44 +// with the passed IDs. If no IDs are passed, an ErrNoSubscriptionID error is
    1.45 +// returned. No matter how many of the IDs are found (including none), a map is
    1.46 +// returned, with the key being a String()ed version of the ID for the Subscription in
    1.47 +// the value. If no error is returned, the map will represent all of the Subscriptions// matching the passed IDs that exist in the Memstore, even if it's empty.
    1.48  func (m *Memstore) GetSubscriptions(ids []uuid.ID) (map[string]Subscription, error) {
    1.49  	if len(ids) < 1 {
    1.50  		return map[string]Subscription{}, ErrNoSubscriptionID
    1.51 @@ -80,6 +100,11 @@
    1.52  	return result, nil
    1.53  }
    1.54  
    1.55 +// GetSubscriptionStats returns statistics about the subscription data stored in the
    1.56 +// Memstore as a SubscriptionStats variable. The number of Subscriptions, the
    1.57 +// breakdown of how many Subscriptions belong to each plan, the number of
    1.58 +// Subscriptions that are canceling, and the number of Subscriptions whose payment
    1.59 +// information is failing are all tracked.
    1.60  func (m *Memstore) GetSubscriptionStats() (SubscriptionStats, error) {
    1.61  	m.subscriptionLock.RLock()
    1.62  	defer m.subscriptionLock.RUnlock()