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