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
··· 12 "tangled.org/core/appview/models" 13 ) 14 15 - type Star struct { 16 - StarredByDid string 17 - RepoAt syntax.ATURI 18 - Created time.Time 19 - Rkey string 20 - 21 - // optionally, populate this when querying for reverse mappings 22 - Repo *models.Repo 23 - } 24 - 25 - func (star *Star) ResolveRepo(e Execer) error { 26 - if star.Repo != nil { 27 - return nil 28 - } 29 - 30 - repo, err := GetRepoByAtUri(e, star.RepoAt.String()) 31 - if err != nil { 32 - return err 33 - } 34 - 35 - star.Repo = repo 36 - return nil 37 - } 38 - 39 - func AddStar(e Execer, star *Star) error { 40 query := `insert or ignore into stars (starred_by_did, repo_at, rkey) values (?, ?, ?)` 41 _, err := e.Exec( 42 query, ··· 48 } 49 50 // Get a star record 51 - func GetStar(e Execer, starredByDid string, repoAt syntax.ATURI) (*Star, error) { 52 query := ` 53 select starred_by_did, repo_at, created, rkey 54 from stars 55 where starred_by_did = ? and repo_at = ?` 56 row := e.QueryRow(query, starredByDid, repoAt) 57 58 - var star Star 59 var created string 60 err := row.Scan(&star.StarredByDid, &star.RepoAt, &created, &star.Rkey) 61 if err != nil { ··· 153 func GetStarStatuses(e Execer, userDid string, repoAts []syntax.ATURI) (map[string]bool, error) { 154 return getStarStatuses(e, userDid, repoAts) 155 } 156 - func GetStars(e Execer, limit int, filters ...filter) ([]Star, error) { 157 var conditions []string 158 var args []any 159 for _, filter := range filters { ··· 185 return nil, err 186 } 187 188 - starMap := make(map[string][]Star) 189 for rows.Next() { 190 - var star Star 191 var created string 192 err := rows.Scan(&star.StarredByDid, &star.RepoAt, &created, &star.Rkey) 193 if err != nil { ··· 228 } 229 } 230 231 - var stars []Star 232 for _, s := range starMap { 233 stars = append(stars, s...) 234 } ··· 260 return count, nil 261 } 262 263 - func GetAllStars(e Execer, limit int) ([]Star, error) { 264 - var stars []Star 265 266 rows, err := e.Query(` 267 select ··· 284 defer rows.Close() 285 286 for rows.Next() { 287 - var star Star 288 var repo models.Repo 289 var starCreatedAt, repoCreatedAt string 290
··· 12 "tangled.org/core/appview/models" 13 ) 14 15 + func AddStar(e Execer, star *models.Star) error { 16 query := `insert or ignore into stars (starred_by_did, repo_at, rkey) values (?, ?, ?)` 17 _, err := e.Exec( 18 query, ··· 24 } 25 26 // Get a star record 27 + func GetStar(e Execer, starredByDid string, repoAt syntax.ATURI) (*models.Star, error) { 28 query := ` 29 select starred_by_did, repo_at, created, rkey 30 from stars 31 where starred_by_did = ? and repo_at = ?` 32 row := e.QueryRow(query, starredByDid, repoAt) 33 34 + var star models.Star 35 var created string 36 err := row.Scan(&star.StarredByDid, &star.RepoAt, &created, &star.Rkey) 37 if err != nil { ··· 129 func GetStarStatuses(e Execer, userDid string, repoAts []syntax.ATURI) (map[string]bool, error) { 130 return getStarStatuses(e, userDid, repoAts) 131 } 132 + func GetStars(e Execer, limit int, filters ...filter) ([]models.Star, error) { 133 var conditions []string 134 var args []any 135 for _, filter := range filters { ··· 161 return nil, err 162 } 163 164 + starMap := make(map[string][]models.Star) 165 for rows.Next() { 166 + var star models.Star 167 var created string 168 err := rows.Scan(&star.StarredByDid, &star.RepoAt, &created, &star.Rkey) 169 if err != nil { ··· 204 } 205 } 206 207 + var stars []models.Star 208 for _, s := range starMap { 209 stars = append(stars, s...) 210 } ··· 236 return count, nil 237 } 238 239 + func GetAllStars(e Execer, limit int) ([]models.Star, error) { 240 + var stars []models.Star 241 242 rows, err := e.Query(` 243 select ··· 260 defer rows.Close() 261 262 for rows.Next() { 263 + var star models.Star 264 var repo models.Repo 265 var starCreatedAt, repoCreatedAt string 266
+1 -1
appview/db/timeline.go
··· 11 type TimelineEvent struct { 12 *models.Repo 13 *models.Follow 14 - *Star 15 16 EventAt time.Time 17
··· 11 type TimelineEvent struct { 12 *models.Repo 13 *models.Follow 14 + *models.Star 15 16 EventAt time.Time 17
+1 -1
appview/ingester.go
··· 116 l.Error("invalid record", "err", err) 117 return err 118 } 119 - err = db.AddStar(i.Db, &db.Star{ 120 StarredByDid: did, 121 RepoAt: subjectUri, 122 Rkey: e.Commit.RKey,
··· 116 l.Error("invalid record", "err", err) 117 return err 118 } 119 + err = db.AddStar(i.Db, &models.Star{ 120 StarredByDid: did, 121 RepoAt: subjectUri, 122 Rkey: e.Commit.RKey,
+17
appview/models/star.go
···
··· 1 + package models 2 + 3 + import ( 4 + "time" 5 + 6 + "github.com/bluesky-social/indigo/atproto/syntax" 7 + ) 8 + 9 + type Star struct { 10 + StarredByDid string 11 + RepoAt syntax.ATURI 12 + Created time.Time 13 + Rkey string 14 + 15 + // optionally, populate this when querying for reverse mappings 16 + Repo *Repo 17 + }
+2 -2
appview/notify/merged_notifier.go
··· 23 } 24 } 25 26 - func (m *mergedNotifier) NewStar(ctx context.Context, star *db.Star) { 27 for _, notifier := range m.notifiers { 28 notifier.NewStar(ctx, star) 29 } 30 } 31 - func (m *mergedNotifier) DeleteStar(ctx context.Context, star *db.Star) { 32 for _, notifier := range m.notifiers { 33 notifier.DeleteStar(ctx, star) 34 }
··· 23 } 24 } 25 26 + func (m *mergedNotifier) NewStar(ctx context.Context, star *models.Star) { 27 for _, notifier := range m.notifiers { 28 notifier.NewStar(ctx, star) 29 } 30 } 31 + func (m *mergedNotifier) DeleteStar(ctx context.Context, star *models.Star) { 32 for _, notifier := range m.notifiers { 33 notifier.DeleteStar(ctx, star) 34 }
+4 -4
appview/notify/notifier.go
··· 10 type Notifier interface { 11 NewRepo(ctx context.Context, repo *models.Repo) 12 13 - NewStar(ctx context.Context, star *db.Star) 14 - DeleteStar(ctx context.Context, star *db.Star) 15 16 NewIssue(ctx context.Context, issue *models.Issue) 17 ··· 35 36 func (m *BaseNotifier) NewRepo(ctx context.Context, repo *models.Repo) {} 37 38 - func (m *BaseNotifier) NewStar(ctx context.Context, star *db.Star) {} 39 - func (m *BaseNotifier) DeleteStar(ctx context.Context, star *db.Star) {} 40 41 func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} 42
··· 10 type Notifier interface { 11 NewRepo(ctx context.Context, repo *models.Repo) 12 13 + NewStar(ctx context.Context, star *models.Star) 14 + DeleteStar(ctx context.Context, star *models.Star) 15 16 NewIssue(ctx context.Context, issue *models.Issue) 17 ··· 35 36 func (m *BaseNotifier) NewRepo(ctx context.Context, repo *models.Repo) {} 37 38 + func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} 39 + func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} 40 41 func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} 42
+2 -2
appview/posthog/notifier.go
··· 35 } 36 } 37 38 - func (n *posthogNotifier) NewStar(ctx context.Context, star *db.Star) { 39 err := n.client.Enqueue(posthog.Capture{ 40 DistinctId: star.StarredByDid, 41 Event: "star", ··· 46 } 47 } 48 49 - func (n *posthogNotifier) DeleteStar(ctx context.Context, star *db.Star) { 50 err := n.client.Enqueue(posthog.Capture{ 51 DistinctId: star.StarredByDid, 52 Event: "unstar",
··· 35 } 36 } 37 38 + func (n *posthogNotifier) NewStar(ctx context.Context, star *models.Star) { 39 err := n.client.Enqueue(posthog.Capture{ 40 DistinctId: star.StarredByDid, 41 Event: "star", ··· 46 } 47 } 48 49 + func (n *posthogNotifier) DeleteStar(ctx context.Context, star *models.Star) { 50 err := n.client.Enqueue(posthog.Capture{ 51 DistinctId: star.StarredByDid, 52 Event: "unstar",
+1 -1
appview/state/star.go
··· 56 } 57 log.Println("created atproto record: ", resp.Uri) 58 59 - star := &db.Star{ 60 StarredByDid: currentUser.Did, 61 RepoAt: subjectUri, 62 Rkey: rkey,
··· 56 } 57 log.Println("created atproto record: ", resp.Uri) 58 59 + star := &models.Star{ 60 StarredByDid: currentUser.Did, 61 RepoAt: subjectUri, 62 Rkey: rkey,