start work on accounts module
This commit is contained in:
@ -25,6 +25,7 @@ import (
|
||||
|
||||
"github.com/go-fed/activity/pub"
|
||||
"github.com/gotosocial/gotosocial/internal/config"
|
||||
"github.com/gotosocial/gotosocial/internal/gtsmodel"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -68,6 +69,15 @@ type DB interface {
|
||||
|
||||
// Delete where deletes i where key = value
|
||||
DeleteWhere(key string, value interface{}, i interface{}) error
|
||||
|
||||
// GetAccountByUserID is a shortcut for the common action of fetching an account corresponding to a user ID
|
||||
GetAccountByUserID(userID string, account *gtsmodel.Account) error
|
||||
|
||||
// GetFollowingByAccountID is a shortcut for the common action of fetching a list of accounts that accountID is following
|
||||
GetFollowingByAccountID(accountID string, following *[]gtsmodel.Follow) error
|
||||
|
||||
// GetFollowersByAccountID is a shortcut for the common action of fetching a list of accounts that accountID is followed by
|
||||
GetFollowersByAccountID(accountID string, following *[]gtsmodel.Follow) error
|
||||
}
|
||||
|
||||
// New returns a new database service that satisfies the DB interface and, by extension,
|
||||
|
||||
@ -249,3 +249,21 @@ func (ps *postgresService) DeleteWhere(key string, value interface{}, i interfac
|
||||
_, err := ps.conn.Model(i).Where(fmt.Sprintf("%s = ?", key), value).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
func (ps *postgresService) GetAccountByUserID(userID string, account *gtsmodel.Account) error {
|
||||
user := >smodel.User{
|
||||
ID: userID,
|
||||
}
|
||||
if err := ps.conn.Model(user).Where("id = ?", userID).Select(); err != nil {
|
||||
return err
|
||||
}
|
||||
return ps.conn.Model(account).Where("id = ?", user.AccountID).Select()
|
||||
}
|
||||
|
||||
func (ps *postgresService) GetFollowingByAccountID(accountID string, following *[]gtsmodel.Follow) error {
|
||||
return ps.conn.Model(following).Where("account_id = ?", accountID).Select()
|
||||
}
|
||||
|
||||
func (ps *postgresService) GetFollowersByAccountID(accountID string, following *[]gtsmodel.Follow) error {
|
||||
return ps.conn.Model(following).Where("target_account_id = ?", accountID).Select()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user