diff options
| author | 2022-12-09 05:37:12 -0500 | |
|---|---|---|
| committer | 2022-12-09 11:37:12 +0100 | |
| commit | 477ae50933ab7447757752ec35bf898db287acff (patch) | |
| tree | 28750a1aea3cda180ca1461cfad7ea130c22bba1 /internal/db/bundb | |
| parent | [chore] move caches to a separate State{} structure (#1078) (diff) | |
| download | gotosocial-477ae50933ab7447757752ec35bf898db287acff.tar.xz | |
[feature] Allow users to create + delete bookbarks, and view bookmarked statuses (#1168)
* Implement Bookmarks
* Update based on review comments
* Update swagger doc
* Fix argument passing to status.Bookmark
* Update changed test
* Updates based on latest PR review
Diffstat (limited to 'internal/db/bundb')
| -rw-r--r-- | internal/db/bundb/account.go | 32 | ||||
| -rw-r--r-- | internal/db/bundb/account_test.go | 6 | 
2 files changed, 38 insertions, 0 deletions
| diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index 9f3fc8a16..01601e540 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -442,6 +442,38 @@ func (a *accountDB) GetAccountWebStatuses(ctx context.Context, accountID string,  	return a.statusesFromIDs(ctx, statusIDs)  } +func (a *accountDB) GetBookmarks(ctx context.Context, accountID string, limit int, maxID string, minID string) ([]*gtsmodel.StatusBookmark, db.Error) { +	bookmarks := []*gtsmodel.StatusBookmark{} + +	q := a.conn. +		NewSelect(). +		TableExpr("? AS ?", bun.Ident("status_bookmarks"), bun.Ident("status_bookmark")). +		Order("status_bookmark.id DESC"). +		Where("? = ?", bun.Ident("status_bookmark.account_id"), accountID) + +	if accountID == "" { +		return nil, errors.New("must provide an account") +	} + +	if limit != 0 { +		q = q.Limit(limit) +	} + +	if maxID != "" { +		q = q.Where("? < ?", bun.Ident("status_bookmark.id"), maxID) +	} + +	if minID != "" { +		q = q.Where("? > ?", bun.Ident("status_bookmark.id"), minID) +	} + +	if err := q.Scan(ctx, &bookmarks); err != nil { +		return nil, a.conn.ProcessError(err) +	} + +	return bookmarks, nil +} +  func (a *accountDB) GetAccountBlocks(ctx context.Context, accountID string, maxID string, sinceID string, limit int) ([]*gtsmodel.Account, string, string, db.Error) {  	blocks := []*gtsmodel.Block{} diff --git a/internal/db/bundb/account_test.go b/internal/db/bundb/account_test.go index bf85f14f4..e63956f87 100644 --- a/internal/db/bundb/account_test.go +++ b/internal/db/bundb/account_test.go @@ -208,6 +208,12 @@ func (suite *AccountTestSuite) TestInsertAccountWithDefaults() {  	suite.False(*newAccount.HideCollections)  } +func (suite *AccountTestSuite) TestGettingBookmarksWithNoAccount() { +	statuses, err := suite.db.GetBookmarks(context.Background(), "", 10, "", "") +	suite.Error(err) +	suite.Nil(statuses) +} +  func TestAccountTestSuite(t *testing.T) {  	suite.Run(t, new(AccountTestSuite))  } | 
