2019-10-13 08:50:55 +00:00
|
|
|
package common
|
|
|
|
|
2019-10-13 09:07:05 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
|
|
)
|
2019-10-13 08:50:55 +00:00
|
|
|
|
|
|
|
type BlockStore interface {
|
|
|
|
IsBlockedBy(blocker int, blockee int) (bool, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultBlockStore struct {
|
2019-10-13 09:07:05 +00:00
|
|
|
isBlocked *sql.Stmt
|
2019-10-13 08:50:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultBlockStore(acc *qgen.Accumulator) (*DefaultBlockStore, error) {
|
2019-10-13 09:07:05 +00:00
|
|
|
return &DefaultBlockStore{
|
|
|
|
isBlocked: acc.Select("users_blocks").Cols("blocker").Where("blocker = ? AND blockedUser = ?").Prepare(),
|
|
|
|
}, acc.FirstError()
|
2019-10-13 08:50:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DefaultBlockStore) IsBlockedBy(blocker int, blockee int) (bool, error) {
|
2019-10-13 09:07:05 +00:00
|
|
|
err := s.isBlocked.QueryRow(blocker, blockee).Scan(&blocker)
|
|
|
|
if err != nil && err != ErrNoRows {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return err != ErrNoRows, nil
|
2019-10-13 08:50:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type FriendStore interface {
|
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultFriendStore struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultFriendStore(acc *qgen.Accumulator) (*DefaultFriendStore, error) {
|
|
|
|
return &DefaultFriendStore{}, acc.FirstError()
|
|
|
|
}
|