forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

appview/models: move db.Star into models

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li c07ba238 cca61e7f

verified
Changed files
+38 -45
appview
+10 -34
appview/db/star.go
···
"tangled.org/core/appview/models"
)
-
type Star struct {
-
StarredByDid string
-
RepoAt syntax.ATURI
-
Created time.Time
-
Rkey string
-
-
// optionally, populate this when querying for reverse mappings
-
Repo *models.Repo
-
}
-
-
func (star *Star) ResolveRepo(e Execer) error {
-
if star.Repo != nil {
-
return nil
-
}
-
-
repo, err := GetRepoByAtUri(e, star.RepoAt.String())
-
if err != nil {
-
return err
-
}
-
-
star.Repo = repo
-
return nil
-
}
-
-
func AddStar(e Execer, star *Star) error {
+
func AddStar(e Execer, star *models.Star) error {
query := `insert or ignore into stars (starred_by_did, repo_at, rkey) values (?, ?, ?)`
_, err := e.Exec(
query,
···
}
// Get a star record
-
func GetStar(e Execer, starredByDid string, repoAt syntax.ATURI) (*Star, error) {
+
func GetStar(e Execer, starredByDid string, repoAt syntax.ATURI) (*models.Star, error) {
query := `
select starred_by_did, repo_at, created, rkey
from stars
where starred_by_did = ? and repo_at = ?`
row := e.QueryRow(query, starredByDid, repoAt)
-
var star Star
+
var star models.Star
var created string
err := row.Scan(&star.StarredByDid, &star.RepoAt, &created, &star.Rkey)
if err != nil {
···
func GetStarStatuses(e Execer, userDid string, repoAts []syntax.ATURI) (map[string]bool, error) {
return getStarStatuses(e, userDid, repoAts)
}
-
func GetStars(e Execer, limit int, filters ...filter) ([]Star, error) {
+
func GetStars(e Execer, limit int, filters ...filter) ([]models.Star, error) {
var conditions []string
var args []any
for _, filter := range filters {
···
return nil, err
}
-
starMap := make(map[string][]Star)
+
starMap := make(map[string][]models.Star)
for rows.Next() {
-
var star Star
+
var star models.Star
var created string
err := rows.Scan(&star.StarredByDid, &star.RepoAt, &created, &star.Rkey)
if err != nil {
···
}
}
-
var stars []Star
+
var stars []models.Star
for _, s := range starMap {
stars = append(stars, s...)
}
···
return count, nil
}
-
func GetAllStars(e Execer, limit int) ([]Star, error) {
-
var stars []Star
+
func GetAllStars(e Execer, limit int) ([]models.Star, error) {
+
var stars []models.Star
rows, err := e.Query(`
select
···
defer rows.Close()
for rows.Next() {
-
var star Star
+
var star models.Star
var repo models.Repo
var starCreatedAt, repoCreatedAt string
+1 -1
appview/db/timeline.go
···
type TimelineEvent struct {
*models.Repo
*models.Follow
-
*Star
+
*models.Star
EventAt time.Time
+1 -1
appview/ingester.go
···
l.Error("invalid record", "err", err)
return err
}
-
err = db.AddStar(i.Db, &db.Star{
+
err = db.AddStar(i.Db, &models.Star{
StarredByDid: did,
RepoAt: subjectUri,
Rkey: e.Commit.RKey,
+17
appview/models/star.go
···
+
package models
+
+
import (
+
"time"
+
+
"github.com/bluesky-social/indigo/atproto/syntax"
+
)
+
+
type Star struct {
+
StarredByDid string
+
RepoAt syntax.ATURI
+
Created time.Time
+
Rkey string
+
+
// optionally, populate this when querying for reverse mappings
+
Repo *Repo
+
}
+2 -2
appview/notify/merged_notifier.go
···
}
}
-
func (m *mergedNotifier) NewStar(ctx context.Context, star *db.Star) {
+
func (m *mergedNotifier) NewStar(ctx context.Context, star *models.Star) {
for _, notifier := range m.notifiers {
notifier.NewStar(ctx, star)
}
}
-
func (m *mergedNotifier) DeleteStar(ctx context.Context, star *db.Star) {
+
func (m *mergedNotifier) DeleteStar(ctx context.Context, star *models.Star) {
for _, notifier := range m.notifiers {
notifier.DeleteStar(ctx, star)
}
+4 -4
appview/notify/notifier.go
···
type Notifier interface {
NewRepo(ctx context.Context, repo *models.Repo)
-
NewStar(ctx context.Context, star *db.Star)
-
DeleteStar(ctx context.Context, star *db.Star)
+
NewStar(ctx context.Context, star *models.Star)
+
DeleteStar(ctx context.Context, star *models.Star)
NewIssue(ctx context.Context, issue *models.Issue)
···
func (m *BaseNotifier) NewRepo(ctx context.Context, repo *models.Repo) {}
-
func (m *BaseNotifier) NewStar(ctx context.Context, star *db.Star) {}
-
func (m *BaseNotifier) DeleteStar(ctx context.Context, star *db.Star) {}
+
func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {}
+
func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {}
func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {}
+2 -2
appview/posthog/notifier.go
···
}
}
-
func (n *posthogNotifier) NewStar(ctx context.Context, star *db.Star) {
+
func (n *posthogNotifier) NewStar(ctx context.Context, star *models.Star) {
err := n.client.Enqueue(posthog.Capture{
DistinctId: star.StarredByDid,
Event: "star",
···
}
}
-
func (n *posthogNotifier) DeleteStar(ctx context.Context, star *db.Star) {
+
func (n *posthogNotifier) DeleteStar(ctx context.Context, star *models.Star) {
err := n.client.Enqueue(posthog.Capture{
DistinctId: star.StarredByDid,
Event: "unstar",
+1 -1
appview/state/star.go
···
}
log.Println("created atproto record: ", resp.Uri)
-
star := &db.Star{
+
star := &models.Star{
StarredByDid: currentUser.Did,
RepoAt: subjectUri,
Rkey: rkey,