Documentation
¶
Index ¶
- Variables
- func IsDuplicateEntryError(err error) bool
- func IsRecordNotFoundError(err error) bool
- type GormStorage
- func (gs *GormStorage) Close() error
- func (gs *GormStorage) Create(m interface{}) error
- func (g *GormStorage) CreateABookmarkOfAUser(userID string, bookmark models.Bookmark) (models.Bookmark, error)
- func (g *GormStorage) CreateAPayByOtherMethodDonation(m models.PayByOtherMethodDonation) error
- func (g *GormStorage) CreateAPeriodicDonation(mpd *models.PeriodicDonation, mtd *models.PayByCardTokenDonation) error
- func (g *GormStorage) CreateAWebPushSubscription(wpSub models.WebPushSubscription) error
- func (g *GormStorage) CreateRegistration(service string, json models.RegistrationJSON) (models.Registration, error)
- func (g *GormStorage) CreateService(json models.ServiceJSON) (models.Service, error)
- func (gs *GormStorage) Delete(id uint, m interface{}) error
- func (g *GormStorage) DeleteABookmarkOfAUser(userID, bookmarkID string) error
- func (g *GormStorage) DeleteAPeriodicDonation(periodicID uint, failData models.PayByCardTokenDonation) error
- func (g *GormStorage) DeleteRegistration(email, service string) error
- func (g *GormStorage) DeleteService(name string) error
- func (gs *GormStorage) Get(id uint, m interface{}) error
- func (g *GormStorage) GetABookmarkByID(id string) (models.Bookmark, error)
- func (g *GormStorage) GetABookmarkBySlug(slug string) (models.Bookmark, error)
- func (g *GormStorage) GetABookmarkOfAUser(userID string, bookmarkSlug string, bookmarkHost string) (models.Bookmark, error)
- func (g *GormStorage) GetAWebPushSubscription(crc32Endpoint uint32, endpoint string) (models.WebPushSubscription, error)
- func (g *GormStorage) GetBookmarksOfAUser(id string, limit, offset int) ([]models.Bookmark, int, error)
- func (gs *GormStorage) GetByConditions(cond map[string]interface{}, m interface{}) error
- func (gs *GormStorage) GetOAuthData(aid null.String, aType string) (models.OAuthAccount, error)
- func (g *GormStorage) GetRegistration(email, service string) (models.Registration, error)
- func (g *GormStorage) GetRegistrationsAmountByService(service string, activeCode int) (uint, error)
- func (g *GormStorage) GetRegistrationsByService(service string, offset, limit int, orderBy string, activeCode int) ([]models.Registration, error)
- func (gs *GormStorage) GetReporterAccountData(email string) (models.ReporterAccount, error)
- func (g *GormStorage) GetService(name string) (models.Service, error)
- func (gs *GormStorage) GetUserByEmail(email string) (models.User, error)
- func (gs *GormStorage) GetUserByID(userID string) (models.User, error)
- func (gs *GormStorage) GetUserDataByOAuth(oac models.OAuthAccount) (models.User, error)
- func (gs *GormStorage) GetUserDataByReporterAccount(ra models.ReporterAccount) (models.User, error)
- func (gs *GormStorage) InsertOAuthAccount(account models.OAuthAccount) error
- func (gs *GormStorage) InsertReporterAccount(account models.ReporterAccount) error
- func (gs *GormStorage) InsertUserByOAuth(omodel models.OAuthAccount) (user models.User, err error)
- func (gs *GormStorage) InsertUserByReporterAccount(raModel models.ReporterAccount) (models.User, error)
- func (g *GormStorage) NewStorageError(err error, where string, message string) error
- func (gs *GormStorage) UpdateByConditions(cond map[string]interface{}, m interface{}) (err error, rowsAffected int64)
- func (gs *GormStorage) UpdateOAuthData(newData models.OAuthAccount) (models.OAuthAccount, error)
- func (g *GormStorage) UpdatePeriodicAndCardTokenDonationInTRX(periodicID uint, mpd models.PeriodicDonation, ...) error
- func (g *GormStorage) UpdateRegistration(service string, json models.RegistrationJSON) (models.Registration, error)
- func (gs *GormStorage) UpdateReporterAccount(ra models.ReporterAccount) error
- func (g *GormStorage) UpdateService(name string, json models.ServiceJSON) (models.Service, error)
- type MembershipStorage
- type MongoStorage
- func (m *MongoStorage) Close() error
- func (m *MongoStorage) GetAuthors(ids []bson.ObjectId) ([]models.Author, error)
- func (m *MongoStorage) GetDocument(id bson.ObjectId, collection string, doc interface{}) error
- func (m *MongoStorage) GetDocuments(qs models.MongoQuery, limit int, offset int, sort string, collection string, ...) (count int, err error)
- func (m *MongoStorage) GetEmbeddedAsset(entity models.NewsEntity, embedded []string)
- func (m *MongoStorage) GetFullAuthors(limit int, offset int, sort string) ([]models.FullAuthor, int, error)
- func (m *MongoStorage) GetFullPosts(mq models.MongoQuery, limit int, offset int, sort string, embedded []string) ([]models.Post, int, error)
- func (m *MongoStorage) GetFullTopics(mq models.MongoQuery, limit int, offset int, sort string, embedded []string) ([]models.Topic, int, error)
- func (m *MongoStorage) GetMetaOfPosts(mq models.MongoQuery, limit int, offset int, sort string, embedded []string) ([]models.Post, int, error)
- func (m *MongoStorage) GetMetaOfTopics(mq models.MongoQuery, limit int, offset int, sort string, embedded []string) ([]models.Topic, int, error)
- func (m *MongoStorage) NewStorageError(err error, where string, message string) error
- type NewsStorage
Constants ¶
This section is empty.
Variables ¶
var ErrDuplicateEntry uint16 = 1062
ErrDuplicateEntry record is already existed in MySQL database
var ErrMgoDuplicateEntry = 11000
ErrMgoDuplicateEntry record is already existed in MongoDB
var ErrMgoNotFound = mgo.ErrNotFound
ErrMgoNotFound record not found error when accessing MongoDB
var ErrRecordNotFound = gorm.ErrRecordNotFound
ErrRecordNotFound record not found error, happens when haven't find any matched data when looking up with a struct
Functions ¶
func IsDuplicateEntryError ¶
IsDuplicateEntryError check if err belongs to mysql.MySQLError and its error number is equal to ErrDuplicateEntry
func IsRecordNotFoundError ¶
IsRecordNotFoundError check if err is equal to gorm.ErrRecordNotFound
Types ¶
type GormStorage ¶
type GormStorage struct {
// contains filtered or unexported fields
}
GormStorage implements MembershipStorage interface
func NewGormStorage ¶
func NewGormStorage(db *gorm.DB) *GormStorage
NewGormStorage initializes the storage connected to MySQL database by gorm library
func (*GormStorage) Close ¶
func (gs *GormStorage) Close() error
Close quits the DB connection gracefully
func (*GormStorage) Create ¶
func (gs *GormStorage) Create(m interface{}) error
Create method of MembershipStorage interface
func (*GormStorage) CreateABookmarkOfAUser ¶
func (g *GormStorage) CreateABookmarkOfAUser(userID string, bookmark models.Bookmark) (models.Bookmark, error)
CreateABookmarkOfAUser this func will create a bookmark and build the relationship between the bookmark and the user
func (*GormStorage) CreateAPayByOtherMethodDonation ¶
func (g *GormStorage) CreateAPayByOtherMethodDonation(m models.PayByOtherMethodDonation) error
TODO
func (*GormStorage) CreateAPeriodicDonation ¶
func (g *GormStorage) CreateAPeriodicDonation(mpd *models.PeriodicDonation, mtd *models.PayByCardTokenDonation) error
CreateAPeriodicDonation creates the draft record along with the first draft tap pay transaction
func (*GormStorage) CreateAWebPushSubscription ¶
func (g *GormStorage) CreateAWebPushSubscription(wpSub models.WebPushSubscription) error
CreateAWebPushSubscription - create a record in the persistent database, return error if fails.
func (*GormStorage) CreateRegistration ¶
func (g *GormStorage) CreateRegistration(service string, json models.RegistrationJSON) (models.Registration, error)
CreateRegistration this func will create a registration
func (*GormStorage) CreateService ¶
func (g *GormStorage) CreateService(json models.ServiceJSON) (models.Service, error)
CreateService this func will create a service record
func (*GormStorage) Delete ¶
func (gs *GormStorage) Delete(id uint, m interface{}) error
Delete method of MembershipStorage interface
func (*GormStorage) DeleteABookmarkOfAUser ¶
func (g *GormStorage) DeleteABookmarkOfAUser(userID, bookmarkID string) error
DeleteABookmarkOfAUser this func will delete the relationship between the user and the bookmark
func (*GormStorage) DeleteAPeriodicDonation ¶
func (g *GormStorage) DeleteAPeriodicDonation(periodicID uint, failData models.PayByCardTokenDonation) error
DeleteAPeriodicDonation marks the draft tap pay transaction record as 'fail' and then soft delete the periodic donation
func (*GormStorage) DeleteRegistration ¶
func (g *GormStorage) DeleteRegistration(email, service string) error
DeleteRegistration this func will delete the record in the stroage
func (*GormStorage) DeleteService ¶
func (g *GormStorage) DeleteService(name string) error
DeleteService this func will delete the record in the stroage
func (*GormStorage) Get ¶
func (gs *GormStorage) Get(id uint, m interface{}) error
Get method of MembershipStorage interface
func (*GormStorage) GetABookmarkByID ¶
func (g *GormStorage) GetABookmarkByID(id string) (models.Bookmark, error)
GetABookmarkByID ...
func (*GormStorage) GetABookmarkBySlug ¶
func (g *GormStorage) GetABookmarkBySlug(slug string) (models.Bookmark, error)
GetABookmarkBySlug ...
func (*GormStorage) GetABookmarkOfAUser ¶
func (g *GormStorage) GetABookmarkOfAUser(userID string, bookmarkSlug string, bookmarkHost string) (models.Bookmark, error)
GetABookmarkOfAUser get a bookmark of a user
func (*GormStorage) GetAWebPushSubscription ¶
func (g *GormStorage) GetAWebPushSubscription(crc32Endpoint uint32, endpoint string) (models.WebPushSubscription, error)
GetAWebPushSubscription - read a record from persistent database according to its crc32(endpoint) and endpoint value
func (*GormStorage) GetBookmarksOfAUser ¶
func (g *GormStorage) GetBookmarksOfAUser(id string, limit, offset int) ([]models.Bookmark, int, error)
GetBookmarksOfAUser lists bookmarks of the user
func (*GormStorage) GetByConditions ¶
func (gs *GormStorage) GetByConditions(cond map[string]interface{}, m interface{}) error
GetByConditions method of MembershipStorage interface
func (*GormStorage) GetOAuthData ¶
func (gs *GormStorage) GetOAuthData(aid null.String, aType string) (models.OAuthAccount, error)
GetOAuthData gets the corresponding OAuth by using the OAuth information
func (*GormStorage) GetRegistration ¶
func (g *GormStorage) GetRegistration(email, service string) (models.Registration, error)
GetRegistration ...
func (*GormStorage) GetRegistrationsAmountByService ¶
func (g *GormStorage) GetRegistrationsAmountByService(service string, activeCode int) (uint, error)
GetRegistrationsAmountByService ...
func (*GormStorage) GetRegistrationsByService ¶
func (g *GormStorage) GetRegistrationsByService(service string, offset, limit int, orderBy string, activeCode int) ([]models.Registration, error)
GetRegistrationsByService ...
func (*GormStorage) GetReporterAccountData ¶
func (gs *GormStorage) GetReporterAccountData(email string) (models.ReporterAccount, error)
GetReporterAccountData get the corresponding Reporter account by comparing email and password
func (*GormStorage) GetService ¶
func (g *GormStorage) GetService(name string) (models.Service, error)
GetService ...
func (*GormStorage) GetUserByEmail ¶
func (gs *GormStorage) GetUserByEmail(email string) (models.User, error)
GetUserByEmail gets the user by its email
func (*GormStorage) GetUserByID ¶
func (gs *GormStorage) GetUserByID(userID string) (models.User, error)
GetUserByID gets the user by its ID
func (*GormStorage) GetUserDataByOAuth ¶
func (gs *GormStorage) GetUserDataByOAuth(oac models.OAuthAccount) (models.User, error)
GetUserDataByOAuth gets the corresponding user data by using the OAuth information
func (*GormStorage) GetUserDataByReporterAccount ¶
func (gs *GormStorage) GetUserDataByReporterAccount(ra models.ReporterAccount) (models.User, error)
GetUserDataByReporterAccount get user data from user table by providing its reporter account data
func (*GormStorage) InsertOAuthAccount ¶
func (gs *GormStorage) InsertOAuthAccount(account models.OAuthAccount) error
InsertOAuthAccount insert a new record into o_auth_accounts table
func (*GormStorage) InsertReporterAccount ¶
func (gs *GormStorage) InsertReporterAccount(account models.ReporterAccount) error
InsertReporterAccount insert a new record into reporter_accounts table
func (*GormStorage) InsertUserByOAuth ¶
func (gs *GormStorage) InsertUserByOAuth(omodel models.OAuthAccount) (user models.User, err error)
InsertUserByOAuth insert a new user into db after the oath loginin
func (*GormStorage) InsertUserByReporterAccount ¶
func (gs *GormStorage) InsertUserByReporterAccount(raModel models.ReporterAccount) (models.User, error)
InsertUserByReporterAccount insert a new user into db after the sign up
func (*GormStorage) NewStorageError ¶
func (g *GormStorage) NewStorageError(err error, where string, message string) error
NewStorageError return AppError with detailed information. This method is mainly used to deal with MySQL error.
func (*GormStorage) UpdateByConditions ¶
func (gs *GormStorage) UpdateByConditions(cond map[string]interface{}, m interface{}) (err error, rowsAffected int64)
UpdateByConditions method of MembershipStorage interface
func (*GormStorage) UpdateOAuthData ¶
func (gs *GormStorage) UpdateOAuthData(newData models.OAuthAccount) (models.OAuthAccount, error)
UpdateOAuthData updates the corresponding OAuth by using the OAuth information
func (*GormStorage) UpdatePeriodicAndCardTokenDonationInTRX ¶
func (g *GormStorage) UpdatePeriodicAndCardTokenDonationInTRX(periodicID uint, mpd models.PeriodicDonation, mtd models.PayByCardTokenDonation) error
UpdatePeriodicAndCardTokenDonationInTRX updates the draft tap pay transaction with response and fills up the required information in periodic_donations table
func (*GormStorage) UpdateRegistration ¶
func (g *GormStorage) UpdateRegistration(service string, json models.RegistrationJSON) (models.Registration, error)
UpdateRegistration this func will update the record in the stroage
func (*GormStorage) UpdateReporterAccount ¶
func (gs *GormStorage) UpdateReporterAccount(ra models.ReporterAccount) error
UpdateReporterAccount update a reporter account
func (*GormStorage) UpdateService ¶
func (g *GormStorage) UpdateService(name string, json models.ServiceJSON) (models.Service, error)
UpdateService this func will update the record in the stroage
type MembershipStorage ¶
type MembershipStorage interface { /** Close DB Connection **/ Close() error /** Default CRUD **/ Create(interface{}) error Get(uint, interface{}) error GetByConditions(map[string]interface{}, interface{}) error UpdateByConditions(map[string]interface{}, interface{}) (error, int64) Delete(uint, interface{}) error /** User methods **/ GetUserByID(string) (models.User, error) GetUserByEmail(string) (models.User, error) GetOAuthData(null.String, string) (models.OAuthAccount, error) GetUserDataByOAuth(models.OAuthAccount) (models.User, error) GetReporterAccountData(string) (models.ReporterAccount, error) GetUserDataByReporterAccount(models.ReporterAccount) (models.User, error) InsertOAuthAccount(models.OAuthAccount) error InsertReporterAccount(models.ReporterAccount) error InsertUserByOAuth(models.OAuthAccount) (models.User, error) InsertUserByReporterAccount(models.ReporterAccount) (models.User, error) UpdateOAuthData(models.OAuthAccount) (models.OAuthAccount, error) UpdateReporterAccount(models.ReporterAccount) error /** Bookmark methods **/ GetABookmarkBySlug(string) (models.Bookmark, error) GetABookmarkByID(string) (models.Bookmark, error) GetABookmarkOfAUser(string, string, string) (models.Bookmark, error) GetBookmarksOfAUser(string, int, int) ([]models.Bookmark, int, error) CreateABookmarkOfAUser(string, models.Bookmark) (models.Bookmark, error) DeleteABookmarkOfAUser(string, string) error /** Web Push Subscription methods **/ CreateAWebPushSubscription(models.WebPushSubscription) error GetAWebPushSubscription(uint32, string) (models.WebPushSubscription, error) /** Donation methods **/ CreateAPeriodicDonation(*models.PeriodicDonation, *models.PayByCardTokenDonation) error DeleteAPeriodicDonation(uint, models.PayByCardTokenDonation) error UpdatePeriodicAndCardTokenDonationInTRX(uint, models.PeriodicDonation, models.PayByCardTokenDonation) error }
MembershipStorage defines the methods we need to implement, in order to fulfill the functionalities a membership system needs. Such as, let user signup, login w/o oauth, CRUD bookmarks, CRUD registrations.
type MongoStorage ¶
type MongoStorage struct {
// contains filtered or unexported fields
}
MongoStorage implements `NewsStorage`
func NewMongoStorage ¶
func NewMongoStorage(db *mgo.Session) *MongoStorage
NewMongoStorage initializes the storage connected to Mongo database
func (*MongoStorage) Close ¶
func (m *MongoStorage) Close() error
Close quits the DB connection gracefully
func (*MongoStorage) GetAuthors ¶
GetAuthors - get whole author documents by their objectIDs
func (*MongoStorage) GetDocument ¶
func (m *MongoStorage) GetDocument(id bson.ObjectId, collection string, doc interface{}) error
GetDocument ...
func (*MongoStorage) GetDocuments ¶
func (m *MongoStorage) GetDocuments(qs models.MongoQuery, limit int, offset int, sort string, collection string, documents interface{}) (count int, err error)
GetDocuments ...
func (*MongoStorage) GetEmbeddedAsset ¶
func (m *MongoStorage) GetEmbeddedAsset(entity models.NewsEntity, embedded []string)
GetEmbeddedAsset - get full embedded assets of the instance of models.NewsEntity
func (*MongoStorage) GetFullAuthors ¶
func (m *MongoStorage) GetFullAuthors(limit int, offset int, sort string) ([]models.FullAuthor, int, error)
GetFullAuthors finds the authors according to mongo aggregation pipeline stages
func (*MongoStorage) GetFullPosts ¶
func (m *MongoStorage) GetFullPosts(mq models.MongoQuery, limit int, offset int, sort string, embedded []string) ([]models.Post, int, error)
GetFullPosts is a type-specific functions implementing the method defined in the NewsStorage. It finds the posts according to query string.
func (*MongoStorage) GetFullTopics ¶
func (m *MongoStorage) GetFullTopics(mq models.MongoQuery, limit int, offset int, sort string, embedded []string) ([]models.Topic, int, error)
GetFullTopics is a type-specific functions implementing the method defined in the NewsStorage. It will get full topics having ALL the corresponding assets
func (*MongoStorage) GetMetaOfPosts ¶
func (m *MongoStorage) GetMetaOfPosts(mq models.MongoQuery, limit int, offset int, sort string, embedded []string) ([]models.Post, int, error)
GetMetaOfPosts is a type-specific functions implementing the method defined in the NewsStorage. It finds the posts according to query string and only return the metadata of posts.
func (*MongoStorage) GetMetaOfTopics ¶
func (m *MongoStorage) GetMetaOfTopics(mq models.MongoQuery, limit int, offset int, sort string, embedded []string) ([]models.Topic, int, error)
GetMetaOfTopics is a type-specific functions implementing the method defined in the NewsStorage. It will get full topics having PARTIAL corresponding assets
func (*MongoStorage) NewStorageError ¶
func (m *MongoStorage) NewStorageError(err error, where string, message string) error
NewStorageError return AppError with detailed information. This method is mainly used to deal with MongoDB error.
type NewsStorage ¶
type NewsStorage interface { /** Close DB Connection **/ Close() error /** Posts methods **/ GetMetaOfPosts(models.MongoQuery, int, int, string, []string) ([]models.Post, int, error) GetFullPosts(models.MongoQuery, int, int, string, []string) ([]models.Post, int, error) GetMetaOfTopics(models.MongoQuery, int, int, string, []string) ([]models.Topic, int, error) GetFullTopics(models.MongoQuery, int, int, string, []string) ([]models.Topic, int, error) /** Authors methods **/ GetFullAuthors(int, int, string) ([]models.FullAuthor, int, error) }
NewsStorage defines the methods we need to implement, in order to provide the news resource to twreporter main site.