2018-01-22 08:15:45 +00:00
|
|
|
package common
|
|
|
|
|
2019-09-29 04:56:39 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
|
|
)
|
2018-01-22 08:15:45 +00:00
|
|
|
|
|
|
|
var Subscriptions SubscriptionStore
|
|
|
|
|
|
|
|
// ? Should we have a subscription store for each zone? topic, forum, etc?
|
|
|
|
type SubscriptionStore interface {
|
|
|
|
Add(uid int, elementID int, elementType string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultSubscriptionStore struct {
|
|
|
|
add *sql.Stmt
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultSubscriptionStore() (*DefaultSubscriptionStore, error) {
|
2018-08-04 11:46:36 +00:00
|
|
|
acc := qgen.NewAcc()
|
2018-01-22 08:15:45 +00:00
|
|
|
return &DefaultSubscriptionStore{
|
|
|
|
add: acc.Insert("activity_subscriptions").Columns("user, targetID, targetType, level").Fields("?,?,?,2").Prepare(),
|
|
|
|
}, acc.FirstError()
|
|
|
|
}
|
|
|
|
|
2019-09-29 04:56:39 +00:00
|
|
|
func (s *DefaultSubscriptionStore) Add(uid int, elementID int, elementType string) error {
|
|
|
|
_, err := s.add.Exec(uid, elementID, elementType)
|
2018-01-22 08:15:45 +00:00
|
|
|
return err
|
|
|
|
}
|