an app.bsky.* indexer

add GraphStarterpack

Changed files
+63 -1
cmd
monarch
models
+7
cmd/monarch/handlers.go
···
&models.GraphList{},
&models.GraphListblock{},
&models.GraphListitem{},
+
&models.GraphStarterpack{},
}
for _, migration := range migrations {
store.AutoMigrate(migration)
···
listitem := models.NewGraphListitem(uri, *rec)
if err := hs.store.Where(models.GraphListitem{ID: string(uri)}).Assign(listitem).FirstOrCreate(&models.GraphListitem{}).Error; err != nil {
return fmt.Errorf("error upserting graph listitem: %w", err)
+
}
+
+
case syntax.NSID("app.bsky.graph.starterpack"):
+
pack := models.NewGraphStarterpack(uri, *rec)
+
if err := hs.store.Where(models.GraphStarterpack{ID: string(uri)}).Assign(pack).FirstOrCreate(&models.GraphStarterpack{}).Error; err != nil {
+
return fmt.Errorf("error upserting graph starterpack: %w", err)
}
}
+55
models/graph_starterpack.go
···
+
package models
+
+
import (
+
"bytes"
+
"log/slog"
+
"time"
+
+
appbsky "github.com/bluesky-social/indigo/api/bsky"
+
"github.com/bluesky-social/indigo/atproto/syntax"
+
)
+
+
type GraphStarterpack struct {
+
ID string `gorm:"primaryKey"`
+
+
// TODO: DescriptionFacets
+
+
CreatedAt string
+
Description *string
+
Feeds []GraphStarterpack_Feed
+
List string
+
Name string
+
+
AutoCreatedAt time.Time `gorm:"autoCreateTime"`
+
AutoUpdatedAt time.Time `gorm:"autoUpdateTime"`
+
}
+
+
type GraphStarterpack_Feed struct {
+
GraphStarterpackID string
+
Uri string
+
}
+
+
func NewGraphStarterpack(uri syntax.ATURI, rec []byte) *GraphStarterpack {
+
var out appbsky.GraphStarterpack
+
if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
+
slog.Error("could not unmarshal graph starterpack CBOR", "err", err)
+
return nil
+
}
+
+
pack := GraphStarterpack{
+
CreatedAt: out.CreatedAt,
+
Description: out.Description,
+
List: out.List,
+
Name: out.Name,
+
}
+
+
if out.Feeds != nil {
+
for _, feed := range out.Feeds {
+
pack.Feeds = append(pack.Feeds, GraphStarterpack_Feed{
+
Uri: feed.Uri,
+
})
+
}
+
}
+
+
return &pack
+
}
+1 -1
models/models.go
···
// - [X] GraphList *
// - [X] GraphListblock *
// - [X] GraphListitem *
-
// - [ ] GraphStarterpack *
+
// - [X] GraphStarterpack *
// - [ ] GraphVerification *
// - [ ] LabelerService *
// - [ ] ActorDeclaration