Documentation
¶
Index ¶
- func MigrateDatabase(db *gorm.DB)
- func NewPostgresDB(cfg Config) (*gorm.DB, error)
- type Config
- type Info
- type InfoPostgres
- type InitDatabase
- type Storage
- type Subscription
- type SubscriptionPostgres
- func (subsStorage *SubscriptionPostgres) Add(user *logic.User, publication *logic.Publication) error
- func (subsStorage *SubscriptionPostgres) AddDefault(publication *logic.Publication) error
- func (subsStorage *SubscriptionPostgres) Connect(user *logic.User, publication *logic.Publication) error
- func (subsStorage *SubscriptionPostgres) Disonnect(user *logic.User, publication *logic.Publication) error
- func (subsStorage *SubscriptionPostgres) GetAllDefaultSubs() []logic.Publication
- func (subsStorage *SubscriptionPostgres) GetAllSubs() []logic.Publication
- func (subsStorage *SubscriptionPostgres) GetSubsByUser(user *logic.User) ([]logic.Publication, error)
- func (subsStorage *SubscriptionPostgres) Remove(publication *logic.Publication) error
- func (subsStorage *SubscriptionPostgres) Update(user *logic.User, publication *logic.Publication) error
- type User
- type UserPostgres
- func (userStorage *UserPostgres) GetUserByChatID(chatID int64) (*logic.User, error)
- func (userStorage *UserPostgres) GetUserByID(userID int64) (*logic.User, error)
- func (userStorage *UserPostgres) GetUsersByPublication(pub *logic.Publication) ([]logic.User, error)
- func (userStorage *UserPostgres) IsChatAdmin(chatID int64) bool
- func (userStorage *UserPostgres) IsUserAdmin(user *logic.User) bool
- func (userStorage *UserPostgres) Register(user *logic.User) error
- func (userStorage *UserPostgres) Unregister(user *logic.User) error
- func (userStorage *UserPostgres) Update(user *logic.User) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Host string Username string Password string DBName string Port string SSLMode string }
Config struct for database connection
type Info ¶
type Info interface { GetLastTimestamp() uint64 // Returns time of the latest post SetLastTimestamp(tsp uint64) // Sets time of the latest post }
Info interface definces methods for Info Storage
type InfoPostgres ¶
type InfoPostgres struct {
// contains filtered or unexported fields
}
InfoPostgres is an implementation of storage.Info
func NewInfoPostgres ¶
func NewInfoPostgres(db *gorm.DB) *InfoPostgres
NewInfoPostgres constructor of InfoPostgres struct
func (*InfoPostgres) GetLastTimestamp ¶
func (infoStorage *InfoPostgres) GetLastTimestamp() uint64
GetLastTimestamp returns time of the latest post
func (*InfoPostgres) SetLastTimestamp ¶
func (infoStorage *InfoPostgres) SetLastTimestamp(timestamp uint64)
SetLastTimestamp sets time of the latest post
type InitDatabase ¶
type InitDatabase struct {
Admin []int64
}
InitDatabase configuration struct to database data
type Storage ¶
type Storage struct { User Subscription Info }
Storage struct is used to access database
func NewStorage ¶
func NewStorage(db *gorm.DB, cfg *InitDatabase) *Storage
NewStorage constructor of Storage
type Subscription ¶
type Subscription interface { Add(user *logic.User, publication *logic.Publication) error // Adds new subscription to user with publication AddDefault(publication *logic.Publication) error // Adds new subscription to user with publication Remove(publication *logic.Publication) error // Removes existing sybscription Disonnect(user *logic.User, publication *logic.Publication) error // Disonnect user from publication Update(user *logic.User, publication *logic.Publication) error // Updates selected subscription GetSubsByUser(user *logic.User) ([]logic.Publication, error) // Returns list of user's subscriptions GetAllSubs() []logic.Publication // Returns all publications GetAllDefaultSubs() []logic.Publication Connect(user *logic.User, publication *logic.Publication) error }
Subscription interface defines methods for Publicaiton Storage
type SubscriptionPostgres ¶
type SubscriptionPostgres struct {
// contains filtered or unexported fields
}
SubscriptionPostgres is an implementation of storage.Subscription
func NewSubscriptionPostgres ¶
func NewSubscriptionPostgres(db *gorm.DB) *SubscriptionPostgres
NewSubscriptionPostgres constructor of SubscriptionPostgres struct
func (*SubscriptionPostgres) Add ¶
func (subsStorage *SubscriptionPostgres) Add(user *logic.User, publication *logic.Publication) error
Add new subscription to user with publication
func (*SubscriptionPostgres) AddDefault ¶
func (subsStorage *SubscriptionPostgres) AddDefault(publication *logic.Publication) error
AddDefault creates default publication
func (*SubscriptionPostgres) Connect ¶
func (subsStorage *SubscriptionPostgres) Connect(user *logic.User, publication *logic.Publication) error
Connect (subscribe) user to publication
func (*SubscriptionPostgres) Disonnect ¶
func (subsStorage *SubscriptionPostgres) Disonnect(user *logic.User, publication *logic.Publication) error
Disonnect (unsubscribe) user from publication
func (*SubscriptionPostgres) GetAllDefaultSubs ¶
func (subsStorage *SubscriptionPostgres) GetAllDefaultSubs() []logic.Publication
GetAllDefaultSubs returns all default publications
func (*SubscriptionPostgres) GetAllSubs ¶
func (subsStorage *SubscriptionPostgres) GetAllSubs() []logic.Publication
GetAllSubs returns all publications
func (*SubscriptionPostgres) GetSubsByUser ¶
func (subsStorage *SubscriptionPostgres) GetSubsByUser(user *logic.User) ([]logic.Publication, error)
GetSubsByUser returns list of user's subscriptions
func (*SubscriptionPostgres) Remove ¶
func (subsStorage *SubscriptionPostgres) Remove(publication *logic.Publication) error
Remove existing sybscription from user
func (*SubscriptionPostgres) Update ¶
func (subsStorage *SubscriptionPostgres) Update(user *logic.User, publication *logic.Publication) error
Update selected subscription
type User ¶
type User interface { Register(user *logic.User) error // Adds user in databse Unregister(user *logic.User) error // Removes user from database GetUserByChatID(chatID int64) (*logic.User, error) // Returns user by chat id Update(user *logic.User) error // Updates user GetUserByID(userID int64) (*logic.User, error) // Returns user by it's id GetUsersByPublication(pub *logic.Publication) ([]logic.User, error) // Returns owner of publication IsUserAdmin(user *logic.User) bool IsChatAdmin(userID int64) bool }
User interface defines methods for User Storage
type UserPostgres ¶
type UserPostgres struct {
// contains filtered or unexported fields
}
UserPostgres is an implementation of storage.User
func NewUserPostgres ¶
func NewUserPostgres(db *gorm.DB, cfg *InitDatabase) *UserPostgres
NewUserPostgres constructor of UserPostgres struct
func (*UserPostgres) GetUserByChatID ¶
func (userStorage *UserPostgres) GetUserByChatID(chatID int64) (*logic.User, error)
GetUserByChatID returns user by chat id
func (*UserPostgres) GetUserByID ¶
func (userStorage *UserPostgres) GetUserByID(userID int64) (*logic.User, error)
GetUserByID returns user by it's id
func (*UserPostgres) GetUsersByPublication ¶
func (userStorage *UserPostgres) GetUsersByPublication(pub *logic.Publication) ([]logic.User, error)
GetUsersByPublication returns subscribers of publication
func (*UserPostgres) IsChatAdmin ¶
func (userStorage *UserPostgres) IsChatAdmin(chatID int64) bool
IsChatAdmin checks if user has administrator privileges by chatID
func (*UserPostgres) IsUserAdmin ¶
func (userStorage *UserPostgres) IsUserAdmin(user *logic.User) bool
IsUserAdmin checks if user has administrator privileges
func (*UserPostgres) Register ¶
func (userStorage *UserPostgres) Register(user *logic.User) error
Register adds user in databse
func (*UserPostgres) Unregister ¶
func (userStorage *UserPostgres) Unregister(user *logic.User) error
Unregister removes user from database