mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-07 22:48:09 -06:00
[chore] Add interaction policy gtsmodels (#3075)
* [chore] introduce interaction policy gts models * update migration a smidge * fix copy paste typo * update migration * use int for InteractionType
This commit is contained in:
parent
8f8093aea4
commit
5bc567196b
46 changed files with 1318 additions and 531 deletions
|
|
@ -23,6 +23,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
|
|
@ -77,6 +78,21 @@ func (s *statusFaveDB) GetStatusFaveByID(ctx context.Context, id string) (*gtsmo
|
|||
)
|
||||
}
|
||||
|
||||
func (s *statusFaveDB) GetStatusFaveByURI(ctx context.Context, uri string) (*gtsmodel.StatusFave, error) {
|
||||
return s.getStatusFave(
|
||||
ctx,
|
||||
"URI",
|
||||
func(fave *gtsmodel.StatusFave) error {
|
||||
return s.db.
|
||||
NewSelect().
|
||||
Model(fave).
|
||||
Where("? = ?", bun.Ident("uri"), uri).
|
||||
Scan(ctx)
|
||||
},
|
||||
uri,
|
||||
)
|
||||
}
|
||||
|
||||
func (s *statusFaveDB) getStatusFave(ctx context.Context, lookup string, dbQuery func(*gtsmodel.StatusFave) error, keyParts ...any) (*gtsmodel.StatusFave, error) {
|
||||
// Fetch status fave from database cache with loader callback
|
||||
fave, err := s.state.Caches.GTS.StatusFave.LoadOne(lookup, func() (*gtsmodel.StatusFave, error) {
|
||||
|
|
@ -242,6 +258,26 @@ func (s *statusFaveDB) PutStatusFave(ctx context.Context, fave *gtsmodel.StatusF
|
|||
})
|
||||
}
|
||||
|
||||
func (s *statusFaveDB) UpdateStatusFave(ctx context.Context, fave *gtsmodel.StatusFave, columns ...string) error {
|
||||
fave.UpdatedAt = time.Now()
|
||||
if len(columns) > 0 {
|
||||
// If we're updating by column,
|
||||
// ensure "updated_at" is included.
|
||||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
// Update the status fave model in the database.
|
||||
return s.state.Caches.GTS.StatusFave.Store(fave, func() error {
|
||||
_, err := s.db.
|
||||
NewUpdate().
|
||||
Model(fave).
|
||||
Where("? = ?", bun.Ident("status_fave.id"), fave.ID).
|
||||
Column(columns...).
|
||||
Exec(ctx)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *statusFaveDB) DeleteStatusFaveByID(ctx context.Context, id string) error {
|
||||
var statusID string
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue