basic queries for friends and blocks
fix the tests again
This commit is contained in:
parent
3cff453494
commit
f8e0c5635c
@ -7,20 +7,23 @@ import (
|
||||
)
|
||||
|
||||
type BlockStore interface {
|
||||
IsBlockedBy(blocker int, blockee int) (bool, error)
|
||||
IsBlockedBy(blocker, blockee int) (bool, error)
|
||||
Add(blocker, blockee int) error
|
||||
}
|
||||
|
||||
type DefaultBlockStore struct {
|
||||
isBlocked *sql.Stmt
|
||||
add *sql.Stmt
|
||||
}
|
||||
|
||||
func NewDefaultBlockStore(acc *qgen.Accumulator) (*DefaultBlockStore, error) {
|
||||
return &DefaultBlockStore{
|
||||
isBlocked: acc.Select("users_blocks").Cols("blocker").Where("blocker = ? AND blockedUser = ?").Prepare(),
|
||||
add: acc.Insert("users_blocks").Columns("blocker,blockedUser").Fields("?,?").Prepare(),
|
||||
}, acc.FirstError()
|
||||
}
|
||||
|
||||
func (s *DefaultBlockStore) IsBlockedBy(blocker int, blockee int) (bool, error) {
|
||||
func (s *DefaultBlockStore) IsBlockedBy(blocker, blockee int) (bool, error) {
|
||||
err := s.isBlocked.QueryRow(blocker, blockee).Scan(&blocker)
|
||||
if err != nil && err != ErrNoRows {
|
||||
return false, err
|
||||
@ -28,12 +31,47 @@ func (s *DefaultBlockStore) IsBlockedBy(blocker int, blockee int) (bool, error)
|
||||
return err != ErrNoRows, nil
|
||||
}
|
||||
|
||||
func (s *DefaultBlockStore) Add(blocker, blockee int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type FriendInvite struct {
|
||||
Requester int
|
||||
Target int
|
||||
}
|
||||
|
||||
type FriendStore interface {
|
||||
AddInvite(requester, target int) error
|
||||
Confirm(requester, target int) error
|
||||
GetOwSentInvites(uid int) ([]FriendInvite, error)
|
||||
GetOwnRecvInvites(uid int) ([]FriendInvite, error)
|
||||
}
|
||||
|
||||
type DefaultFriendStore struct {
|
||||
addInvite *sql.Stmt
|
||||
confirm *sql.Stmt
|
||||
getOwnSentInvites *sql.Stmt
|
||||
getOwnRecvInvites *sql.Stmt
|
||||
}
|
||||
|
||||
func NewDefaultFriendStore(acc *qgen.Accumulator) (*DefaultFriendStore, error) {
|
||||
return &DefaultFriendStore{}, acc.FirstError()
|
||||
return &DefaultFriendStore{
|
||||
addInvite: acc.Insert("users_friends_invites").Columns("requester, target").Fields("?,?").Prepare(),
|
||||
confirm: acc.Insert("users_friends").Columns("uid,uid2").Fields("?,?").Prepare(),
|
||||
getOwnSentInvites: acc.Select("users_friends_invites").Cols("requester, target").Where("requester = ?").Prepare(),
|
||||
getOwnRecvInvites: acc.Select("users_friends_invites").Cols("requester, target").Where("target = ?").Prepare(),
|
||||
}, acc.FirstError()
|
||||
}
|
||||
|
||||
func (s *DefaultFriendStore) AddInvite(requester, target int) error {
|
||||
return nil
|
||||
}
|
||||
func (s *DefaultFriendStore) Confirm(requester, target int) error {
|
||||
return nil
|
||||
}
|
||||
func (s *DefaultFriendStore) GetOwnSentInvites(uid int) ([]FriendInvite, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (s *DefaultFriendStore) GetOwnRecvInvites(uid int) ([]FriendInvite, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -209,9 +209,9 @@ func TestParser(t *testing.T) {
|
||||
s = "https:" + s
|
||||
fs = "https://" + c.Site.URL
|
||||
}
|
||||
l.Add("//"+u, "<a href='"+s+"'>"+c.Site.URL+"</a>")
|
||||
l.Add("//"+u+"\n", "<a href='"+s+"'>"+c.Site.URL+"</a><br>")
|
||||
l.Add("//"+u+"\n//"+u, "<a href='"+s+"'>"+c.Site.URL+"</a><br><a href='"+s+"'>"+c.Site.URL+"</a>")
|
||||
l.Add("//"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
|
||||
l.Add("//"+u+"\n", "<a href='"+fs+"'>"+c.Site.URL+"</a><br>")
|
||||
l.Add("//"+u+"\n//"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a><br><a href='"+fs+"'>"+c.Site.URL+"</a>")
|
||||
l.Add("http://"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
|
||||
l.Add("https://"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user